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:
136 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
137 lpfc_mbuf_free(phba, matp->virt, matp->phys);
138 list_del(&matp->list);
141 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
148 lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
150 struct lpfc_dmabuf *mlast, *next_mlast;
152 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
153 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
154 list_del(&mlast->list);
157 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
162 static struct lpfc_dmabuf *
163 lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
164 uint32_t size, int *entries)
166 struct lpfc_dmabuf *mlist = NULL;
167 struct lpfc_dmabuf *mp;
170 /* We get chucks of FCELSSIZE */
171 cnt = size > FCELSSIZE ? FCELSSIZE: size;
174 /* Allocate buffer for rsp payload */
175 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
178 lpfc_free_ct_rsp(phba, mlist);
182 INIT_LIST_HEAD(&mp->list);
184 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
185 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
187 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
191 lpfc_free_ct_rsp(phba, mlist);
195 /* Queue it to a linked list */
199 list_add_tail(&mp->list, &mlist->list);
201 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
202 /* build buffer ptr list for IOCB */
203 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
204 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
205 bpl->tus.f.bdeSize = (uint16_t) cnt;
206 bpl->tus.w = le32_to_cpu(bpl->tus.w);
218 lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
219 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
220 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
221 struct lpfc_iocbq *),
222 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
226 struct lpfc_sli *psli = &phba->sli;
227 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
229 struct lpfc_iocbq *geniocb;
231 /* Allocate buffer for command iocb */
232 spin_lock_irq(phba->host->host_lock);
233 geniocb = lpfc_sli_get_iocbq(phba);
234 spin_unlock_irq(phba->host->host_lock);
239 icmd = &geniocb->iocb;
240 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
241 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
242 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
243 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
244 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
247 geniocb->context3 = NULL;
249 geniocb->context3 = (uint8_t *) bmp;
251 /* Save for completion so we can release these resources */
252 geniocb->context1 = (uint8_t *) inp;
253 geniocb->context2 = (uint8_t *) outp;
255 /* Fill in payload, bp points to frame payload */
256 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
258 /* Fill in rest of iocb */
259 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
260 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
261 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
262 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
265 /* FC spec states we need 3 * ratov for CT requests */
266 tmo = (3 * phba->fc_ratov);
268 icmd->ulpTimeout = tmo;
269 icmd->ulpBdeCount = 1;
271 icmd->ulpClass = CLASS3;
272 icmd->ulpContext = ndlp->nlp_rpi;
274 /* Issue GEN REQ IOCB for NPORT <did> */
275 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
276 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
277 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
278 icmd->ulpIoTag, phba->hba_state);
279 geniocb->iocb_cmpl = cmpl;
280 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
281 spin_lock_irq(phba->host->host_lock);
282 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
283 lpfc_sli_release_iocbq(phba, geniocb);
284 spin_unlock_irq(phba->host->host_lock);
287 spin_unlock_irq(phba->host->host_lock);
293 lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
294 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
295 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
296 struct lpfc_iocbq *),
299 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
300 struct lpfc_dmabuf *outmp;
302 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
303 CommandResponse.bits.CmdRsp;
305 bpl++; /* Skip past ct request */
307 /* Put buffer(s) for ct rsp in bpl */
308 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
312 status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
315 lpfc_free_ct_rsp(phba, outmp);
322 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
324 struct lpfc_sli_ct_request *Response =
325 (struct lpfc_sli_ct_request *) mp->virt;
326 struct lpfc_nodelist *ndlp = NULL;
327 struct lpfc_nodelist *next_ndlp;
328 struct lpfc_dmabuf *mlast, *next_mp;
329 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
333 struct list_head head;
335 lpfc_set_disctmo(phba);
337 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
339 list_add_tail(&head, &mp->list);
340 list_for_each_entry_safe(mp, next_mp, &head, list) {
346 ctptr = (uint32_t *) mlast->virt;
348 Cnt -= 16; /* subtract length of CT header */
350 /* Loop through entire NameServer list of DIDs */
353 /* Get next DID from NameServer List */
355 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
358 if (Did != phba->fc_myDID) {
359 /* Check for rscn processing or not */
360 ndlp = lpfc_setup_disc_node(phba, Did);
362 /* Mark all node table entries that are in the
366 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
367 "%d:0238 Process x%x NameServer"
368 " Rsp Data: x%x x%x x%x\n",
372 phba->fc_rscn_id_cnt);
375 lpfc_printf_log(phba,
378 "%d:0239 Skip x%x NameServer "
379 "Rsp Data: x%x x%x x%x\n",
381 Did, Size, phba->fc_flag,
382 phba->fc_rscn_id_cnt);
385 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
387 Cnt -= sizeof (uint32_t);
397 * The driver has cycled through all Nports in the RSCN payload.
398 * Complete the handling by cleaning up and marking the
399 * current driver state.
401 if (phba->hba_state == LPFC_HBA_READY) {
404 * Switch ports that connect a loop of multiple targets need
405 * special consideration. The driver wants to unregister the
406 * rpi only on the target that was pulled from the loop. On
407 * RSCN, the driver wants to rediscover an NPort only if the
408 * driver flagged it as NLP_NPR_2B_DISC. Provided adisc is
409 * not enabled and the NPort is not capable of retransmissions
410 * (FC Tape) prevent timing races with the scsi error handler by
411 * unregistering the Nport's RPI. This action causes all
412 * outstanding IO to flush back to the midlayer.
414 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
416 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
417 (lpfc_rscn_payload_check(phba, ndlp->nlp_DID))) {
418 if ((phba->cfg_use_adisc == 0) &&
419 !(ndlp->nlp_fcp_info &
421 lpfc_unreg_rpi(phba, ndlp);
422 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
426 lpfc_els_flush_rscn(phba);
427 spin_lock_irq(phba->host->host_lock);
428 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
429 spin_unlock_irq(phba->host->host_lock);
438 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
439 struct lpfc_iocbq * rspiocb)
442 struct lpfc_sli *psli;
443 struct lpfc_dmabuf *bmp;
444 struct lpfc_dmabuf *inp;
445 struct lpfc_dmabuf *outp;
446 struct lpfc_nodelist *ndlp;
447 struct lpfc_sli_ct_request *CTrsp;
450 /* we pass cmdiocb to state machine which needs rspiocb as well */
451 cmdiocb->context_un.rsp_iocb = rspiocb;
453 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
454 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
455 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
457 irsp = &rspiocb->iocb;
458 if (irsp->ulpStatus) {
459 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
460 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
461 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
465 /* Check for retry */
466 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
468 /* CT command is being retried */
470 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
473 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
480 /* Good status, continue checking */
481 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
482 if (CTrsp->CommandResponse.bits.CmdRsp ==
483 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
484 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
485 "%d:0239 NameServer Rsp "
489 lpfc_ns_rsp(phba, outp,
490 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
491 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
492 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
493 /* NameServer Rsp Error */
494 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
495 "%d:0240 NameServer Rsp Error "
496 "Data: x%x x%x x%x x%x\n",
498 CTrsp->CommandResponse.bits.CmdRsp,
499 (uint32_t) CTrsp->ReasonCode,
500 (uint32_t) CTrsp->Explanation,
503 /* NameServer Rsp Error */
504 lpfc_printf_log(phba,
507 "%d:0241 NameServer Rsp Error "
508 "Data: x%x x%x x%x x%x\n",
510 CTrsp->CommandResponse.bits.CmdRsp,
511 (uint32_t) CTrsp->ReasonCode,
512 (uint32_t) CTrsp->Explanation,
516 /* Link up / RSCN discovery */
517 lpfc_disc_start(phba);
519 lpfc_free_ct_rsp(phba, outp);
520 lpfc_mbuf_free(phba, inp->virt, inp->phys);
521 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
524 spin_lock_irq(phba->host->host_lock);
525 lpfc_sli_release_iocbq(phba, cmdiocb);
526 spin_unlock_irq(phba->host->host_lock);
531 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
532 struct lpfc_iocbq * rspiocb)
534 struct lpfc_sli *psli;
535 struct lpfc_dmabuf *bmp;
536 struct lpfc_dmabuf *inp;
537 struct lpfc_dmabuf *outp;
539 struct lpfc_sli_ct_request *CTrsp;
542 /* we pass cmdiocb to state machine which needs rspiocb as well */
543 cmdiocb->context_un.rsp_iocb = rspiocb;
545 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
546 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
547 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
548 irsp = &rspiocb->iocb;
550 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
552 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
553 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
554 "%d:0209 RFT request completes ulpStatus x%x "
555 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
556 CTrsp->CommandResponse.bits.CmdRsp);
558 lpfc_free_ct_rsp(phba, outp);
559 lpfc_mbuf_free(phba, inp->virt, inp->phys);
560 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
563 spin_lock_irq(phba->host->host_lock);
564 lpfc_sli_release_iocbq(phba, cmdiocb);
565 spin_unlock_irq(phba->host->host_lock);
570 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
571 struct lpfc_iocbq * rspiocb)
573 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
578 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
579 struct lpfc_iocbq * rspiocb)
581 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
586 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
590 lpfc_decode_firmware_rev(phba, fwrev, 0);
593 sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
594 phba->Port, fwrev, lpfc_release_version);
596 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
597 fwrev, lpfc_release_version);
604 * Issue Cmd to NameServer
609 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
611 struct lpfc_dmabuf *mp, *bmp;
612 struct lpfc_sli_ct_request *CtReq;
613 struct ulp_bde64 *bpl;
614 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
615 struct lpfc_iocbq *) = NULL;
616 uint32_t rsp_size = 1024;
618 /* fill in BDEs for command */
619 /* Allocate buffer for command payload */
620 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
624 INIT_LIST_HEAD(&mp->list);
625 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
629 /* Allocate buffer for Buffer ptr list */
630 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
632 goto ns_cmd_free_mpvirt;
634 INIT_LIST_HEAD(&bmp->list);
635 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
637 goto ns_cmd_free_bmp;
640 lpfc_printf_log(phba,
643 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
644 phba->brd_no, cmdcode, phba->fc_flag,
645 phba->fc_rscn_id_cnt);
647 bpl = (struct ulp_bde64 *) bmp->virt;
648 memset(bpl, 0, sizeof(struct ulp_bde64));
649 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
650 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
651 bpl->tus.f.bdeFlags = 0;
652 if (cmdcode == SLI_CTNS_GID_FT)
653 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
654 else if (cmdcode == SLI_CTNS_RFT_ID)
655 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
656 else if (cmdcode == SLI_CTNS_RNN_ID)
657 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
658 else if (cmdcode == SLI_CTNS_RSNN_NN)
659 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
661 bpl->tus.f.bdeSize = 0;
662 bpl->tus.w = le32_to_cpu(bpl->tus.w);
664 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
665 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
666 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
667 CtReq->RevisionId.bits.InId = 0;
668 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
669 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
670 CtReq->CommandResponse.bits.Size = 0;
672 case SLI_CTNS_GID_FT:
673 CtReq->CommandResponse.bits.CmdRsp =
674 be16_to_cpu(SLI_CTNS_GID_FT);
675 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
676 if (phba->hba_state < LPFC_HBA_READY)
677 phba->hba_state = LPFC_NS_QRY;
678 lpfc_set_disctmo(phba);
679 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
680 rsp_size = FC_MAX_NS_RSP;
683 case SLI_CTNS_RFT_ID:
684 CtReq->CommandResponse.bits.CmdRsp =
685 be16_to_cpu(SLI_CTNS_RFT_ID);
686 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
687 CtReq->un.rft.fcpReg = 1;
688 cmpl = lpfc_cmpl_ct_cmd_rft_id;
691 case SLI_CTNS_RNN_ID:
692 CtReq->CommandResponse.bits.CmdRsp =
693 be16_to_cpu(SLI_CTNS_RNN_ID);
694 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
695 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
696 sizeof (struct lpfc_name));
697 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
700 case SLI_CTNS_RSNN_NN:
701 CtReq->CommandResponse.bits.CmdRsp =
702 be16_to_cpu(SLI_CTNS_RSNN_NN);
703 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
704 sizeof (struct lpfc_name));
705 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
706 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
707 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
711 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
712 /* On success, The cmpl function will free the buffers */
715 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
719 lpfc_mbuf_free(phba, mp->virt, mp->phys);
727 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
728 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
730 struct lpfc_dmabuf *bmp = cmdiocb->context3;
731 struct lpfc_dmabuf *inp = cmdiocb->context1;
732 struct lpfc_dmabuf *outp = cmdiocb->context2;
733 struct lpfc_sli_ct_request *CTrsp = outp->virt;
734 struct lpfc_sli_ct_request *CTcmd = inp->virt;
735 struct lpfc_nodelist *ndlp;
736 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
737 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
739 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
740 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
741 /* FDMI rsp failed */
742 lpfc_printf_log(phba,
745 "%d:0220 FDMI rsp failed Data: x%x\n",
747 be16_to_cpu(fdmi_cmd));
750 switch (be16_to_cpu(fdmi_cmd)) {
752 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
759 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
763 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
767 lpfc_free_ct_rsp(phba, outp);
768 lpfc_mbuf_free(phba, inp->virt, inp->phys);
769 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
772 spin_lock_irq(phba->host->host_lock);
773 lpfc_sli_release_iocbq(phba, cmdiocb);
774 spin_unlock_irq(phba->host->host_lock);
778 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
780 struct lpfc_dmabuf *mp, *bmp;
781 struct lpfc_sli_ct_request *CtReq;
782 struct ulp_bde64 *bpl;
786 REG_PORT_ATTRIBUTE *pab;
789 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
790 struct lpfc_iocbq *);
793 /* fill in BDEs for command */
794 /* Allocate buffer for command payload */
795 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
799 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
801 goto fdmi_cmd_free_mp;
803 /* Allocate buffer for Buffer ptr list */
804 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
806 goto fdmi_cmd_free_mpvirt;
808 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
810 goto fdmi_cmd_free_bmp;
812 INIT_LIST_HEAD(&mp->list);
813 INIT_LIST_HEAD(&bmp->list);
816 lpfc_printf_log(phba,
819 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
821 phba->fc_flag, phba->hba_state, cmdcode);
823 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
825 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
826 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
827 CtReq->RevisionId.bits.InId = 0;
829 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
830 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
836 lpfc_vpd_t *vp = &phba->vpd;
840 CtReq->CommandResponse.bits.CmdRsp =
841 be16_to_cpu(SLI_MGMT_RHBA);
842 CtReq->CommandResponse.bits.Size = 0;
843 rh = (REG_HBA *) & CtReq->un.PortID;
844 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
845 sizeof (struct lpfc_name));
846 /* One entry (port) per adapter */
847 rh->rpl.EntryCnt = be32_to_cpu(1);
848 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
849 sizeof (struct lpfc_name));
851 /* point to the HBA attribute block */
852 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
853 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
856 /* Point to the beginning of the first HBA attribute
858 /* #1 HBA attribute entry */
860 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
861 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
862 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
863 + sizeof (struct lpfc_name));
864 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
865 sizeof (struct lpfc_name));
867 size += FOURBYTES + sizeof (struct lpfc_name);
869 /* #2 HBA attribute entry */
870 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
871 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
872 strcpy(ae->un.Manufacturer, "Emulex Corporation");
873 len = strlen(ae->un.Manufacturer);
874 len += (len & 3) ? (4 - (len & 3)) : 4;
875 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
877 size += FOURBYTES + len;
879 /* #3 HBA attribute entry */
880 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
881 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
882 strcpy(ae->un.SerialNumber, phba->SerialNumber);
883 len = strlen(ae->un.SerialNumber);
884 len += (len & 3) ? (4 - (len & 3)) : 4;
885 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
887 size += FOURBYTES + len;
889 /* #4 HBA attribute entry */
890 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
891 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
892 strcpy(ae->un.Model, phba->ModelName);
893 len = strlen(ae->un.Model);
894 len += (len & 3) ? (4 - (len & 3)) : 4;
895 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
897 size += FOURBYTES + len;
899 /* #5 HBA attribute entry */
900 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
901 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
902 strcpy(ae->un.ModelDescription, phba->ModelDesc);
903 len = strlen(ae->un.ModelDescription);
904 len += (len & 3) ? (4 - (len & 3)) : 4;
905 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
907 size += FOURBYTES + len;
909 /* #6 HBA attribute entry */
910 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
911 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
912 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
913 /* Convert JEDEC ID to ascii for hardware version */
914 incr = vp->rev.biuRev;
915 for (i = 0; i < 8; i++) {
918 ae->un.HardwareVersion[7 - i] =
919 (char)((uint8_t) 0x30 +
922 ae->un.HardwareVersion[7 - i] =
923 (char)((uint8_t) 0x61 +
928 size += FOURBYTES + 8;
930 /* #7 HBA attribute entry */
931 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
932 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
933 strcpy(ae->un.DriverVersion, lpfc_release_version);
934 len = strlen(ae->un.DriverVersion);
935 len += (len & 3) ? (4 - (len & 3)) : 4;
936 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
938 size += FOURBYTES + len;
940 /* #8 HBA attribute entry */
941 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
942 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
943 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
944 len = strlen(ae->un.OptionROMVersion);
945 len += (len & 3) ? (4 - (len & 3)) : 4;
946 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
948 size += FOURBYTES + len;
950 /* #9 HBA attribute entry */
951 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
952 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
953 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
955 len = strlen(ae->un.FirmwareVersion);
956 len += (len & 3) ? (4 - (len & 3)) : 4;
957 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
959 size += FOURBYTES + len;
961 /* #10 HBA attribute entry */
962 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
963 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
964 sprintf(ae->un.OsNameVersion, "%s %s %s",
965 system_utsname.sysname, system_utsname.release,
966 system_utsname.version);
967 len = strlen(ae->un.OsNameVersion);
968 len += (len & 3) ? (4 - (len & 3)) : 4;
969 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
971 size += FOURBYTES + len;
973 /* #11 HBA attribute entry */
974 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
975 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
976 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
977 ae->un.MaxCTPayloadLen = (65 * 4096);
979 size += FOURBYTES + 4;
981 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
983 size = GID_REQUEST_SZ - 4 + size;
990 struct serv_parm *hsp;
995 CtReq->CommandResponse.bits.CmdRsp =
996 be16_to_cpu(SLI_MGMT_RPA);
997 CtReq->CommandResponse.bits.Size = 0;
998 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
999 size = sizeof (struct lpfc_name) + FOURBYTES;
1000 memcpy((uint8_t *) & pab->PortName,
1001 (uint8_t *) & phba->fc_sparam.portName,
1002 sizeof (struct lpfc_name));
1003 pab->ab.EntryCnt = 0;
1005 /* #1 Port attribute entry */
1006 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1007 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1008 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1009 ae->un.SupportFC4Types[2] = 1;
1010 ae->un.SupportFC4Types[7] = 1;
1012 size += FOURBYTES + 32;
1014 /* #2 Port attribute entry */
1015 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1016 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1017 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1019 ae->un.SupportSpeed = 0;
1020 if (phba->lmt & LMT_10Gb)
1021 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1022 if (phba->lmt & LMT_8Gb)
1023 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1024 if (phba->lmt & LMT_4Gb)
1025 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1026 if (phba->lmt & LMT_2Gb)
1027 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1028 if (phba->lmt & LMT_1Gb)
1029 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1032 size += FOURBYTES + 4;
1034 /* #3 Port attribute entry */
1035 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1036 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1037 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1038 switch(phba->fc_linkspeed) {
1040 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1043 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1046 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1050 HBA_PORTSPEED_UNKNOWN;
1054 size += FOURBYTES + 4;
1056 /* #4 Port attribute entry */
1057 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1058 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1059 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1060 hsp = (struct serv_parm *) & phba->fc_sparam;
1061 ae->un.MaxFrameSize =
1062 (((uint32_t) hsp->cmn.
1063 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1066 size += FOURBYTES + 4;
1068 /* #5 Port attribute entry */
1069 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1070 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1071 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1072 len = strlen((char *)ae->un.OsDeviceName);
1073 len += (len & 3) ? (4 - (len & 3)) : 4;
1074 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1076 size += FOURBYTES + len;
1078 if (phba->cfg_fdmi_on == 2) {
1079 /* #6 Port attribute entry */
1080 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1082 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1083 sprintf(ae->un.HostName, "%s",
1084 system_utsname.nodename);
1085 len = strlen(ae->un.HostName);
1086 len += (len & 3) ? (4 - (len & 3)) : 4;
1087 ae->ad.bits.AttrLen =
1088 be16_to_cpu(FOURBYTES + len);
1090 size += FOURBYTES + len;
1093 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1095 size = GID_REQUEST_SZ - 4 + size;
1100 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1101 CtReq->CommandResponse.bits.Size = 0;
1102 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1103 memcpy((uint8_t *) & pe->PortName,
1104 (uint8_t *) & phba->fc_sparam.portName,
1105 sizeof (struct lpfc_name));
1106 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1110 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1111 CtReq->CommandResponse.bits.Size = 0;
1112 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1113 memcpy((uint8_t *) & pe->PortName,
1114 (uint8_t *) & phba->fc_sparam.portName,
1115 sizeof (struct lpfc_name));
1116 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1120 bpl = (struct ulp_bde64 *) bmp->virt;
1121 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1122 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1123 bpl->tus.f.bdeFlags = 0;
1124 bpl->tus.f.bdeSize = size;
1125 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1127 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1129 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1132 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1135 fdmi_cmd_free_mpvirt:
1136 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1140 /* Issue FDMI request failed */
1141 lpfc_printf_log(phba,
1144 "%d:0244 Issue FDMI request failed Data: x%x\n",
1151 lpfc_fdmi_tmo(unsigned long ptr)
1153 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1154 unsigned long iflag;
1156 spin_lock_irqsave(phba->host->host_lock, iflag);
1157 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1158 phba->work_hba_events |= WORKER_FDMI_TMO;
1159 if (phba->work_wait)
1160 wake_up(phba->work_wait);
1162 spin_unlock_irqrestore(phba->host->host_lock,iflag);
1166 lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1168 struct lpfc_nodelist *ndlp;
1170 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1172 if (system_utsname.nodename[0] != '\0') {
1173 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1175 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1183 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1185 struct lpfc_sli *psli = &phba->sli;
1186 lpfc_vpd_t *vp = &phba->vpd;
1187 uint32_t b1, b2, b3, b4, i, rev;
1189 uint32_t *ptr, str[4];
1193 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1194 rev = vp->rev.sli2FwRev;
1196 rev = vp->rev.sli1FwRev;
1198 b1 = (rev & 0x0000f000) >> 12;
1199 b2 = (rev & 0x00000f00) >> 8;
1200 b3 = (rev & 0x000000c0) >> 6;
1201 b4 = (rev & 0x00000030) >> 4;
1217 b4 = (rev & 0x0000000f);
1219 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1220 fwname = vp->rev.sli2FwName;
1222 fwname = vp->rev.sli1FwName;
1224 for (i = 0; i < 16; i++)
1225 if (fwname[i] == 0x20)
1228 ptr = (uint32_t*)fwname;
1230 for (i = 0; i < 3; i++)
1231 str[i] = be32_to_cpu(*ptr++);
1235 sprintf(fwrevision, "%d.%d%d (%s)",
1236 b1, b2, b3, (char *)str);
1238 sprintf(fwrevision, "%d.%d%d", b1,
1242 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1246 sprintf(fwrevision, "%d.%d%d%c%d",
1250 rev = vp->rev.smFwRev;
1252 b1 = (rev & 0xff000000) >> 24;
1253 b2 = (rev & 0x00f00000) >> 20;
1254 b3 = (rev & 0x000f0000) >> 16;
1255 c = (rev & 0x0000ff00) >> 8;
1256 b4 = (rev & 0x000000ff);
1259 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1262 sprintf(fwrevision, "%d.%d%d%c%d ", b1,