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"
43 #include "lpfc_vport.h"
45 #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
46 * incapable of reporting */
47 #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
48 #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
49 #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
50 #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
51 #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
52 #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
57 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
63 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
64 struct lpfc_dmabuf *mp, uint32_t size)
67 printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
68 "piocbq = %p, status = x%x, mp = %p, size = %d\n",
69 __FUNCTION__, __LINE__,
70 piocbq, piocbq->iocb.ulpStatus, mp, size);
73 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
74 "buffer = %p, size = %d, status = x%x\n",
75 __FUNCTION__, __LINE__,
77 piocbq->iocb.ulpStatus);
82 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
83 struct lpfc_dmabuf *mp, uint32_t size)
86 printk(KERN_ERR "%s (%d): Unsolited CT, no "
87 "HBQ buffer, piocbq = %p, status = x%x\n",
88 __FUNCTION__, __LINE__,
89 piocbq, piocbq->iocb.ulpStatus);
91 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
92 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
93 "piocbq = %p, buffer = %p, size = %d, "
95 __FUNCTION__, __LINE__,
96 piocbq, mp, size, piocbq->iocb.ulpStatus);
101 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
102 struct lpfc_iocbq *piocbq)
105 struct lpfc_dmabuf *mp = NULL;
106 IOCB_t *icmd = &piocbq->iocb;
108 struct lpfc_iocbq *iocbq;
111 struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
112 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
114 piocbq->context2 = NULL;
115 piocbq->context3 = NULL;
117 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
118 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
119 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
120 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
121 /* Not enough posted buffers; Try posting more buffers */
122 phba->fc_stat.NoRcvBuf++;
123 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
124 lpfc_post_buffer(phba, pring, 0, 1);
128 /* If there are no BDEs associated with this IOCB,
129 * there is nothing to do.
131 if (icmd->ulpBdeCount == 0)
134 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
135 list_for_each_entry(iocbq, &piocbq->list, list) {
137 if (icmd->ulpBdeCount == 0) {
138 printk(KERN_ERR "%s (%d): Unsolited CT, no "
139 "BDE, iocbq = %p, status = x%x\n",
140 __FUNCTION__, __LINE__,
141 iocbq, iocbq->iocb.ulpStatus);
145 size = icmd->un.cont64[0].tus.f.bdeSize;
146 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf1, size);
147 lpfc_in_buf_free(phba, bdeBuf1);
148 if (icmd->ulpBdeCount == 2) {
149 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf2,
151 lpfc_in_buf_free(phba, bdeBuf2);
155 struct lpfc_iocbq *next;
157 list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
159 if (icmd->ulpBdeCount == 0) {
160 printk(KERN_ERR "%s (%d): Unsolited CT, no "
161 "BDE, iocbq = %p, status = x%x\n",
162 __FUNCTION__, __LINE__,
163 iocbq, iocbq->iocb.ulpStatus);
167 for (i = 0; i < icmd->ulpBdeCount; i++) {
168 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
169 icmd->un.cont64[i].addrLow);
170 mp = lpfc_sli_ringpostbuf_get(phba, pring,
172 size = icmd->un.cont64[i].tus.f.bdeSize;
173 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
174 lpfc_in_buf_free(phba, mp);
176 list_del(&iocbq->list);
177 lpfc_sli_release_iocbq(phba, iocbq);
183 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
185 struct lpfc_dmabuf *mlast, *next_mlast;
187 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
188 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
189 list_del(&mlast->list);
192 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
197 static struct lpfc_dmabuf *
198 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
199 uint32_t size, int *entries)
201 struct lpfc_dmabuf *mlist = NULL;
202 struct lpfc_dmabuf *mp;
205 /* We get chucks of FCELSSIZE */
206 cnt = size > FCELSSIZE ? FCELSSIZE: size;
209 /* Allocate buffer for rsp payload */
210 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
213 lpfc_free_ct_rsp(phba, mlist);
217 INIT_LIST_HEAD(&mp->list);
219 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
220 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
221 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
223 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
228 lpfc_free_ct_rsp(phba, mlist);
232 /* Queue it to a linked list */
236 list_add_tail(&mp->list, &mlist->list);
238 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
239 /* build buffer ptr list for IOCB */
240 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
241 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
242 bpl->tus.f.bdeSize = (uint16_t) cnt;
243 bpl->tus.w = le32_to_cpu(bpl->tus.w);
255 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
256 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
257 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
258 struct lpfc_iocbq *),
259 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
260 uint32_t tmo, uint8_t retry)
262 struct lpfc_hba *phba = vport->phba;
263 struct lpfc_sli *psli = &phba->sli;
264 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
266 struct lpfc_iocbq *geniocb;
269 /* Allocate buffer for command iocb */
270 geniocb = lpfc_sli_get_iocbq(phba);
275 icmd = &geniocb->iocb;
276 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
277 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
278 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
279 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
280 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
283 geniocb->context3 = NULL;
285 geniocb->context3 = (uint8_t *) bmp;
287 /* Save for completion so we can release these resources */
288 geniocb->context1 = (uint8_t *) inp;
289 geniocb->context2 = (uint8_t *) outp;
291 /* Fill in payload, bp points to frame payload */
292 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
294 /* Fill in rest of iocb */
295 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
296 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
297 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
298 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
301 /* FC spec states we need 3 * ratov for CT requests */
302 tmo = (3 * phba->fc_ratov);
304 icmd->ulpTimeout = tmo;
305 icmd->ulpBdeCount = 1;
307 icmd->ulpClass = CLASS3;
308 icmd->ulpContext = ndlp->nlp_rpi;
310 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
311 /* For GEN_REQUEST64_CR, use the RPI */
316 /* Issue GEN REQ IOCB for NPORT <did> */
317 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
318 "%d (%d):0119 Issue GEN REQ IOCB to NPORT x%x "
319 "Data: x%x x%x\n", phba->brd_no, vport->vpi,
320 ndlp->nlp_DID, icmd->ulpIoTag,
322 geniocb->iocb_cmpl = cmpl;
323 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
324 geniocb->vport = vport;
325 geniocb->retry = retry;
326 rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
328 if (rc == IOCB_ERROR) {
329 lpfc_sli_release_iocbq(phba, geniocb);
337 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
338 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
339 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
340 struct lpfc_iocbq *),
341 uint32_t rsp_size, uint8_t retry)
343 struct lpfc_hba *phba = vport->phba;
344 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
345 struct lpfc_dmabuf *outmp;
347 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
348 CommandResponse.bits.CmdRsp;
350 bpl++; /* Skip past ct request */
352 /* Put buffer(s) for ct rsp in bpl */
353 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
357 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
360 lpfc_free_ct_rsp(phba, outmp);
366 static struct lpfc_vport *
367 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
369 struct lpfc_vport *vport_curr;
371 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
372 if ((vport_curr->fc_myDID) &&
373 (vport_curr->fc_myDID == did))
381 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
383 struct lpfc_hba *phba = vport->phba;
384 struct lpfc_sli_ct_request *Response =
385 (struct lpfc_sli_ct_request *) mp->virt;
386 struct lpfc_nodelist *ndlp = NULL;
387 struct lpfc_dmabuf *mlast, *next_mp;
388 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
389 uint32_t Did, CTentry;
391 struct list_head head;
393 lpfc_set_disctmo(vport);
394 vport->num_disc_nodes = 0;
397 list_add_tail(&head, &mp->list);
398 list_for_each_entry_safe(mp, next_mp, &head, list) {
401 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
406 ctptr = (uint32_t *) mlast->virt;
408 Cnt -= 16; /* subtract length of CT header */
410 /* Loop through entire NameServer list of DIDs */
411 while (Cnt >= sizeof (uint32_t)) {
412 /* Get next DID from NameServer List */
414 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
419 * Check for rscn processing or not
420 * To conserve rpi's, filter out addresses for other
421 * vports on the same physical HBAs.
423 if ((Did != vport->fc_myDID) &&
424 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
425 phba->cfg_peer_port_login)) {
426 if ((vport->port_type != LPFC_NPIV_PORT) ||
427 (vport->fc_flag & FC_RFF_NOT_SUPPORTED) ||
428 (!phba->cfg_vport_restrict_login)) {
429 ndlp = lpfc_setup_disc_node(vport, Did);
431 lpfc_printf_log(phba, KERN_INFO,
433 "%d (%d):0238 Process "
435 "Data: x%x x%x x%x\n",
440 vport->fc_rscn_id_cnt);
442 lpfc_printf_log(phba, KERN_INFO,
444 "%d (%d):0239 Skip x%x "
445 "NameServer Rsp Data: "
450 vport->fc_rscn_id_cnt);
454 if (!(vport->fc_flag & FC_RSCN_MODE) ||
455 (lpfc_rscn_payload_check(vport, Did))) {
456 if (lpfc_ns_cmd(vport,
459 vport->num_disc_nodes++;
462 lpfc_printf_log(phba, KERN_INFO,
464 "%d (%d):0245 Skip x%x "
465 "NameServer Rsp Data: "
470 vport->fc_rscn_id_cnt);
474 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
476 Cnt -= sizeof (uint32_t);
488 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
489 struct lpfc_iocbq *rspiocb)
491 struct lpfc_vport *vport = cmdiocb->vport;
492 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
494 struct lpfc_dmabuf *bmp;
495 struct lpfc_dmabuf *inp;
496 struct lpfc_dmabuf *outp;
497 struct lpfc_sli_ct_request *CTrsp;
500 /* we pass cmdiocb to state machine which needs rspiocb as well */
501 cmdiocb->context_un.rsp_iocb = rspiocb;
503 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
504 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
505 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
507 /* Don't bother processing response if vport is being torn down. */
508 if (vport->load_flag & FC_UNLOADING)
511 irsp = &rspiocb->iocb;
512 if (irsp->ulpStatus) {
513 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
514 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
515 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
518 /* Check for retry */
519 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
520 vport->fc_ns_retry++;
521 /* CT command is being retried */
522 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
523 vport->fc_ns_retry, 0);
528 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
529 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
530 "%d (%d):0257 GID_FT Query error: 0x%x 0x%x\n",
531 phba->brd_no, vport->vpi, irsp->ulpStatus,
534 /* Good status, continue checking */
535 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
536 if (CTrsp->CommandResponse.bits.CmdRsp ==
537 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
538 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
539 "%d (%d):0208 NameServer Rsp "
541 phba->brd_no, vport->vpi,
543 lpfc_ns_rsp(vport, outp,
544 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
545 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
546 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
547 /* NameServer Rsp Error */
548 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
549 "%d (%d):0240 NameServer Rsp Error "
550 "Data: x%x x%x x%x x%x\n",
551 phba->brd_no, vport->vpi,
552 CTrsp->CommandResponse.bits.CmdRsp,
553 (uint32_t) CTrsp->ReasonCode,
554 (uint32_t) CTrsp->Explanation,
557 /* NameServer Rsp Error */
558 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
559 "%d (%d):0241 NameServer Rsp Error "
560 "Data: x%x x%x x%x x%x\n",
561 phba->brd_no, vport->vpi,
562 CTrsp->CommandResponse.bits.CmdRsp,
563 (uint32_t) CTrsp->ReasonCode,
564 (uint32_t) CTrsp->Explanation,
568 /* Link up / RSCN discovery */
569 if (vport->num_disc_nodes == 0) {
571 * The driver has cycled through all Nports in the RSCN payload.
572 * Complete the handling by cleaning up and marking the
573 * current driver state.
575 if (vport->port_state >= LPFC_DISC_AUTH) {
576 if (vport->fc_flag & FC_RSCN_MODE) {
577 lpfc_els_flush_rscn(vport);
578 spin_lock_irq(shost->host_lock);
579 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
580 spin_unlock_irq(shost->host_lock);
583 lpfc_els_flush_rscn(vport);
586 lpfc_disc_start(vport);
589 lpfc_free_ct_rsp(phba, outp);
590 lpfc_mbuf_free(phba, inp->virt, inp->phys);
591 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
594 lpfc_sli_release_iocbq(phba, cmdiocb);
599 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
600 struct lpfc_iocbq *rspiocb)
602 struct lpfc_vport *vport = cmdiocb->vport;
603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
604 IOCB_t *irsp = &rspiocb->iocb;
605 struct lpfc_dmabuf *bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
606 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
607 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
608 struct lpfc_sli_ct_request *CTrsp;
611 struct lpfc_nodelist *ndlp;
613 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
614 did = be32_to_cpu(did);
616 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
617 /* Good status, continue checking */
618 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
619 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
621 if (CTrsp->CommandResponse.bits.CmdRsp ==
622 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
623 if ((fbits & FC4_FEATURE_INIT) &&
624 !(fbits & FC4_FEATURE_TARGET)) {
625 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
626 "%d (%d):0245 Skip x%x GFF "
627 "NameServer Rsp Data: (init) "
628 "x%x x%x\n", phba->brd_no,
629 vport->vpi, did, fbits,
630 vport->fc_rscn_id_cnt);
635 /* This is a target port, unregistered port, or the GFF_ID failed */
636 ndlp = lpfc_setup_disc_node(vport, did);
638 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
639 "%d (%d):0242 Process x%x GFF "
640 "NameServer Rsp Data: x%x x%x x%x\n",
641 phba->brd_no, vport->vpi,
642 did, ndlp->nlp_flag, vport->fc_flag,
643 vport->fc_rscn_id_cnt);
645 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
646 "%d (%d):0243 Skip x%x GFF "
647 "NameServer Rsp Data: x%x x%x\n",
648 phba->brd_no, vport->vpi, did,
649 vport->fc_flag, vport->fc_rscn_id_cnt);
652 /* Link up / RSCN discovery */
653 if (vport->num_disc_nodes)
654 vport->num_disc_nodes--;
655 if (vport->num_disc_nodes == 0) {
657 * The driver has cycled through all Nports in the RSCN payload.
658 * Complete the handling by cleaning up and marking the
659 * current driver state.
661 if (vport->port_state >= LPFC_DISC_AUTH) {
662 if (vport->fc_flag & FC_RSCN_MODE) {
663 lpfc_els_flush_rscn(vport);
664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
666 spin_unlock_irq(shost->host_lock);
669 lpfc_els_flush_rscn(vport);
671 lpfc_disc_start(vport);
674 lpfc_free_ct_rsp(phba, outp);
675 lpfc_mbuf_free(phba, inp->virt, inp->phys);
676 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
679 lpfc_sli_release_iocbq(phba, cmdiocb);
685 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
686 struct lpfc_iocbq *rspiocb)
688 struct lpfc_vport *vport = cmdiocb->vport;
689 struct lpfc_dmabuf *bmp;
690 struct lpfc_dmabuf *inp;
691 struct lpfc_dmabuf *outp;
693 struct lpfc_sli_ct_request *CTrsp;
697 /* we pass cmdiocb to state machine which needs rspiocb as well */
698 cmdiocb->context_un.rsp_iocb = rspiocb;
700 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
701 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
702 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
703 irsp = &rspiocb->iocb;
705 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
706 CommandResponse.bits.CmdRsp);
707 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
709 /* NS request completes status <ulpStatus> CmdRsp <CmdRsp> */
710 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
711 "%d (%d):0209 NS request %x completes "
712 "ulpStatus x%x / x%x "
713 "CmdRsp x%x, Context x%x, Tag x%x\n",
714 phba->brd_no, vport->vpi,
715 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4],
716 CTrsp->CommandResponse.bits.CmdRsp,
717 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
719 if (irsp->ulpStatus) {
720 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
721 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
722 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
725 retry = cmdiocb->retry;
726 if (retry >= LPFC_MAX_NS_RETRY)
730 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
731 "%d (%d):0216 Retrying NS cmd %x\n",
732 phba->brd_no, vport->vpi, cmdcode);
733 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
739 lpfc_free_ct_rsp(phba, outp);
740 lpfc_mbuf_free(phba, inp->virt, inp->phys);
741 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
744 lpfc_sli_release_iocbq(phba, cmdiocb);
749 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
750 struct lpfc_iocbq *rspiocb)
752 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
757 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
758 struct lpfc_iocbq *rspiocb)
760 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
765 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
766 struct lpfc_iocbq *rspiocb)
768 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
773 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
774 struct lpfc_iocbq *rspiocb)
776 IOCB_t *irsp = &rspiocb->iocb;
777 struct lpfc_vport *vport = cmdiocb->vport;
779 if (irsp->ulpStatus != IOSTAT_SUCCESS)
780 vport->fc_flag |= FC_RFF_NOT_SUPPORTED;
782 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
787 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
791 uint8_t *wwn = vport->phba->wwpn;
793 n = snprintf(symbol, size,
794 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
795 wwn[0], wwn[1], wwn[2], wwn[3],
796 wwn[4], wwn[5], wwn[6], wwn[7]);
798 if (vport->port_type == LPFC_PHYSICAL_PORT)
802 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
804 if (n < size && vport->vname)
805 n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
810 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
816 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
818 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
819 vport->phba->ModelName, fwrev, lpfc_release_version);
826 * Issue Cmd to NameServer
831 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
832 uint8_t retry, uint32_t context)
834 struct lpfc_nodelist * ndlp;
835 struct lpfc_hba *phba = vport->phba;
836 struct lpfc_dmabuf *mp, *bmp;
837 struct lpfc_sli_ct_request *CtReq;
838 struct ulp_bde64 *bpl;
839 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
840 struct lpfc_iocbq *) = NULL;
841 uint32_t rsp_size = 1024;
844 ndlp = lpfc_findnode_did(vport, NameServer_DID);
845 if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
848 /* fill in BDEs for command */
849 /* Allocate buffer for command payload */
850 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
854 INIT_LIST_HEAD(&mp->list);
855 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
859 /* Allocate buffer for Buffer ptr list */
860 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
862 goto ns_cmd_free_mpvirt;
864 INIT_LIST_HEAD(&bmp->list);
865 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
867 goto ns_cmd_free_bmp;
870 lpfc_printf_log(phba, KERN_INFO ,LOG_DISCOVERY,
871 "%d (%d):0236 NameServer Req Data: x%x x%x x%x\n",
872 phba->brd_no, vport->vpi, cmdcode, vport->fc_flag,
873 vport->fc_rscn_id_cnt);
875 bpl = (struct ulp_bde64 *) bmp->virt;
876 memset(bpl, 0, sizeof(struct ulp_bde64));
877 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
878 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
879 bpl->tus.f.bdeFlags = 0;
880 if (cmdcode == SLI_CTNS_GID_FT)
881 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
882 else if (cmdcode == SLI_CTNS_GFF_ID)
883 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
884 else if (cmdcode == SLI_CTNS_RFT_ID)
885 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
886 else if (cmdcode == SLI_CTNS_RNN_ID)
887 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
888 else if (cmdcode == SLI_CTNS_RSPN_ID)
889 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
890 else if (cmdcode == SLI_CTNS_RSNN_NN)
891 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
892 else if (cmdcode == SLI_CTNS_RFF_ID)
893 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
895 bpl->tus.f.bdeSize = 0;
896 bpl->tus.w = le32_to_cpu(bpl->tus.w);
898 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
899 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
900 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
901 CtReq->RevisionId.bits.InId = 0;
902 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
903 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
904 CtReq->CommandResponse.bits.Size = 0;
906 case SLI_CTNS_GID_FT:
907 CtReq->CommandResponse.bits.CmdRsp =
908 be16_to_cpu(SLI_CTNS_GID_FT);
909 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
910 if (vport->port_state < LPFC_NS_QRY)
911 vport->port_state = LPFC_NS_QRY;
912 lpfc_set_disctmo(vport);
913 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
914 rsp_size = FC_MAX_NS_RSP;
917 case SLI_CTNS_GFF_ID:
918 CtReq->CommandResponse.bits.CmdRsp =
919 be16_to_cpu(SLI_CTNS_GFF_ID);
920 CtReq->un.gff.PortId = be32_to_cpu(context);
921 cmpl = lpfc_cmpl_ct_cmd_gff_id;
924 case SLI_CTNS_RFT_ID:
925 CtReq->CommandResponse.bits.CmdRsp =
926 be16_to_cpu(SLI_CTNS_RFT_ID);
927 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
928 CtReq->un.rft.fcpReg = 1;
929 cmpl = lpfc_cmpl_ct_cmd_rft_id;
932 case SLI_CTNS_RNN_ID:
933 CtReq->CommandResponse.bits.CmdRsp =
934 be16_to_cpu(SLI_CTNS_RNN_ID);
935 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
936 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
937 sizeof (struct lpfc_name));
938 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
941 case SLI_CTNS_RSPN_ID:
942 CtReq->CommandResponse.bits.CmdRsp =
943 be16_to_cpu(SLI_CTNS_RSPN_ID);
944 CtReq->un.rspn.PortId = be32_to_cpu(vport->fc_myDID);
945 size = sizeof(CtReq->un.rspn.symbname);
947 lpfc_vport_symbolic_port_name(vport,
948 CtReq->un.rspn.symbname, size);
949 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
951 case SLI_CTNS_RSNN_NN:
952 CtReq->CommandResponse.bits.CmdRsp =
953 be16_to_cpu(SLI_CTNS_RSNN_NN);
954 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
955 sizeof (struct lpfc_name));
956 size = sizeof(CtReq->un.rsnn.symbname);
958 lpfc_vport_symbolic_node_name(vport,
959 CtReq->un.rsnn.symbname, size);
960 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
962 case SLI_CTNS_RFF_ID:
963 vport->fc_flag &= ~FC_RFF_NOT_SUPPORTED;
964 CtReq->CommandResponse.bits.CmdRsp =
965 be16_to_cpu(SLI_CTNS_RFF_ID);
966 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);;
967 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
968 CtReq->un.rff.type_code = FC_FCP_DATA;
969 cmpl = lpfc_cmpl_ct_cmd_rff_id;
973 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry))
974 /* On success, The cmpl function will free the buffers */
977 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
981 lpfc_mbuf_free(phba, mp->virt, mp->phys);
989 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
990 struct lpfc_iocbq * rspiocb)
992 struct lpfc_dmabuf *bmp = cmdiocb->context3;
993 struct lpfc_dmabuf *inp = cmdiocb->context1;
994 struct lpfc_dmabuf *outp = cmdiocb->context2;
995 struct lpfc_sli_ct_request *CTrsp = outp->virt;
996 struct lpfc_sli_ct_request *CTcmd = inp->virt;
997 struct lpfc_nodelist *ndlp;
998 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
999 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1000 struct lpfc_vport *vport = cmdiocb->vport;
1002 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1003 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1004 /* FDMI rsp failed */
1005 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1006 "%d (%d):0220 FDMI rsp failed Data: x%x\n",
1007 phba->brd_no, vport->vpi,
1008 be16_to_cpu(fdmi_cmd));
1011 switch (be16_to_cpu(fdmi_cmd)) {
1013 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
1020 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
1024 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
1028 lpfc_free_ct_rsp(phba, outp);
1029 lpfc_mbuf_free(phba, inp->virt, inp->phys);
1030 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1033 lpfc_sli_release_iocbq(phba, cmdiocb);
1038 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
1040 struct lpfc_hba *phba = vport->phba;
1041 struct lpfc_dmabuf *mp, *bmp;
1042 struct lpfc_sli_ct_request *CtReq;
1043 struct ulp_bde64 *bpl;
1047 REG_PORT_ATTRIBUTE *pab;
1048 ATTRIBUTE_BLOCK *ab;
1049 ATTRIBUTE_ENTRY *ae;
1050 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1051 struct lpfc_iocbq *);
1054 /* fill in BDEs for command */
1055 /* Allocate buffer for command payload */
1056 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1060 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1062 goto fdmi_cmd_free_mp;
1064 /* Allocate buffer for Buffer ptr list */
1065 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1067 goto fdmi_cmd_free_mpvirt;
1069 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1071 goto fdmi_cmd_free_bmp;
1073 INIT_LIST_HEAD(&mp->list);
1074 INIT_LIST_HEAD(&bmp->list);
1077 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1078 "%d (%d):0218 FDMI Request Data: x%x x%x x%x\n",
1079 phba->brd_no, vport->vpi, vport->fc_flag,
1080 vport->port_state, cmdcode);
1082 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1084 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1085 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1086 CtReq->RevisionId.bits.InId = 0;
1088 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1089 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1095 lpfc_vpd_t *vp = &phba->vpd;
1096 uint32_t i, j, incr;
1099 CtReq->CommandResponse.bits.CmdRsp =
1100 be16_to_cpu(SLI_MGMT_RHBA);
1101 CtReq->CommandResponse.bits.Size = 0;
1102 rh = (REG_HBA *) & CtReq->un.PortID;
1103 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
1104 sizeof (struct lpfc_name));
1105 /* One entry (port) per adapter */
1106 rh->rpl.EntryCnt = be32_to_cpu(1);
1107 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
1108 sizeof (struct lpfc_name));
1110 /* point to the HBA attribute block */
1111 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1112 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1115 /* Point to the beginning of the first HBA attribute
1117 /* #1 HBA attribute entry */
1119 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1120 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1121 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1122 + sizeof (struct lpfc_name));
1123 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
1124 sizeof (struct lpfc_name));
1126 size += FOURBYTES + sizeof (struct lpfc_name);
1128 /* #2 HBA attribute entry */
1129 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1130 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1131 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1132 len = strlen(ae->un.Manufacturer);
1133 len += (len & 3) ? (4 - (len & 3)) : 4;
1134 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1136 size += FOURBYTES + len;
1138 /* #3 HBA attribute entry */
1139 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1140 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1141 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1142 len = strlen(ae->un.SerialNumber);
1143 len += (len & 3) ? (4 - (len & 3)) : 4;
1144 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1146 size += FOURBYTES + len;
1148 /* #4 HBA attribute entry */
1149 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1150 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1151 strcpy(ae->un.Model, phba->ModelName);
1152 len = strlen(ae->un.Model);
1153 len += (len & 3) ? (4 - (len & 3)) : 4;
1154 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1156 size += FOURBYTES + len;
1158 /* #5 HBA attribute entry */
1159 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1160 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1161 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1162 len = strlen(ae->un.ModelDescription);
1163 len += (len & 3) ? (4 - (len & 3)) : 4;
1164 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1166 size += FOURBYTES + len;
1168 /* #6 HBA attribute entry */
1169 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1170 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1171 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1172 /* Convert JEDEC ID to ascii for hardware version */
1173 incr = vp->rev.biuRev;
1174 for (i = 0; i < 8; i++) {
1177 ae->un.HardwareVersion[7 - i] =
1178 (char)((uint8_t) 0x30 +
1181 ae->un.HardwareVersion[7 - i] =
1182 (char)((uint8_t) 0x61 +
1183 (uint8_t) (j - 10));
1187 size += FOURBYTES + 8;
1189 /* #7 HBA attribute entry */
1190 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1191 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1192 strcpy(ae->un.DriverVersion, lpfc_release_version);
1193 len = strlen(ae->un.DriverVersion);
1194 len += (len & 3) ? (4 - (len & 3)) : 4;
1195 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1197 size += FOURBYTES + len;
1199 /* #8 HBA attribute entry */
1200 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1201 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1202 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1203 len = strlen(ae->un.OptionROMVersion);
1204 len += (len & 3) ? (4 - (len & 3)) : 4;
1205 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1207 size += FOURBYTES + len;
1209 /* #9 HBA attribute entry */
1210 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1211 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1212 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1214 len = strlen(ae->un.FirmwareVersion);
1215 len += (len & 3) ? (4 - (len & 3)) : 4;
1216 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1218 size += FOURBYTES + len;
1220 /* #10 HBA attribute entry */
1221 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1222 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1223 sprintf(ae->un.OsNameVersion, "%s %s %s",
1224 init_utsname()->sysname,
1225 init_utsname()->release,
1226 init_utsname()->version);
1227 len = strlen(ae->un.OsNameVersion);
1228 len += (len & 3) ? (4 - (len & 3)) : 4;
1229 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1231 size += FOURBYTES + len;
1233 /* #11 HBA attribute entry */
1234 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1235 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1236 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1237 ae->un.MaxCTPayloadLen = (65 * 4096);
1239 size += FOURBYTES + 4;
1241 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1243 size = GID_REQUEST_SZ - 4 + size;
1250 struct serv_parm *hsp;
1255 CtReq->CommandResponse.bits.CmdRsp =
1256 be16_to_cpu(SLI_MGMT_RPA);
1257 CtReq->CommandResponse.bits.Size = 0;
1258 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1259 size = sizeof (struct lpfc_name) + FOURBYTES;
1260 memcpy((uint8_t *) & pab->PortName,
1261 (uint8_t *) & vport->fc_sparam.portName,
1262 sizeof (struct lpfc_name));
1263 pab->ab.EntryCnt = 0;
1265 /* #1 Port attribute entry */
1266 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1267 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1268 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1269 ae->un.SupportFC4Types[2] = 1;
1270 ae->un.SupportFC4Types[7] = 1;
1272 size += FOURBYTES + 32;
1274 /* #2 Port attribute entry */
1275 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1276 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1277 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1279 ae->un.SupportSpeed = 0;
1280 if (phba->lmt & LMT_10Gb)
1281 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1282 if (phba->lmt & LMT_8Gb)
1283 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1284 if (phba->lmt & LMT_4Gb)
1285 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1286 if (phba->lmt & LMT_2Gb)
1287 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1288 if (phba->lmt & LMT_1Gb)
1289 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1292 size += FOURBYTES + 4;
1294 /* #3 Port attribute entry */
1295 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1296 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1297 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1298 switch(phba->fc_linkspeed) {
1300 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1303 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1306 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1309 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1313 HBA_PORTSPEED_UNKNOWN;
1317 size += FOURBYTES + 4;
1319 /* #4 Port attribute entry */
1320 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1321 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1322 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1323 hsp = (struct serv_parm *) & vport->fc_sparam;
1324 ae->un.MaxFrameSize =
1325 (((uint32_t) hsp->cmn.
1326 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1329 size += FOURBYTES + 4;
1331 /* #5 Port attribute entry */
1332 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1333 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1334 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1335 len = strlen((char *)ae->un.OsDeviceName);
1336 len += (len & 3) ? (4 - (len & 3)) : 4;
1337 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1339 size += FOURBYTES + len;
1341 if (phba->cfg_fdmi_on == 2) {
1342 /* #6 Port attribute entry */
1343 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1345 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1346 sprintf(ae->un.HostName, "%s",
1347 init_utsname()->nodename);
1348 len = strlen(ae->un.HostName);
1349 len += (len & 3) ? (4 - (len & 3)) : 4;
1350 ae->ad.bits.AttrLen =
1351 be16_to_cpu(FOURBYTES + len);
1353 size += FOURBYTES + len;
1356 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1358 size = GID_REQUEST_SZ - 4 + size;
1363 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1364 CtReq->CommandResponse.bits.Size = 0;
1365 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1366 memcpy((uint8_t *) & pe->PortName,
1367 (uint8_t *) & vport->fc_sparam.portName,
1368 sizeof (struct lpfc_name));
1369 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1373 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1374 CtReq->CommandResponse.bits.Size = 0;
1375 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1376 memcpy((uint8_t *) & pe->PortName,
1377 (uint8_t *) & vport->fc_sparam.portName,
1378 sizeof (struct lpfc_name));
1379 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1383 bpl = (struct ulp_bde64 *) bmp->virt;
1384 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1385 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1386 bpl->tus.f.bdeFlags = 0;
1387 bpl->tus.f.bdeSize = size;
1388 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1390 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1392 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
1395 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1398 fdmi_cmd_free_mpvirt:
1399 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1403 /* Issue FDMI request failed */
1404 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1405 "%d (%d):0244 Issue FDMI request failed Data: x%x\n",
1406 phba->brd_no, vport->vpi, cmdcode);
1411 lpfc_fdmi_tmo(unsigned long ptr)
1413 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1414 struct lpfc_hba *phba = vport->phba;
1415 unsigned long iflag;
1417 spin_lock_irqsave(&vport->work_port_lock, iflag);
1418 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1419 vport->work_port_events |= WORKER_FDMI_TMO;
1420 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1422 spin_lock_irqsave(&phba->hbalock, iflag);
1423 if (phba->work_wait)
1424 lpfc_worker_wake_up(phba);
1425 spin_unlock_irqrestore(&phba->hbalock, iflag);
1428 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1432 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1434 struct lpfc_nodelist *ndlp;
1436 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1438 if (init_utsname()->nodename[0] != '\0')
1439 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1441 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1447 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1449 struct lpfc_sli *psli = &phba->sli;
1450 lpfc_vpd_t *vp = &phba->vpd;
1451 uint32_t b1, b2, b3, b4, i, rev;
1453 uint32_t *ptr, str[4];
1457 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1458 rev = vp->rev.sli2FwRev;
1460 rev = vp->rev.sli1FwRev;
1462 b1 = (rev & 0x0000f000) >> 12;
1463 b2 = (rev & 0x00000f00) >> 8;
1464 b3 = (rev & 0x000000c0) >> 6;
1465 b4 = (rev & 0x00000030) >> 4;
1481 b4 = (rev & 0x0000000f);
1483 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1484 fwname = vp->rev.sli2FwName;
1486 fwname = vp->rev.sli1FwName;
1488 for (i = 0; i < 16; i++)
1489 if (fwname[i] == 0x20)
1492 ptr = (uint32_t*)fwname;
1494 for (i = 0; i < 3; i++)
1495 str[i] = be32_to_cpu(*ptr++);
1499 sprintf(fwrevision, "%d.%d%d (%s)",
1500 b1, b2, b3, (char *)str);
1502 sprintf(fwrevision, "%d.%d%d", b1,
1506 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1510 sprintf(fwrevision, "%d.%d%d%c%d",
1514 rev = vp->rev.smFwRev;
1516 b1 = (rev & 0xff000000) >> 24;
1517 b2 = (rev & 0x00f00000) >> 20;
1518 b3 = (rev & 0x000f0000) >> 16;
1519 c = (rev & 0x0000ff00) >> 8;
1520 b4 = (rev & 0x000000ff);
1523 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1526 sprintf(fwrevision, "%d.%d%d%c%d ", b1,