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_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
63 struct lpfc_dmabuf *mp, uint32_t size)
66 printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
67 "piocbq = %p, status = x%x, mp = %p, size = %d\n",
68 __FUNCTION__, __LINE__,
69 piocbq, piocbq->iocb.ulpStatus, mp, size);
72 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
73 "buffer = %p, size = %d, status = x%x\n",
74 __FUNCTION__, __LINE__,
76 piocbq->iocb.ulpStatus);
80 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct hbq_dmabuf *sp, uint32_t size)
83 struct lpfc_dmabuf *mp = NULL;
85 mp = sp ? &sp->dbuf : NULL;
87 printk(KERN_ERR "%s (%d): Unsolited CT, no "
88 "HBQ buffer, piocbq = %p, status = x%x\n",
89 __FUNCTION__, __LINE__,
90 piocbq, piocbq->iocb.ulpStatus);
92 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
93 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
94 "piocbq = %p, buffer = %p, size = %d, "
96 __FUNCTION__, __LINE__,
97 piocbq, mp, size, piocbq->iocb.ulpStatus);
102 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
103 struct lpfc_iocbq *piocbq)
105 struct lpfc_dmabuf *mp = NULL;
106 struct hbq_dmabuf *sp = NULL;
107 IOCB_t *icmd = &piocbq->iocb;
109 struct lpfc_iocbq *iocbq;
113 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
114 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
115 /* Not enough posted buffers; Try posting more buffers */
116 phba->fc_stat.NoRcvBuf++;
117 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
118 lpfc_sli_hbqbuf_fill_hbq(phba);
120 lpfc_post_buffer(phba, pring, 0, 1);
124 /* If there are no BDEs associated with this IOCB,
125 * there is nothing to do.
127 if (icmd->ulpBdeCount == 0)
130 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
131 list_for_each_entry(iocbq, &piocbq->list, list) {
133 if (icmd->ulpBdeCount == 0) {
134 printk(KERN_ERR "%s (%d): Unsolited CT, no "
135 "BDE, iocbq = %p, status = x%x\n",
136 __FUNCTION__, __LINE__,
137 iocbq, iocbq->iocb.ulpStatus);
141 size = icmd->un.cont64[0].tus.f.bdeSize;
142 sp = lpfc_sli_hbqbuf_find(phba, icmd->un.ulpWord[3]);
144 phba->hbq_buff_count--;
145 lpfc_ct_ignore_hbq_buffer(phba, iocbq, sp, size);
146 lpfc_sli_free_hbq(phba, sp);
147 if (icmd->ulpBdeCount == 2) {
148 sp = lpfc_sli_hbqbuf_find(phba,
149 icmd->un.ulpWord[15]);
151 phba->hbq_buff_count--;
152 lpfc_ct_ignore_hbq_buffer(phba, iocbq, sp,
154 lpfc_sli_free_hbq(phba, sp);
158 lpfc_sli_hbqbuf_fill_hbq(phba);
160 struct lpfc_iocbq *next;
162 list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
164 if (icmd->ulpBdeCount == 0) {
165 printk(KERN_ERR "%s (%d): Unsolited CT, no "
166 "BDE, iocbq = %p, status = x%x\n",
167 __FUNCTION__, __LINE__,
168 iocbq, iocbq->iocb.ulpStatus);
172 for (i = 0; i < icmd->ulpBdeCount; i++) {
173 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
174 icmd->un.cont64[i].addrLow);
175 mp = lpfc_sli_ringpostbuf_get(phba, pring,
177 size = icmd->un.cont64[i].tus.f.bdeSize;
178 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
179 lpfc_mbuf_free(phba, mp->virt, mp->phys);
182 list_del(&iocbq->list);
183 lpfc_sli_release_iocbq(phba, iocbq);
189 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
191 struct lpfc_dmabuf *mlast, *next_mlast;
193 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
194 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
195 list_del(&mlast->list);
198 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
203 static struct lpfc_dmabuf *
204 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
205 uint32_t size, int *entries)
207 struct lpfc_dmabuf *mlist = NULL;
208 struct lpfc_dmabuf *mp;
211 /* We get chucks of FCELSSIZE */
212 cnt = size > FCELSSIZE ? FCELSSIZE: size;
215 /* Allocate buffer for rsp payload */
216 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
219 lpfc_free_ct_rsp(phba, mlist);
223 INIT_LIST_HEAD(&mp->list);
225 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
226 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
228 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
233 lpfc_free_ct_rsp(phba, mlist);
237 /* Queue it to a linked list */
241 list_add_tail(&mp->list, &mlist->list);
243 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
244 /* build buffer ptr list for IOCB */
245 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
246 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
247 bpl->tus.f.bdeSize = (uint16_t) cnt;
248 bpl->tus.w = le32_to_cpu(bpl->tus.w);
260 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
261 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
262 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
263 struct lpfc_iocbq *),
264 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
267 struct lpfc_hba *phba = vport->phba;
268 struct lpfc_sli *psli = &phba->sli;
269 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
271 struct lpfc_iocbq *geniocb;
273 /* Allocate buffer for command iocb */
274 geniocb = lpfc_sli_get_iocbq(phba);
279 icmd = &geniocb->iocb;
280 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
281 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
282 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
283 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
284 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
287 geniocb->context3 = NULL;
289 geniocb->context3 = (uint8_t *) bmp;
291 /* Save for completion so we can release these resources */
292 geniocb->context1 = (uint8_t *) inp;
293 geniocb->context2 = (uint8_t *) outp;
295 /* Fill in payload, bp points to frame payload */
296 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
298 /* Fill in rest of iocb */
299 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
300 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
301 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
302 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
305 /* FC spec states we need 3 * ratov for CT requests */
306 tmo = (3 * phba->fc_ratov);
308 icmd->ulpTimeout = tmo;
309 icmd->ulpBdeCount = 1;
311 icmd->ulpClass = CLASS3;
312 icmd->ulpContext = ndlp->nlp_rpi;
314 /* Issue GEN REQ IOCB for NPORT <did> */
315 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
316 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
317 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
318 icmd->ulpIoTag, vport->port_state);
319 geniocb->iocb_cmpl = cmpl;
320 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
321 geniocb->vport = vport;
322 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
323 lpfc_sli_release_iocbq(phba, geniocb);
331 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
332 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
333 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
334 struct lpfc_iocbq *),
337 struct lpfc_hba *phba = vport->phba;
338 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
339 struct lpfc_dmabuf *outmp;
341 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
342 CommandResponse.bits.CmdRsp;
344 bpl++; /* Skip past ct request */
346 /* Put buffer(s) for ct rsp in bpl */
347 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
351 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
354 lpfc_free_ct_rsp(phba, outmp);
361 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
364 struct lpfc_hba *phba = vport->phba;
365 struct lpfc_sli_ct_request *Response =
366 (struct lpfc_sli_ct_request *) mp->virt;
367 struct lpfc_nodelist *ndlp = NULL;
368 struct lpfc_dmabuf *mlast, *next_mp;
369 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
370 uint32_t Did, CTentry;
372 struct list_head head;
374 lpfc_set_disctmo(vport);
377 list_add_tail(&head, &mp->list);
378 list_for_each_entry_safe(mp, next_mp, &head, list) {
381 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
386 ctptr = (uint32_t *) mlast->virt;
388 Cnt -= 16; /* subtract length of CT header */
390 /* Loop through entire NameServer list of DIDs */
391 while (Cnt >= sizeof (uint32_t)) {
392 /* Get next DID from NameServer List */
394 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
396 /* Check for rscn processing or not */
397 if (Did != vport->fc_myDID)
398 ndlp = lpfc_setup_disc_node(vport, Did);
400 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
401 "%d:0238 Process x%x NameServer"
402 " Rsp Data: x%x x%x x%x\n",
406 vport->fc_rscn_id_cnt);
408 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
409 "%d:0239 Skip x%x NameServer "
410 "Rsp Data: x%x x%x x%x\n",
412 Did, Size, vport->fc_flag,
413 vport->fc_rscn_id_cnt);
415 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
417 Cnt -= sizeof (uint32_t);
427 * The driver has cycled through all Nports in the RSCN payload.
428 * Complete the handling by cleaning up and marking the
429 * current driver state.
431 if (vport->port_state == LPFC_VPORT_READY) {
432 lpfc_els_flush_rscn(vport);
433 spin_lock_irq(shost->host_lock);
434 vport->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
435 spin_unlock_irq(shost->host_lock);
444 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
445 struct lpfc_iocbq *rspiocb)
447 struct lpfc_vport *vport = cmdiocb->vport;
449 struct lpfc_dmabuf *bmp;
450 struct lpfc_dmabuf *inp;
451 struct lpfc_dmabuf *outp;
452 struct lpfc_nodelist *ndlp;
453 struct lpfc_sli_ct_request *CTrsp;
456 /* we pass cmdiocb to state machine which needs rspiocb as well */
457 cmdiocb->context_un.rsp_iocb = rspiocb;
459 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
460 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
461 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
463 irsp = &rspiocb->iocb;
464 if (irsp->ulpStatus) {
465 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
466 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
467 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
470 /* Check for retry */
471 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
472 vport->fc_ns_retry++;
473 /* CT command is being retried */
474 ndlp = lpfc_findnode_did(vport, NameServer_DID);
475 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
476 rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
482 /* Good status, continue checking */
483 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
484 if (CTrsp->CommandResponse.bits.CmdRsp ==
485 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
486 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
487 "%d:0208 NameServer Rsp "
491 lpfc_ns_rsp(vport, outp,
492 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
493 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
494 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
495 /* NameServer Rsp Error */
496 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
497 "%d:0240 NameServer Rsp Error "
498 "Data: x%x x%x x%x x%x\n",
500 CTrsp->CommandResponse.bits.CmdRsp,
501 (uint32_t) CTrsp->ReasonCode,
502 (uint32_t) CTrsp->Explanation,
505 /* NameServer Rsp Error */
506 lpfc_printf_log(phba,
509 "%d:0241 NameServer Rsp Error "
510 "Data: x%x x%x x%x x%x\n",
512 CTrsp->CommandResponse.bits.CmdRsp,
513 (uint32_t) CTrsp->ReasonCode,
514 (uint32_t) CTrsp->Explanation,
518 /* Link up / RSCN discovery */
519 lpfc_disc_start(vport);
521 lpfc_free_ct_rsp(phba, outp);
522 lpfc_mbuf_free(phba, inp->virt, inp->phys);
523 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
526 lpfc_sli_release_iocbq(phba, cmdiocb);
531 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
532 struct lpfc_iocbq *rspiocb)
534 struct lpfc_dmabuf *bmp;
535 struct lpfc_dmabuf *inp;
536 struct lpfc_dmabuf *outp;
538 struct lpfc_sli_ct_request *CTrsp;
540 /* we pass cmdiocb to state machine which needs rspiocb as well */
541 cmdiocb->context_un.rsp_iocb = rspiocb;
543 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
544 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
545 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
546 irsp = &rspiocb->iocb;
548 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
550 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
551 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
552 "%d:0209 RFT request completes ulpStatus x%x "
553 "CmdRsp x%x, Context x%x, Tag x%x\n",
554 phba->brd_no, irsp->ulpStatus,
555 CTrsp->CommandResponse.bits.CmdRsp,
556 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
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 lpfc_sli_release_iocbq(phba, cmdiocb);
568 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
569 struct lpfc_iocbq *rspiocb)
571 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
576 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
577 struct lpfc_iocbq *rspiocb)
579 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
584 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
585 struct lpfc_iocbq * rspiocb)
587 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
592 lpfc_get_hba_sym_node_name(struct lpfc_hba *phba, uint8_t *symbp)
596 lpfc_decode_firmware_rev(phba, fwrev, 0);
598 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
599 fwrev, lpfc_release_version);
606 * Issue Cmd to NameServer
611 lpfc_ns_cmd(struct lpfc_vport *vport, struct lpfc_nodelist * ndlp, int cmdcode)
613 struct lpfc_hba *phba = vport->phba;
614 struct lpfc_dmabuf *mp, *bmp;
615 struct lpfc_sli_ct_request *CtReq;
616 struct ulp_bde64 *bpl;
617 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
618 struct lpfc_iocbq *) = NULL;
619 uint32_t rsp_size = 1024;
621 /* fill in BDEs for command */
622 /* Allocate buffer for command payload */
623 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
627 INIT_LIST_HEAD(&mp->list);
628 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
632 /* Allocate buffer for Buffer ptr list */
633 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
635 goto ns_cmd_free_mpvirt;
637 INIT_LIST_HEAD(&bmp->list);
638 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
640 goto ns_cmd_free_bmp;
643 lpfc_printf_log(phba,
646 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
647 phba->brd_no, cmdcode, vport->fc_flag,
648 vport->fc_rscn_id_cnt);
650 bpl = (struct ulp_bde64 *) bmp->virt;
651 memset(bpl, 0, sizeof(struct ulp_bde64));
652 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
653 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
654 bpl->tus.f.bdeFlags = 0;
655 if (cmdcode == SLI_CTNS_GID_FT)
656 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
657 else if (cmdcode == SLI_CTNS_RFT_ID)
658 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
659 else if (cmdcode == SLI_CTNS_RNN_ID)
660 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
661 else if (cmdcode == SLI_CTNS_RSNN_NN)
662 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
663 else if (cmdcode == SLI_CTNS_RFF_ID)
664 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
666 bpl->tus.f.bdeSize = 0;
667 bpl->tus.w = le32_to_cpu(bpl->tus.w);
669 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
670 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
671 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
672 CtReq->RevisionId.bits.InId = 0;
673 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
674 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
675 CtReq->CommandResponse.bits.Size = 0;
677 case SLI_CTNS_GID_FT:
678 CtReq->CommandResponse.bits.CmdRsp =
679 be16_to_cpu(SLI_CTNS_GID_FT);
680 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
681 if (vport->port_state < LPFC_VPORT_READY)
682 vport->port_state = LPFC_NS_QRY;
683 lpfc_set_disctmo(vport);
684 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
685 rsp_size = FC_MAX_NS_RSP;
688 case SLI_CTNS_RFT_ID:
689 CtReq->CommandResponse.bits.CmdRsp =
690 be16_to_cpu(SLI_CTNS_RFT_ID);
691 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
692 CtReq->un.rft.fcpReg = 1;
693 cmpl = lpfc_cmpl_ct_cmd_rft_id;
696 case SLI_CTNS_RFF_ID:
697 CtReq->CommandResponse.bits.CmdRsp =
698 be16_to_cpu(SLI_CTNS_RFF_ID);
699 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);
700 CtReq->un.rff.feature_res = 0;
701 CtReq->un.rff.feature_tgt = 0;
702 CtReq->un.rff.type_code = FC_FCP_DATA;
703 CtReq->un.rff.feature_init = 1;
704 cmpl = lpfc_cmpl_ct_cmd_rff_id;
707 case SLI_CTNS_RNN_ID:
708 CtReq->CommandResponse.bits.CmdRsp =
709 be16_to_cpu(SLI_CTNS_RNN_ID);
710 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
711 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
712 sizeof (struct lpfc_name));
713 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
716 case SLI_CTNS_RSNN_NN:
717 CtReq->CommandResponse.bits.CmdRsp =
718 be16_to_cpu(SLI_CTNS_RSNN_NN);
719 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
720 sizeof (struct lpfc_name));
721 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
722 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
723 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
727 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size))
728 /* On success, The cmpl function will free the buffers */
731 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
735 lpfc_mbuf_free(phba, mp->virt, mp->phys);
743 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
744 struct lpfc_iocbq * rspiocb)
746 struct lpfc_dmabuf *bmp = cmdiocb->context3;
747 struct lpfc_dmabuf *inp = cmdiocb->context1;
748 struct lpfc_dmabuf *outp = cmdiocb->context2;
749 struct lpfc_sli_ct_request *CTrsp = outp->virt;
750 struct lpfc_sli_ct_request *CTcmd = inp->virt;
751 struct lpfc_nodelist *ndlp;
752 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
753 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
754 struct lpfc_vport *vport = cmdiocb->vport;
756 ndlp = lpfc_findnode_did(vport, FDMI_DID);
757 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
758 /* FDMI rsp failed */
759 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
760 "%d:0220 FDMI rsp failed Data: x%x\n",
761 phba->brd_no, be16_to_cpu(fdmi_cmd));
764 switch (be16_to_cpu(fdmi_cmd)) {
766 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
773 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
777 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
781 lpfc_free_ct_rsp(phba, outp);
782 lpfc_mbuf_free(phba, inp->virt, inp->phys);
783 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
786 lpfc_sli_release_iocbq(phba, cmdiocb);
791 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
793 struct lpfc_hba *phba = vport->phba;
794 struct lpfc_dmabuf *mp, *bmp;
795 struct lpfc_sli_ct_request *CtReq;
796 struct ulp_bde64 *bpl;
800 REG_PORT_ATTRIBUTE *pab;
803 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
804 struct lpfc_iocbq *);
807 /* fill in BDEs for command */
808 /* Allocate buffer for command payload */
809 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
813 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
815 goto fdmi_cmd_free_mp;
817 /* Allocate buffer for Buffer ptr list */
818 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
820 goto fdmi_cmd_free_mpvirt;
822 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
824 goto fdmi_cmd_free_bmp;
826 INIT_LIST_HEAD(&mp->list);
827 INIT_LIST_HEAD(&bmp->list);
830 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
831 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
833 vport->fc_flag, vport->port_state, cmdcode);
835 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
837 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
838 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
839 CtReq->RevisionId.bits.InId = 0;
841 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
842 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
848 lpfc_vpd_t *vp = &phba->vpd;
852 CtReq->CommandResponse.bits.CmdRsp =
853 be16_to_cpu(SLI_MGMT_RHBA);
854 CtReq->CommandResponse.bits.Size = 0;
855 rh = (REG_HBA *) & CtReq->un.PortID;
856 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
857 sizeof (struct lpfc_name));
858 /* One entry (port) per adapter */
859 rh->rpl.EntryCnt = be32_to_cpu(1);
860 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
861 sizeof (struct lpfc_name));
863 /* point to the HBA attribute block */
864 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
865 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
868 /* Point to the beginning of the first HBA attribute
870 /* #1 HBA attribute entry */
872 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
873 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
874 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
875 + sizeof (struct lpfc_name));
876 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
877 sizeof (struct lpfc_name));
879 size += FOURBYTES + sizeof (struct lpfc_name);
881 /* #2 HBA attribute entry */
882 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
883 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
884 strcpy(ae->un.Manufacturer, "Emulex Corporation");
885 len = strlen(ae->un.Manufacturer);
886 len += (len & 3) ? (4 - (len & 3)) : 4;
887 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
889 size += FOURBYTES + len;
891 /* #3 HBA attribute entry */
892 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
893 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
894 strcpy(ae->un.SerialNumber, phba->SerialNumber);
895 len = strlen(ae->un.SerialNumber);
896 len += (len & 3) ? (4 - (len & 3)) : 4;
897 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
899 size += FOURBYTES + len;
901 /* #4 HBA attribute entry */
902 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
903 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
904 strcpy(ae->un.Model, phba->ModelName);
905 len = strlen(ae->un.Model);
906 len += (len & 3) ? (4 - (len & 3)) : 4;
907 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
909 size += FOURBYTES + len;
911 /* #5 HBA attribute entry */
912 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
913 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
914 strcpy(ae->un.ModelDescription, phba->ModelDesc);
915 len = strlen(ae->un.ModelDescription);
916 len += (len & 3) ? (4 - (len & 3)) : 4;
917 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
919 size += FOURBYTES + len;
921 /* #6 HBA attribute entry */
922 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
923 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
924 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
925 /* Convert JEDEC ID to ascii for hardware version */
926 incr = vp->rev.biuRev;
927 for (i = 0; i < 8; i++) {
930 ae->un.HardwareVersion[7 - i] =
931 (char)((uint8_t) 0x30 +
934 ae->un.HardwareVersion[7 - i] =
935 (char)((uint8_t) 0x61 +
940 size += FOURBYTES + 8;
942 /* #7 HBA attribute entry */
943 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
944 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
945 strcpy(ae->un.DriverVersion, lpfc_release_version);
946 len = strlen(ae->un.DriverVersion);
947 len += (len & 3) ? (4 - (len & 3)) : 4;
948 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
950 size += FOURBYTES + len;
952 /* #8 HBA attribute entry */
953 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
954 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
955 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
956 len = strlen(ae->un.OptionROMVersion);
957 len += (len & 3) ? (4 - (len & 3)) : 4;
958 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
960 size += FOURBYTES + len;
962 /* #9 HBA attribute entry */
963 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
964 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
965 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
967 len = strlen(ae->un.FirmwareVersion);
968 len += (len & 3) ? (4 - (len & 3)) : 4;
969 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
971 size += FOURBYTES + len;
973 /* #10 HBA attribute entry */
974 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
975 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
976 sprintf(ae->un.OsNameVersion, "%s %s %s",
977 init_utsname()->sysname,
978 init_utsname()->release,
979 init_utsname()->version);
980 len = strlen(ae->un.OsNameVersion);
981 len += (len & 3) ? (4 - (len & 3)) : 4;
982 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
984 size += FOURBYTES + len;
986 /* #11 HBA attribute entry */
987 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
988 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
989 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
990 ae->un.MaxCTPayloadLen = (65 * 4096);
992 size += FOURBYTES + 4;
994 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
996 size = GID_REQUEST_SZ - 4 + size;
1003 struct serv_parm *hsp;
1008 CtReq->CommandResponse.bits.CmdRsp =
1009 be16_to_cpu(SLI_MGMT_RPA);
1010 CtReq->CommandResponse.bits.Size = 0;
1011 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1012 size = sizeof (struct lpfc_name) + FOURBYTES;
1013 memcpy((uint8_t *) & pab->PortName,
1014 (uint8_t *) & vport->fc_sparam.portName,
1015 sizeof (struct lpfc_name));
1016 pab->ab.EntryCnt = 0;
1018 /* #1 Port attribute entry */
1019 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1020 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1021 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1022 ae->un.SupportFC4Types[2] = 1;
1023 ae->un.SupportFC4Types[7] = 1;
1025 size += FOURBYTES + 32;
1027 /* #2 Port attribute entry */
1028 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1029 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1030 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1032 ae->un.SupportSpeed = 0;
1033 if (phba->lmt & LMT_10Gb)
1034 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1035 if (phba->lmt & LMT_8Gb)
1036 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1037 if (phba->lmt & LMT_4Gb)
1038 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1039 if (phba->lmt & LMT_2Gb)
1040 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1041 if (phba->lmt & LMT_1Gb)
1042 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1045 size += FOURBYTES + 4;
1047 /* #3 Port attribute entry */
1048 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1049 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1050 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1051 switch(phba->fc_linkspeed) {
1053 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1056 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1059 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1062 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1066 HBA_PORTSPEED_UNKNOWN;
1070 size += FOURBYTES + 4;
1072 /* #4 Port attribute entry */
1073 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1074 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1075 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1076 hsp = (struct serv_parm *) & vport->fc_sparam;
1077 ae->un.MaxFrameSize =
1078 (((uint32_t) hsp->cmn.
1079 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1082 size += FOURBYTES + 4;
1084 /* #5 Port attribute entry */
1085 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1086 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1087 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1088 len = strlen((char *)ae->un.OsDeviceName);
1089 len += (len & 3) ? (4 - (len & 3)) : 4;
1090 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1092 size += FOURBYTES + len;
1094 if (phba->cfg_fdmi_on == 2) {
1095 /* #6 Port attribute entry */
1096 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1098 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1099 sprintf(ae->un.HostName, "%s",
1100 init_utsname()->nodename);
1101 len = strlen(ae->un.HostName);
1102 len += (len & 3) ? (4 - (len & 3)) : 4;
1103 ae->ad.bits.AttrLen =
1104 be16_to_cpu(FOURBYTES + len);
1106 size += FOURBYTES + len;
1109 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1111 size = GID_REQUEST_SZ - 4 + size;
1116 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1117 CtReq->CommandResponse.bits.Size = 0;
1118 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1119 memcpy((uint8_t *) & pe->PortName,
1120 (uint8_t *) & vport->fc_sparam.portName,
1121 sizeof (struct lpfc_name));
1122 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1126 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1127 CtReq->CommandResponse.bits.Size = 0;
1128 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1129 memcpy((uint8_t *) & pe->PortName,
1130 (uint8_t *) & vport->fc_sparam.portName,
1131 sizeof (struct lpfc_name));
1132 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1136 bpl = (struct ulp_bde64 *) bmp->virt;
1137 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1138 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1139 bpl->tus.f.bdeFlags = 0;
1140 bpl->tus.f.bdeSize = size;
1141 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1143 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1145 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1148 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1151 fdmi_cmd_free_mpvirt:
1152 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1156 /* Issue FDMI request failed */
1157 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1158 "%d:0244 Issue FDMI request failed Data: x%x\n",
1159 phba->brd_no, cmdcode);
1164 lpfc_fdmi_tmo(unsigned long ptr)
1166 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1167 struct lpfc_hba *phba = vport->phba;
1168 unsigned long iflag;
1170 spin_lock_irqsave(&vport->work_port_lock, iflag);
1171 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1172 vport->work_port_events |= WORKER_FDMI_TMO;
1173 if (phba->work_wait)
1174 wake_up(phba->work_wait);
1176 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1180 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1182 struct lpfc_nodelist *ndlp;
1184 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1186 if (init_utsname()->nodename[0] != '\0')
1187 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1189 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1195 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1197 struct lpfc_sli *psli = &phba->sli;
1198 lpfc_vpd_t *vp = &phba->vpd;
1199 uint32_t b1, b2, b3, b4, i, rev;
1201 uint32_t *ptr, str[4];
1205 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1206 rev = vp->rev.sli2FwRev;
1208 rev = vp->rev.sli1FwRev;
1210 b1 = (rev & 0x0000f000) >> 12;
1211 b2 = (rev & 0x00000f00) >> 8;
1212 b3 = (rev & 0x000000c0) >> 6;
1213 b4 = (rev & 0x00000030) >> 4;
1229 b4 = (rev & 0x0000000f);
1231 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1232 fwname = vp->rev.sli2FwName;
1234 fwname = vp->rev.sli1FwName;
1236 for (i = 0; i < 16; i++)
1237 if (fwname[i] == 0x20)
1240 ptr = (uint32_t*)fwname;
1242 for (i = 0; i < 3; i++)
1243 str[i] = be32_to_cpu(*ptr++);
1247 sprintf(fwrevision, "%d.%d%d (%s)",
1248 b1, b2, b3, (char *)str);
1250 sprintf(fwrevision, "%d.%d%d", b1,
1254 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1258 sprintf(fwrevision, "%d.%d%d%c%d",
1262 rev = vp->rev.smFwRev;
1264 b1 = (rev & 0xff000000) >> 24;
1265 b2 = (rev & 0x00f00000) >> 20;
1266 b3 = (rev & 0x000f0000) >> 16;
1267 c = (rev & 0x0000ff00) >> 8;
1268 b4 = (rev & 0x000000ff);
1271 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1274 sprintf(fwrevision, "%d.%d%d%c%d ", b1,