1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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, struct lpfc_sli_ring *pring,
63 struct lpfc_iocbq *piocbq)
66 struct lpfc_iocbq *next_piocbq;
67 struct lpfc_dmabuf *pmbuf = NULL;
68 struct lpfc_dmabuf *matp = NULL, *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));
192 lpfc_free_ct_rsp(phba, mlist);
196 /* Queue it to a linked list */
200 list_add_tail(&mp->list, &mlist->list);
202 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
203 /* build buffer ptr list for IOCB */
204 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
205 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
206 bpl->tus.f.bdeSize = (uint16_t) cnt;
207 bpl->tus.w = le32_to_cpu(bpl->tus.w);
219 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
220 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
221 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
222 struct lpfc_iocbq *),
223 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
226 struct lpfc_hba *phba = vport->phba;
227 struct lpfc_sli *psli = &phba->sli;
228 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
230 struct lpfc_iocbq *geniocb;
232 /* Allocate buffer for command iocb */
233 geniocb = lpfc_sli_get_iocbq(phba);
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, vport->port_state);
278 geniocb->iocb_cmpl = cmpl;
279 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
280 geniocb->vport = vport;
281 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
282 lpfc_sli_release_iocbq(phba, geniocb);
290 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
291 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
292 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
293 struct lpfc_iocbq *),
296 struct lpfc_hba *phba = vport->phba;
297 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
298 struct lpfc_dmabuf *outmp;
300 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
301 CommandResponse.bits.CmdRsp;
303 bpl++; /* Skip past ct request */
305 /* Put buffer(s) for ct rsp in bpl */
306 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
310 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
313 lpfc_free_ct_rsp(phba, outmp);
320 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
322 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
323 struct lpfc_hba *phba = vport->phba;
324 struct lpfc_sli_ct_request *Response =
325 (struct lpfc_sli_ct_request *) mp->virt;
326 struct lpfc_nodelist *ndlp = NULL;
327 struct lpfc_dmabuf *mlast, *next_mp;
328 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
329 uint32_t Did, CTentry;
331 struct list_head head;
333 lpfc_set_disctmo(vport);
336 list_add_tail(&head, &mp->list);
337 list_for_each_entry_safe(mp, next_mp, &head, list) {
340 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
345 ctptr = (uint32_t *) mlast->virt;
347 Cnt -= 16; /* subtract length of CT header */
349 /* Loop through entire NameServer list of DIDs */
350 while (Cnt >= sizeof (uint32_t)) {
351 /* Get next DID from NameServer List */
353 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
355 /* Check for rscn processing or not */
356 if (Did != vport->fc_myDID)
357 ndlp = lpfc_setup_disc_node(vport, Did);
359 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
360 "%d:0238 Process x%x NameServer"
361 " Rsp Data: x%x x%x x%x\n",
365 vport->fc_rscn_id_cnt);
367 lpfc_printf_log(phba,
370 "%d:0239 Skip x%x NameServer "
371 "Rsp Data: x%x x%x x%x\n",
373 Did, Size, vport->fc_flag,
374 vport->fc_rscn_id_cnt);
376 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
378 Cnt -= sizeof (uint32_t);
388 * The driver has cycled through all Nports in the RSCN payload.
389 * Complete the handling by cleaning up and marking the
390 * current driver state.
392 if (vport->port_state == LPFC_VPORT_READY) {
393 lpfc_els_flush_rscn(vport);
394 spin_lock_irq(shost->host_lock);
395 vport->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
396 spin_unlock_irq(shost->host_lock);
405 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
406 struct lpfc_iocbq *rspiocb)
408 struct lpfc_vport *vport = cmdiocb->vport;
410 struct lpfc_dmabuf *bmp;
411 struct lpfc_dmabuf *inp;
412 struct lpfc_dmabuf *outp;
413 struct lpfc_nodelist *ndlp;
414 struct lpfc_sli_ct_request *CTrsp;
417 /* we pass cmdiocb to state machine which needs rspiocb as well */
418 cmdiocb->context_un.rsp_iocb = rspiocb;
420 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
421 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
422 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
424 irsp = &rspiocb->iocb;
425 if (irsp->ulpStatus) {
426 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
427 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
428 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
431 /* Check for retry */
432 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
433 vport->fc_ns_retry++;
434 /* CT command is being retried */
435 ndlp = lpfc_findnode_did(vport, NameServer_DID);
436 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
437 rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
443 /* Good status, continue checking */
444 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
445 if (CTrsp->CommandResponse.bits.CmdRsp ==
446 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
447 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
448 "%d:0208 NameServer Rsp "
452 lpfc_ns_rsp(vport, outp,
453 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
454 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
455 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
456 /* NameServer Rsp Error */
457 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
458 "%d:0240 NameServer Rsp Error "
459 "Data: x%x x%x x%x x%x\n",
461 CTrsp->CommandResponse.bits.CmdRsp,
462 (uint32_t) CTrsp->ReasonCode,
463 (uint32_t) CTrsp->Explanation,
466 /* NameServer Rsp Error */
467 lpfc_printf_log(phba,
470 "%d:0241 NameServer Rsp Error "
471 "Data: x%x x%x x%x x%x\n",
473 CTrsp->CommandResponse.bits.CmdRsp,
474 (uint32_t) CTrsp->ReasonCode,
475 (uint32_t) CTrsp->Explanation,
479 /* Link up / RSCN discovery */
480 lpfc_disc_start(vport);
482 lpfc_free_ct_rsp(phba, outp);
483 lpfc_mbuf_free(phba, inp->virt, inp->phys);
484 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
487 lpfc_sli_release_iocbq(phba, cmdiocb);
492 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
493 struct lpfc_iocbq *rspiocb)
495 struct lpfc_dmabuf *bmp;
496 struct lpfc_dmabuf *inp;
497 struct lpfc_dmabuf *outp;
499 struct lpfc_sli_ct_request *CTrsp;
501 /* we pass cmdiocb to state machine which needs rspiocb as well */
502 cmdiocb->context_un.rsp_iocb = rspiocb;
504 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
505 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
506 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
507 irsp = &rspiocb->iocb;
509 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
511 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
512 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
513 "%d:0209 RFT request completes ulpStatus x%x "
514 "CmdRsp x%x, Context x%x, Tag x%x\n",
515 phba->brd_no, irsp->ulpStatus,
516 CTrsp->CommandResponse.bits.CmdRsp,
517 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
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 lpfc_sli_release_iocbq(phba, cmdiocb);
529 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
530 struct lpfc_iocbq *rspiocb)
532 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
537 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
538 struct lpfc_iocbq *rspiocb)
540 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
545 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
546 struct lpfc_iocbq * rspiocb)
548 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
553 lpfc_get_hba_sym_node_name(struct lpfc_hba *phba, uint8_t *symbp)
557 lpfc_decode_firmware_rev(phba, fwrev, 0);
559 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
560 fwrev, lpfc_release_version);
567 * Issue Cmd to NameServer
572 lpfc_ns_cmd(struct lpfc_vport *vport, struct lpfc_nodelist * ndlp, int cmdcode)
574 struct lpfc_hba *phba = vport->phba;
575 struct lpfc_dmabuf *mp, *bmp;
576 struct lpfc_sli_ct_request *CtReq;
577 struct ulp_bde64 *bpl;
578 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
579 struct lpfc_iocbq *) = NULL;
580 uint32_t rsp_size = 1024;
582 /* fill in BDEs for command */
583 /* Allocate buffer for command payload */
584 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
588 INIT_LIST_HEAD(&mp->list);
589 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
593 /* Allocate buffer for Buffer ptr list */
594 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
596 goto ns_cmd_free_mpvirt;
598 INIT_LIST_HEAD(&bmp->list);
599 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
601 goto ns_cmd_free_bmp;
604 lpfc_printf_log(phba,
607 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
608 phba->brd_no, cmdcode, vport->fc_flag,
609 vport->fc_rscn_id_cnt);
611 bpl = (struct ulp_bde64 *) bmp->virt;
612 memset(bpl, 0, sizeof(struct ulp_bde64));
613 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
614 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
615 bpl->tus.f.bdeFlags = 0;
616 if (cmdcode == SLI_CTNS_GID_FT)
617 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
618 else if (cmdcode == SLI_CTNS_RFT_ID)
619 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
620 else if (cmdcode == SLI_CTNS_RNN_ID)
621 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
622 else if (cmdcode == SLI_CTNS_RSNN_NN)
623 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
624 else if (cmdcode == SLI_CTNS_RFF_ID)
625 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
627 bpl->tus.f.bdeSize = 0;
628 bpl->tus.w = le32_to_cpu(bpl->tus.w);
630 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
631 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
632 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
633 CtReq->RevisionId.bits.InId = 0;
634 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
635 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
636 CtReq->CommandResponse.bits.Size = 0;
638 case SLI_CTNS_GID_FT:
639 CtReq->CommandResponse.bits.CmdRsp =
640 be16_to_cpu(SLI_CTNS_GID_FT);
641 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
642 if (vport->port_state < LPFC_VPORT_READY)
643 vport->port_state = LPFC_NS_QRY;
644 lpfc_set_disctmo(vport);
645 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
646 rsp_size = FC_MAX_NS_RSP;
649 case SLI_CTNS_RFT_ID:
650 CtReq->CommandResponse.bits.CmdRsp =
651 be16_to_cpu(SLI_CTNS_RFT_ID);
652 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
653 CtReq->un.rft.fcpReg = 1;
654 cmpl = lpfc_cmpl_ct_cmd_rft_id;
657 case SLI_CTNS_RFF_ID:
658 CtReq->CommandResponse.bits.CmdRsp =
659 be16_to_cpu(SLI_CTNS_RFF_ID);
660 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);
661 CtReq->un.rff.feature_res = 0;
662 CtReq->un.rff.feature_tgt = 0;
663 CtReq->un.rff.type_code = FC_FCP_DATA;
664 CtReq->un.rff.feature_init = 1;
665 cmpl = lpfc_cmpl_ct_cmd_rff_id;
668 case SLI_CTNS_RNN_ID:
669 CtReq->CommandResponse.bits.CmdRsp =
670 be16_to_cpu(SLI_CTNS_RNN_ID);
671 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
672 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
673 sizeof (struct lpfc_name));
674 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
677 case SLI_CTNS_RSNN_NN:
678 CtReq->CommandResponse.bits.CmdRsp =
679 be16_to_cpu(SLI_CTNS_RSNN_NN);
680 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
681 sizeof (struct lpfc_name));
682 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
683 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
684 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
688 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size))
689 /* On success, The cmpl function will free the buffers */
692 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
696 lpfc_mbuf_free(phba, mp->virt, mp->phys);
704 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
705 struct lpfc_iocbq * rspiocb)
707 struct lpfc_dmabuf *bmp = cmdiocb->context3;
708 struct lpfc_dmabuf *inp = cmdiocb->context1;
709 struct lpfc_dmabuf *outp = cmdiocb->context2;
710 struct lpfc_sli_ct_request *CTrsp = outp->virt;
711 struct lpfc_sli_ct_request *CTcmd = inp->virt;
712 struct lpfc_nodelist *ndlp;
713 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
714 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
715 struct lpfc_vport *vport = cmdiocb->vport;
717 ndlp = lpfc_findnode_did(vport, FDMI_DID);
718 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
719 /* FDMI rsp failed */
720 lpfc_printf_log(phba,
723 "%d:0220 FDMI rsp failed Data: x%x\n",
725 be16_to_cpu(fdmi_cmd));
728 switch (be16_to_cpu(fdmi_cmd)) {
730 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
737 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
741 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
745 lpfc_free_ct_rsp(phba, outp);
746 lpfc_mbuf_free(phba, inp->virt, inp->phys);
747 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
750 lpfc_sli_release_iocbq(phba, cmdiocb);
755 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
757 struct lpfc_hba *phba = vport->phba;
758 struct lpfc_dmabuf *mp, *bmp;
759 struct lpfc_sli_ct_request *CtReq;
760 struct ulp_bde64 *bpl;
764 REG_PORT_ATTRIBUTE *pab;
767 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
768 struct lpfc_iocbq *);
771 /* fill in BDEs for command */
772 /* Allocate buffer for command payload */
773 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
777 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
779 goto fdmi_cmd_free_mp;
781 /* Allocate buffer for Buffer ptr list */
782 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
784 goto fdmi_cmd_free_mpvirt;
786 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
788 goto fdmi_cmd_free_bmp;
790 INIT_LIST_HEAD(&mp->list);
791 INIT_LIST_HEAD(&bmp->list);
794 lpfc_printf_log(phba,
797 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
799 vport->fc_flag, vport->port_state, cmdcode);
801 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
803 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
804 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
805 CtReq->RevisionId.bits.InId = 0;
807 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
808 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
814 lpfc_vpd_t *vp = &phba->vpd;
818 CtReq->CommandResponse.bits.CmdRsp =
819 be16_to_cpu(SLI_MGMT_RHBA);
820 CtReq->CommandResponse.bits.Size = 0;
821 rh = (REG_HBA *) & CtReq->un.PortID;
822 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
823 sizeof (struct lpfc_name));
824 /* One entry (port) per adapter */
825 rh->rpl.EntryCnt = be32_to_cpu(1);
826 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
827 sizeof (struct lpfc_name));
829 /* point to the HBA attribute block */
830 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
831 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
834 /* Point to the beginning of the first HBA attribute
836 /* #1 HBA attribute entry */
838 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
839 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
840 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
841 + sizeof (struct lpfc_name));
842 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
843 sizeof (struct lpfc_name));
845 size += FOURBYTES + sizeof (struct lpfc_name);
847 /* #2 HBA attribute entry */
848 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
849 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
850 strcpy(ae->un.Manufacturer, "Emulex Corporation");
851 len = strlen(ae->un.Manufacturer);
852 len += (len & 3) ? (4 - (len & 3)) : 4;
853 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
855 size += FOURBYTES + len;
857 /* #3 HBA attribute entry */
858 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
859 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
860 strcpy(ae->un.SerialNumber, phba->SerialNumber);
861 len = strlen(ae->un.SerialNumber);
862 len += (len & 3) ? (4 - (len & 3)) : 4;
863 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
865 size += FOURBYTES + len;
867 /* #4 HBA attribute entry */
868 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
869 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
870 strcpy(ae->un.Model, phba->ModelName);
871 len = strlen(ae->un.Model);
872 len += (len & 3) ? (4 - (len & 3)) : 4;
873 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
875 size += FOURBYTES + len;
877 /* #5 HBA attribute entry */
878 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
879 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
880 strcpy(ae->un.ModelDescription, phba->ModelDesc);
881 len = strlen(ae->un.ModelDescription);
882 len += (len & 3) ? (4 - (len & 3)) : 4;
883 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
885 size += FOURBYTES + len;
887 /* #6 HBA attribute entry */
888 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
889 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
890 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
891 /* Convert JEDEC ID to ascii for hardware version */
892 incr = vp->rev.biuRev;
893 for (i = 0; i < 8; i++) {
896 ae->un.HardwareVersion[7 - i] =
897 (char)((uint8_t) 0x30 +
900 ae->un.HardwareVersion[7 - i] =
901 (char)((uint8_t) 0x61 +
906 size += FOURBYTES + 8;
908 /* #7 HBA attribute entry */
909 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
910 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
911 strcpy(ae->un.DriverVersion, lpfc_release_version);
912 len = strlen(ae->un.DriverVersion);
913 len += (len & 3) ? (4 - (len & 3)) : 4;
914 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
916 size += FOURBYTES + len;
918 /* #8 HBA attribute entry */
919 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
920 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
921 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
922 len = strlen(ae->un.OptionROMVersion);
923 len += (len & 3) ? (4 - (len & 3)) : 4;
924 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
926 size += FOURBYTES + len;
928 /* #9 HBA attribute entry */
929 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
930 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
931 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
933 len = strlen(ae->un.FirmwareVersion);
934 len += (len & 3) ? (4 - (len & 3)) : 4;
935 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
937 size += FOURBYTES + len;
939 /* #10 HBA attribute entry */
940 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
941 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
942 sprintf(ae->un.OsNameVersion, "%s %s %s",
943 init_utsname()->sysname,
944 init_utsname()->release,
945 init_utsname()->version);
946 len = strlen(ae->un.OsNameVersion);
947 len += (len & 3) ? (4 - (len & 3)) : 4;
948 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
950 size += FOURBYTES + len;
952 /* #11 HBA attribute entry */
953 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
954 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
955 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
956 ae->un.MaxCTPayloadLen = (65 * 4096);
958 size += FOURBYTES + 4;
960 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
962 size = GID_REQUEST_SZ - 4 + size;
969 struct serv_parm *hsp;
974 CtReq->CommandResponse.bits.CmdRsp =
975 be16_to_cpu(SLI_MGMT_RPA);
976 CtReq->CommandResponse.bits.Size = 0;
977 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
978 size = sizeof (struct lpfc_name) + FOURBYTES;
979 memcpy((uint8_t *) & pab->PortName,
980 (uint8_t *) & vport->fc_sparam.portName,
981 sizeof (struct lpfc_name));
982 pab->ab.EntryCnt = 0;
984 /* #1 Port attribute entry */
985 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
986 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
987 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
988 ae->un.SupportFC4Types[2] = 1;
989 ae->un.SupportFC4Types[7] = 1;
991 size += FOURBYTES + 32;
993 /* #2 Port attribute entry */
994 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
995 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
996 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
998 ae->un.SupportSpeed = 0;
999 if (phba->lmt & LMT_10Gb)
1000 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1001 if (phba->lmt & LMT_8Gb)
1002 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1003 if (phba->lmt & LMT_4Gb)
1004 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1005 if (phba->lmt & LMT_2Gb)
1006 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1007 if (phba->lmt & LMT_1Gb)
1008 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1011 size += FOURBYTES + 4;
1013 /* #3 Port attribute entry */
1014 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1015 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1016 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1017 switch(phba->fc_linkspeed) {
1019 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1022 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1025 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1028 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1032 HBA_PORTSPEED_UNKNOWN;
1036 size += FOURBYTES + 4;
1038 /* #4 Port attribute entry */
1039 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1040 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1041 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1042 hsp = (struct serv_parm *) & vport->fc_sparam;
1043 ae->un.MaxFrameSize =
1044 (((uint32_t) hsp->cmn.
1045 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1048 size += FOURBYTES + 4;
1050 /* #5 Port attribute entry */
1051 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1052 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1053 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1054 len = strlen((char *)ae->un.OsDeviceName);
1055 len += (len & 3) ? (4 - (len & 3)) : 4;
1056 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1058 size += FOURBYTES + len;
1060 if (phba->cfg_fdmi_on == 2) {
1061 /* #6 Port attribute entry */
1062 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1064 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1065 sprintf(ae->un.HostName, "%s",
1066 init_utsname()->nodename);
1067 len = strlen(ae->un.HostName);
1068 len += (len & 3) ? (4 - (len & 3)) : 4;
1069 ae->ad.bits.AttrLen =
1070 be16_to_cpu(FOURBYTES + len);
1072 size += FOURBYTES + len;
1075 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1077 size = GID_REQUEST_SZ - 4 + size;
1082 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1083 CtReq->CommandResponse.bits.Size = 0;
1084 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1085 memcpy((uint8_t *) & pe->PortName,
1086 (uint8_t *) & vport->fc_sparam.portName,
1087 sizeof (struct lpfc_name));
1088 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1092 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1093 CtReq->CommandResponse.bits.Size = 0;
1094 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1095 memcpy((uint8_t *) & pe->PortName,
1096 (uint8_t *) & vport->fc_sparam.portName,
1097 sizeof (struct lpfc_name));
1098 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1102 bpl = (struct ulp_bde64 *) bmp->virt;
1103 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1104 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1105 bpl->tus.f.bdeFlags = 0;
1106 bpl->tus.f.bdeSize = size;
1107 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1109 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1111 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1114 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1117 fdmi_cmd_free_mpvirt:
1118 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1122 /* Issue FDMI request failed */
1123 lpfc_printf_log(phba,
1126 "%d:0244 Issue FDMI request failed Data: x%x\n",
1133 lpfc_fdmi_tmo(unsigned long ptr)
1135 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1136 struct lpfc_hba *phba = vport->phba;
1137 unsigned long iflag;
1139 spin_lock_irqsave(&vport->work_port_lock, iflag);
1140 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1141 vport->work_port_events |= WORKER_FDMI_TMO;
1142 if (phba->work_wait)
1143 wake_up(phba->work_wait);
1145 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1149 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1151 struct lpfc_nodelist *ndlp;
1153 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1155 if (init_utsname()->nodename[0] != '\0')
1156 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1158 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1164 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1166 struct lpfc_sli *psli = &phba->sli;
1167 lpfc_vpd_t *vp = &phba->vpd;
1168 uint32_t b1, b2, b3, b4, i, rev;
1170 uint32_t *ptr, str[4];
1174 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1175 rev = vp->rev.sli2FwRev;
1177 rev = vp->rev.sli1FwRev;
1179 b1 = (rev & 0x0000f000) >> 12;
1180 b2 = (rev & 0x00000f00) >> 8;
1181 b3 = (rev & 0x000000c0) >> 6;
1182 b4 = (rev & 0x00000030) >> 4;
1198 b4 = (rev & 0x0000000f);
1200 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1201 fwname = vp->rev.sli2FwName;
1203 fwname = vp->rev.sli1FwName;
1205 for (i = 0; i < 16; i++)
1206 if (fwname[i] == 0x20)
1209 ptr = (uint32_t*)fwname;
1211 for (i = 0; i < 3; i++)
1212 str[i] = be32_to_cpu(*ptr++);
1216 sprintf(fwrevision, "%d.%d%d (%s)",
1217 b1, b2, b3, (char *)str);
1219 sprintf(fwrevision, "%d.%d%d", b1,
1223 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1227 sprintf(fwrevision, "%d.%d%d%c%d",
1231 rev = vp->rev.smFwRev;
1233 b1 = (rev & 0xff000000) >> 24;
1234 b2 = (rev & 0x00f00000) >> 20;
1235 b3 = (rev & 0x000f0000) >> 16;
1236 c = (rev & 0x0000ff00) >> 8;
1237 b4 = (rev & 0x000000ff);
1240 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1243 sprintf(fwrevision, "%d.%d%d%c%d ", b1,