[SCSI] lpfc 8.1.12 : Collapse discovery lists to a single node list
[linux-2.6/verdex.git] / drivers / scsi / lpfc / lpfc_ct.c
blobaf819885213d1286946a327df87babc0cfbe6984
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
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>
35 #include "lpfc_hw.h"
36 #include "lpfc_sli.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
39 #include "lpfc.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 */
53 #define FOURBYTES 4
56 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
59 * lpfc_ct_unsol_event
61 void
62 lpfc_ct_unsol_event(struct lpfc_hba * phba,
63 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
66 struct lpfc_iocbq *next_piocbq;
67 struct lpfc_dmabuf *pmbuf = NULL;
68 struct lpfc_dmabuf *matp, *next_matp;
69 uint32_t ctx = 0, size = 0, cnt = 0;
70 IOCB_t *icmd = &piocbq->iocb;
71 IOCB_t *save_icmd = icmd;
72 int i, go_exit = 0;
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);
80 return;
83 /* If there are no BDEs associated with this IOCB,
84 * there is nothing to do.
86 if (icmd->ulpBdeCount == 0)
87 return;
89 INIT_LIST_HEAD(&head);
90 list_add_tail(&head, &piocbq->list);
92 list_for_each_entry_safe(piocbq, next_piocbq, &head, list) {
93 icmd = &piocbq->iocb;
94 if (ctx == 0)
95 ctx = (uint32_t) (icmd->ulpContext);
96 if (icmd->ulpBdeCount == 0)
97 continue;
99 for (i = 0; i < icmd->ulpBdeCount; i++) {
100 matp = lpfc_sli_ringpostbuf_get(phba, pring,
101 getPaddr(icmd->un.
102 cont64[i].
103 addrHigh,
104 icmd->un.
105 cont64[i].
106 addrLow));
107 if (!matp) {
108 /* Insert lpfc log message here */
109 lpfc_post_buffer(phba, pring, cnt, 1);
110 go_exit = 1;
111 goto ct_unsol_event_exit_piocbq;
114 /* Typically for Unsolicited CT requests */
115 if (!pmbuf) {
116 pmbuf = matp;
117 INIT_LIST_HEAD(&pmbuf->list);
118 } else
119 list_add_tail(&matp->list, &pmbuf->list);
121 size += icmd->un.cont64[i].tus.f.bdeSize;
122 cnt++;
125 icmd->ulpBdeCount = 0;
128 lpfc_post_buffer(phba, pring, cnt, 1);
129 if (save_icmd->ulpStatus) {
130 go_exit = 1;
133 ct_unsol_event_exit_piocbq:
134 list_del(&head);
135 if (pmbuf) {
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);
139 kfree(matp);
141 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
142 kfree(pmbuf);
144 return;
147 static void
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);
155 kfree(mlast);
157 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
158 kfree(mlist);
159 return;
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;
168 int cnt, i = 0;
170 /* We get chucks of FCELSSIZE */
171 cnt = size > FCELSSIZE ? FCELSSIZE: size;
173 while (size) {
174 /* Allocate buffer for rsp payload */
175 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
176 if (!mp) {
177 if (mlist)
178 lpfc_free_ct_rsp(phba, mlist);
179 return NULL;
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));
186 else
187 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
189 if (!mp->virt) {
190 kfree(mp);
191 if (mlist)
192 lpfc_free_ct_rsp(phba, mlist);
193 return NULL;
196 /* Queue it to a linked list */
197 if (!mlist)
198 mlist = mp;
199 else
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);
208 bpl++;
210 i++;
211 size -= cnt;
214 *entries = i;
215 return mlist;
218 static int
219 lpfc_gen_req(struct lpfc_hba *phba, 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,
224 uint32_t tmo)
227 struct lpfc_sli *psli = &phba->sli;
228 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
229 IOCB_t *icmd;
230 struct lpfc_iocbq *geniocb;
232 /* Allocate buffer for command iocb */
233 spin_lock_irq(phba->host->host_lock);
234 geniocb = lpfc_sli_get_iocbq(phba);
235 spin_unlock_irq(phba->host->host_lock);
237 if (geniocb == NULL)
238 return 1;
240 icmd = &geniocb->iocb;
241 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
242 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
243 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
244 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
245 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
247 if (usr_flg)
248 geniocb->context3 = NULL;
249 else
250 geniocb->context3 = (uint8_t *) bmp;
252 /* Save for completion so we can release these resources */
253 geniocb->context1 = (uint8_t *) inp;
254 geniocb->context2 = (uint8_t *) outp;
256 /* Fill in payload, bp points to frame payload */
257 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
259 /* Fill in rest of iocb */
260 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
261 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
262 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
263 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
265 if (!tmo) {
266 /* FC spec states we need 3 * ratov for CT requests */
267 tmo = (3 * phba->fc_ratov);
269 icmd->ulpTimeout = tmo;
270 icmd->ulpBdeCount = 1;
271 icmd->ulpLe = 1;
272 icmd->ulpClass = CLASS3;
273 icmd->ulpContext = ndlp->nlp_rpi;
275 /* Issue GEN REQ IOCB for NPORT <did> */
276 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
277 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
278 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
279 icmd->ulpIoTag, phba->hba_state);
280 geniocb->iocb_cmpl = cmpl;
281 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
282 spin_lock_irq(phba->host->host_lock);
283 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
284 lpfc_sli_release_iocbq(phba, geniocb);
285 spin_unlock_irq(phba->host->host_lock);
286 return 1;
288 spin_unlock_irq(phba->host->host_lock);
290 return 0;
293 static int
294 lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
295 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
296 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
297 struct lpfc_iocbq *),
298 uint32_t rsp_size)
300 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
301 struct lpfc_dmabuf *outmp;
302 int cnt = 0, status;
303 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
304 CommandResponse.bits.CmdRsp;
306 bpl++; /* Skip past ct request */
308 /* Put buffer(s) for ct rsp in bpl */
309 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
310 if (!outmp)
311 return -ENOMEM;
313 status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
314 cnt+1, 0);
315 if (status) {
316 lpfc_free_ct_rsp(phba, outmp);
317 return -ENOMEM;
319 return 0;
322 static int
323 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
325 struct lpfc_sli_ct_request *Response =
326 (struct lpfc_sli_ct_request *) mp->virt;
327 struct lpfc_nodelist *ndlp = NULL;
328 struct lpfc_dmabuf *mlast, *next_mp;
329 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
330 uint32_t Did;
331 uint32_t CTentry;
332 int Cnt;
333 struct list_head head;
335 lpfc_set_disctmo(phba);
338 list_add_tail(&head, &mp->list);
339 list_for_each_entry_safe(mp, next_mp, &head, list) {
340 mlast = mp;
342 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
344 Size -= Cnt;
346 if (!ctptr) {
347 ctptr = (uint32_t *) mlast->virt;
348 } else
349 Cnt -= 16; /* subtract length of CT header */
351 /* Loop through entire NameServer list of DIDs */
352 while (Cnt >= sizeof (uint32_t)) {
354 /* Get next DID from NameServer List */
355 CTentry = *ctptr++;
356 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
358 ndlp = NULL;
359 if (Did != phba->fc_myDID) {
360 /* Check for rscn processing or not */
361 ndlp = lpfc_setup_disc_node(phba, Did);
363 /* Mark all node table entries that are in the
364 Nameserver */
365 if (ndlp) {
366 /* NameServer Rsp */
367 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
368 "%d:0238 Process x%x NameServer"
369 " Rsp Data: x%x x%x x%x\n",
370 phba->brd_no,
371 Did, ndlp->nlp_flag,
372 phba->fc_flag,
373 phba->fc_rscn_id_cnt);
374 } else {
375 /* NameServer Rsp */
376 lpfc_printf_log(phba,
377 KERN_INFO,
378 LOG_DISCOVERY,
379 "%d:0239 Skip x%x NameServer "
380 "Rsp Data: x%x x%x x%x\n",
381 phba->brd_no,
382 Did, Size, phba->fc_flag,
383 phba->fc_rscn_id_cnt);
386 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
387 goto nsout1;
388 Cnt -= sizeof (uint32_t);
390 ctptr = NULL;
394 nsout1:
395 list_del(&head);
398 * The driver has cycled through all Nports in the RSCN payload.
399 * Complete the handling by cleaning up and marking the
400 * current driver state.
402 if (phba->hba_state == LPFC_HBA_READY) {
403 lpfc_els_flush_rscn(phba);
404 spin_lock_irq(phba->host->host_lock);
405 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
406 spin_unlock_irq(phba->host->host_lock);
408 return 0;
414 static void
415 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
416 struct lpfc_iocbq * rspiocb)
418 IOCB_t *irsp;
419 struct lpfc_sli *psli;
420 struct lpfc_dmabuf *bmp;
421 struct lpfc_dmabuf *inp;
422 struct lpfc_dmabuf *outp;
423 struct lpfc_nodelist *ndlp;
424 struct lpfc_sli_ct_request *CTrsp;
426 psli = &phba->sli;
427 /* we pass cmdiocb to state machine which needs rspiocb as well */
428 cmdiocb->context_un.rsp_iocb = rspiocb;
430 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
431 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
432 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
434 irsp = &rspiocb->iocb;
435 if (irsp->ulpStatus) {
436 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
437 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
438 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
439 goto out;
442 /* Check for retry */
443 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
444 phba->fc_ns_retry++;
445 /* CT command is being retried */
446 ndlp = lpfc_findnode_did(phba, NameServer_DID);
447 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
448 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
449 0) {
450 goto out;
454 } else {
455 /* Good status, continue checking */
456 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
457 if (CTrsp->CommandResponse.bits.CmdRsp ==
458 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
459 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
460 "%d:0208 NameServer Rsp "
461 "Data: x%x\n",
462 phba->brd_no,
463 phba->fc_flag);
464 lpfc_ns_rsp(phba, outp,
465 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
466 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
467 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
468 /* NameServer Rsp Error */
469 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
470 "%d:0240 NameServer Rsp Error "
471 "Data: x%x x%x x%x x%x\n",
472 phba->brd_no,
473 CTrsp->CommandResponse.bits.CmdRsp,
474 (uint32_t) CTrsp->ReasonCode,
475 (uint32_t) CTrsp->Explanation,
476 phba->fc_flag);
477 } else {
478 /* NameServer Rsp Error */
479 lpfc_printf_log(phba,
480 KERN_INFO,
481 LOG_DISCOVERY,
482 "%d:0241 NameServer Rsp Error "
483 "Data: x%x x%x x%x x%x\n",
484 phba->brd_no,
485 CTrsp->CommandResponse.bits.CmdRsp,
486 (uint32_t) CTrsp->ReasonCode,
487 (uint32_t) CTrsp->Explanation,
488 phba->fc_flag);
491 /* Link up / RSCN discovery */
492 lpfc_disc_start(phba);
493 out:
494 lpfc_free_ct_rsp(phba, outp);
495 lpfc_mbuf_free(phba, inp->virt, inp->phys);
496 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
497 kfree(inp);
498 kfree(bmp);
499 spin_lock_irq(phba->host->host_lock);
500 lpfc_sli_release_iocbq(phba, cmdiocb);
501 spin_unlock_irq(phba->host->host_lock);
502 return;
505 static void
506 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
507 struct lpfc_iocbq * rspiocb)
509 struct lpfc_sli *psli;
510 struct lpfc_dmabuf *bmp;
511 struct lpfc_dmabuf *inp;
512 struct lpfc_dmabuf *outp;
513 IOCB_t *irsp;
514 struct lpfc_sli_ct_request *CTrsp;
516 psli = &phba->sli;
517 /* we pass cmdiocb to state machine which needs rspiocb as well */
518 cmdiocb->context_un.rsp_iocb = rspiocb;
520 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
521 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
522 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
523 irsp = &rspiocb->iocb;
525 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
527 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
528 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
529 "%d:0209 RFT request completes ulpStatus x%x "
530 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
531 CTrsp->CommandResponse.bits.CmdRsp);
533 lpfc_free_ct_rsp(phba, outp);
534 lpfc_mbuf_free(phba, inp->virt, inp->phys);
535 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
536 kfree(inp);
537 kfree(bmp);
538 spin_lock_irq(phba->host->host_lock);
539 lpfc_sli_release_iocbq(phba, cmdiocb);
540 spin_unlock_irq(phba->host->host_lock);
541 return;
544 static void
545 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
546 struct lpfc_iocbq * rspiocb)
548 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
549 return;
552 static void
553 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
554 struct lpfc_iocbq * rspiocb)
556 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
557 return;
560 static void
561 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
562 struct lpfc_iocbq * rspiocb)
564 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
565 return;
568 void
569 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
571 char fwrev[16];
573 lpfc_decode_firmware_rev(phba, fwrev, 0);
575 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
576 fwrev, lpfc_release_version);
577 return;
581 * lpfc_ns_cmd
582 * Description:
583 * Issue Cmd to NameServer
584 * SLI_CTNS_GID_FT
585 * LI_CTNS_RFT_ID
588 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
590 struct lpfc_dmabuf *mp, *bmp;
591 struct lpfc_sli_ct_request *CtReq;
592 struct ulp_bde64 *bpl;
593 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
594 struct lpfc_iocbq *) = NULL;
595 uint32_t rsp_size = 1024;
597 /* fill in BDEs for command */
598 /* Allocate buffer for command payload */
599 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
600 if (!mp)
601 goto ns_cmd_exit;
603 INIT_LIST_HEAD(&mp->list);
604 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
605 if (!mp->virt)
606 goto ns_cmd_free_mp;
608 /* Allocate buffer for Buffer ptr list */
609 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
610 if (!bmp)
611 goto ns_cmd_free_mpvirt;
613 INIT_LIST_HEAD(&bmp->list);
614 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
615 if (!bmp->virt)
616 goto ns_cmd_free_bmp;
618 /* NameServer Req */
619 lpfc_printf_log(phba,
620 KERN_INFO,
621 LOG_DISCOVERY,
622 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
623 phba->brd_no, cmdcode, phba->fc_flag,
624 phba->fc_rscn_id_cnt);
626 bpl = (struct ulp_bde64 *) bmp->virt;
627 memset(bpl, 0, sizeof(struct ulp_bde64));
628 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
629 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
630 bpl->tus.f.bdeFlags = 0;
631 if (cmdcode == SLI_CTNS_GID_FT)
632 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
633 else if (cmdcode == SLI_CTNS_RFT_ID)
634 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
635 else if (cmdcode == SLI_CTNS_RNN_ID)
636 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
637 else if (cmdcode == SLI_CTNS_RSNN_NN)
638 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
639 else if (cmdcode == SLI_CTNS_RFF_ID)
640 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
641 else
642 bpl->tus.f.bdeSize = 0;
643 bpl->tus.w = le32_to_cpu(bpl->tus.w);
645 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
646 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
647 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
648 CtReq->RevisionId.bits.InId = 0;
649 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
650 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
651 CtReq->CommandResponse.bits.Size = 0;
652 switch (cmdcode) {
653 case SLI_CTNS_GID_FT:
654 CtReq->CommandResponse.bits.CmdRsp =
655 be16_to_cpu(SLI_CTNS_GID_FT);
656 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
657 if (phba->hba_state < LPFC_HBA_READY)
658 phba->hba_state = LPFC_NS_QRY;
659 lpfc_set_disctmo(phba);
660 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
661 rsp_size = FC_MAX_NS_RSP;
662 break;
664 case SLI_CTNS_RFT_ID:
665 CtReq->CommandResponse.bits.CmdRsp =
666 be16_to_cpu(SLI_CTNS_RFT_ID);
667 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
668 CtReq->un.rft.fcpReg = 1;
669 cmpl = lpfc_cmpl_ct_cmd_rft_id;
670 break;
672 case SLI_CTNS_RFF_ID:
673 CtReq->CommandResponse.bits.CmdRsp =
674 be16_to_cpu(SLI_CTNS_RFF_ID);
675 CtReq->un.rff.PortId = be32_to_cpu(phba->fc_myDID);
676 CtReq->un.rff.feature_res = 0;
677 CtReq->un.rff.feature_tgt = 0;
678 CtReq->un.rff.type_code = FC_FCP_DATA;
679 CtReq->un.rff.feature_init = 1;
680 cmpl = lpfc_cmpl_ct_cmd_rff_id;
681 break;
683 case SLI_CTNS_RNN_ID:
684 CtReq->CommandResponse.bits.CmdRsp =
685 be16_to_cpu(SLI_CTNS_RNN_ID);
686 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
687 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
688 sizeof (struct lpfc_name));
689 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
690 break;
692 case SLI_CTNS_RSNN_NN:
693 CtReq->CommandResponse.bits.CmdRsp =
694 be16_to_cpu(SLI_CTNS_RSNN_NN);
695 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
696 sizeof (struct lpfc_name));
697 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
698 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
699 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
700 break;
703 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
704 /* On success, The cmpl function will free the buffers */
705 return 0;
707 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
708 ns_cmd_free_bmp:
709 kfree(bmp);
710 ns_cmd_free_mpvirt:
711 lpfc_mbuf_free(phba, mp->virt, mp->phys);
712 ns_cmd_free_mp:
713 kfree(mp);
714 ns_cmd_exit:
715 return 1;
718 static void
719 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
720 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
722 struct lpfc_dmabuf *bmp = cmdiocb->context3;
723 struct lpfc_dmabuf *inp = cmdiocb->context1;
724 struct lpfc_dmabuf *outp = cmdiocb->context2;
725 struct lpfc_sli_ct_request *CTrsp = outp->virt;
726 struct lpfc_sli_ct_request *CTcmd = inp->virt;
727 struct lpfc_nodelist *ndlp;
728 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
729 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
731 ndlp = lpfc_findnode_did(phba, FDMI_DID);
732 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
733 /* FDMI rsp failed */
734 lpfc_printf_log(phba,
735 KERN_INFO,
736 LOG_DISCOVERY,
737 "%d:0220 FDMI rsp failed Data: x%x\n",
738 phba->brd_no,
739 be16_to_cpu(fdmi_cmd));
742 switch (be16_to_cpu(fdmi_cmd)) {
743 case SLI_MGMT_RHBA:
744 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
745 break;
747 case SLI_MGMT_RPA:
748 break;
750 case SLI_MGMT_DHBA:
751 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
752 break;
754 case SLI_MGMT_DPRT:
755 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
756 break;
759 lpfc_free_ct_rsp(phba, outp);
760 lpfc_mbuf_free(phba, inp->virt, inp->phys);
761 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
762 kfree(inp);
763 kfree(bmp);
764 spin_lock_irq(phba->host->host_lock);
765 lpfc_sli_release_iocbq(phba, cmdiocb);
766 spin_unlock_irq(phba->host->host_lock);
767 return;
770 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
772 struct lpfc_dmabuf *mp, *bmp;
773 struct lpfc_sli_ct_request *CtReq;
774 struct ulp_bde64 *bpl;
775 uint32_t size;
776 REG_HBA *rh;
777 PORT_ENTRY *pe;
778 REG_PORT_ATTRIBUTE *pab;
779 ATTRIBUTE_BLOCK *ab;
780 ATTRIBUTE_ENTRY *ae;
781 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
782 struct lpfc_iocbq *);
785 /* fill in BDEs for command */
786 /* Allocate buffer for command payload */
787 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
788 if (!mp)
789 goto fdmi_cmd_exit;
791 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
792 if (!mp->virt)
793 goto fdmi_cmd_free_mp;
795 /* Allocate buffer for Buffer ptr list */
796 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
797 if (!bmp)
798 goto fdmi_cmd_free_mpvirt;
800 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
801 if (!bmp->virt)
802 goto fdmi_cmd_free_bmp;
804 INIT_LIST_HEAD(&mp->list);
805 INIT_LIST_HEAD(&bmp->list);
807 /* FDMI request */
808 lpfc_printf_log(phba,
809 KERN_INFO,
810 LOG_DISCOVERY,
811 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
812 phba->brd_no,
813 phba->fc_flag, phba->hba_state, cmdcode);
815 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
817 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
818 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
819 CtReq->RevisionId.bits.InId = 0;
821 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
822 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
823 size = 0;
825 switch (cmdcode) {
826 case SLI_MGMT_RHBA:
828 lpfc_vpd_t *vp = &phba->vpd;
829 uint32_t i, j, incr;
830 int len;
832 CtReq->CommandResponse.bits.CmdRsp =
833 be16_to_cpu(SLI_MGMT_RHBA);
834 CtReq->CommandResponse.bits.Size = 0;
835 rh = (REG_HBA *) & CtReq->un.PortID;
836 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
837 sizeof (struct lpfc_name));
838 /* One entry (port) per adapter */
839 rh->rpl.EntryCnt = be32_to_cpu(1);
840 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
841 sizeof (struct lpfc_name));
843 /* point to the HBA attribute block */
844 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
845 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
846 ab->EntryCnt = 0;
848 /* Point to the beginning of the first HBA attribute
849 entry */
850 /* #1 HBA attribute entry */
851 size += FOURBYTES;
852 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
853 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
854 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
855 + sizeof (struct lpfc_name));
856 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
857 sizeof (struct lpfc_name));
858 ab->EntryCnt++;
859 size += FOURBYTES + sizeof (struct lpfc_name);
861 /* #2 HBA attribute entry */
862 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
863 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
864 strcpy(ae->un.Manufacturer, "Emulex Corporation");
865 len = strlen(ae->un.Manufacturer);
866 len += (len & 3) ? (4 - (len & 3)) : 4;
867 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
868 ab->EntryCnt++;
869 size += FOURBYTES + len;
871 /* #3 HBA attribute entry */
872 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
873 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
874 strcpy(ae->un.SerialNumber, phba->SerialNumber);
875 len = strlen(ae->un.SerialNumber);
876 len += (len & 3) ? (4 - (len & 3)) : 4;
877 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
878 ab->EntryCnt++;
879 size += FOURBYTES + len;
881 /* #4 HBA attribute entry */
882 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
883 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
884 strcpy(ae->un.Model, phba->ModelName);
885 len = strlen(ae->un.Model);
886 len += (len & 3) ? (4 - (len & 3)) : 4;
887 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
888 ab->EntryCnt++;
889 size += FOURBYTES + len;
891 /* #5 HBA attribute entry */
892 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
893 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
894 strcpy(ae->un.ModelDescription, phba->ModelDesc);
895 len = strlen(ae->un.ModelDescription);
896 len += (len & 3) ? (4 - (len & 3)) : 4;
897 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
898 ab->EntryCnt++;
899 size += FOURBYTES + len;
901 /* #6 HBA attribute entry */
902 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
903 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
904 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
905 /* Convert JEDEC ID to ascii for hardware version */
906 incr = vp->rev.biuRev;
907 for (i = 0; i < 8; i++) {
908 j = (incr & 0xf);
909 if (j <= 9)
910 ae->un.HardwareVersion[7 - i] =
911 (char)((uint8_t) 0x30 +
912 (uint8_t) j);
913 else
914 ae->un.HardwareVersion[7 - i] =
915 (char)((uint8_t) 0x61 +
916 (uint8_t) (j - 10));
917 incr = (incr >> 4);
919 ab->EntryCnt++;
920 size += FOURBYTES + 8;
922 /* #7 HBA attribute entry */
923 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
924 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
925 strcpy(ae->un.DriverVersion, lpfc_release_version);
926 len = strlen(ae->un.DriverVersion);
927 len += (len & 3) ? (4 - (len & 3)) : 4;
928 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
929 ab->EntryCnt++;
930 size += FOURBYTES + len;
932 /* #8 HBA attribute entry */
933 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
934 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
935 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
936 len = strlen(ae->un.OptionROMVersion);
937 len += (len & 3) ? (4 - (len & 3)) : 4;
938 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
939 ab->EntryCnt++;
940 size += FOURBYTES + len;
942 /* #9 HBA attribute entry */
943 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
944 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
945 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
947 len = strlen(ae->un.FirmwareVersion);
948 len += (len & 3) ? (4 - (len & 3)) : 4;
949 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
950 ab->EntryCnt++;
951 size += FOURBYTES + len;
953 /* #10 HBA attribute entry */
954 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
955 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
956 sprintf(ae->un.OsNameVersion, "%s %s %s",
957 init_utsname()->sysname,
958 init_utsname()->release,
959 init_utsname()->version);
960 len = strlen(ae->un.OsNameVersion);
961 len += (len & 3) ? (4 - (len & 3)) : 4;
962 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
963 ab->EntryCnt++;
964 size += FOURBYTES + len;
966 /* #11 HBA attribute entry */
967 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
968 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
969 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
970 ae->un.MaxCTPayloadLen = (65 * 4096);
971 ab->EntryCnt++;
972 size += FOURBYTES + 4;
974 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
975 /* Total size */
976 size = GID_REQUEST_SZ - 4 + size;
978 break;
980 case SLI_MGMT_RPA:
982 lpfc_vpd_t *vp;
983 struct serv_parm *hsp;
984 int len;
986 vp = &phba->vpd;
988 CtReq->CommandResponse.bits.CmdRsp =
989 be16_to_cpu(SLI_MGMT_RPA);
990 CtReq->CommandResponse.bits.Size = 0;
991 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
992 size = sizeof (struct lpfc_name) + FOURBYTES;
993 memcpy((uint8_t *) & pab->PortName,
994 (uint8_t *) & phba->fc_sparam.portName,
995 sizeof (struct lpfc_name));
996 pab->ab.EntryCnt = 0;
998 /* #1 Port attribute entry */
999 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1000 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1001 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1002 ae->un.SupportFC4Types[2] = 1;
1003 ae->un.SupportFC4Types[7] = 1;
1004 pab->ab.EntryCnt++;
1005 size += FOURBYTES + 32;
1007 /* #2 Port attribute entry */
1008 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1009 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1010 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1012 ae->un.SupportSpeed = 0;
1013 if (phba->lmt & LMT_10Gb)
1014 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1015 if (phba->lmt & LMT_8Gb)
1016 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1017 if (phba->lmt & LMT_4Gb)
1018 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1019 if (phba->lmt & LMT_2Gb)
1020 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1021 if (phba->lmt & LMT_1Gb)
1022 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1024 pab->ab.EntryCnt++;
1025 size += FOURBYTES + 4;
1027 /* #3 Port attribute entry */
1028 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1029 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1030 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1031 switch(phba->fc_linkspeed) {
1032 case LA_1GHZ_LINK:
1033 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1034 break;
1035 case LA_2GHZ_LINK:
1036 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1037 break;
1038 case LA_4GHZ_LINK:
1039 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1040 break;
1041 default:
1042 ae->un.PortSpeed =
1043 HBA_PORTSPEED_UNKNOWN;
1044 break;
1046 pab->ab.EntryCnt++;
1047 size += FOURBYTES + 4;
1049 /* #4 Port attribute entry */
1050 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1051 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1052 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1053 hsp = (struct serv_parm *) & phba->fc_sparam;
1054 ae->un.MaxFrameSize =
1055 (((uint32_t) hsp->cmn.
1056 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1057 bbRcvSizeLsb;
1058 pab->ab.EntryCnt++;
1059 size += FOURBYTES + 4;
1061 /* #5 Port attribute entry */
1062 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1063 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1064 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1065 len = strlen((char *)ae->un.OsDeviceName);
1066 len += (len & 3) ? (4 - (len & 3)) : 4;
1067 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1068 pab->ab.EntryCnt++;
1069 size += FOURBYTES + len;
1071 if (phba->cfg_fdmi_on == 2) {
1072 /* #6 Port attribute entry */
1073 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1074 size);
1075 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1076 sprintf(ae->un.HostName, "%s",
1077 init_utsname()->nodename);
1078 len = strlen(ae->un.HostName);
1079 len += (len & 3) ? (4 - (len & 3)) : 4;
1080 ae->ad.bits.AttrLen =
1081 be16_to_cpu(FOURBYTES + len);
1082 pab->ab.EntryCnt++;
1083 size += FOURBYTES + len;
1086 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1087 /* Total size */
1088 size = GID_REQUEST_SZ - 4 + size;
1090 break;
1092 case SLI_MGMT_DHBA:
1093 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1094 CtReq->CommandResponse.bits.Size = 0;
1095 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1096 memcpy((uint8_t *) & pe->PortName,
1097 (uint8_t *) & phba->fc_sparam.portName,
1098 sizeof (struct lpfc_name));
1099 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1100 break;
1102 case SLI_MGMT_DPRT:
1103 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1104 CtReq->CommandResponse.bits.Size = 0;
1105 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1106 memcpy((uint8_t *) & pe->PortName,
1107 (uint8_t *) & phba->fc_sparam.portName,
1108 sizeof (struct lpfc_name));
1109 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1110 break;
1113 bpl = (struct ulp_bde64 *) bmp->virt;
1114 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1115 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1116 bpl->tus.f.bdeFlags = 0;
1117 bpl->tus.f.bdeSize = size;
1118 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1120 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1122 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1123 return 0;
1125 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1126 fdmi_cmd_free_bmp:
1127 kfree(bmp);
1128 fdmi_cmd_free_mpvirt:
1129 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1130 fdmi_cmd_free_mp:
1131 kfree(mp);
1132 fdmi_cmd_exit:
1133 /* Issue FDMI request failed */
1134 lpfc_printf_log(phba,
1135 KERN_INFO,
1136 LOG_DISCOVERY,
1137 "%d:0244 Issue FDMI request failed Data: x%x\n",
1138 phba->brd_no,
1139 cmdcode);
1140 return 1;
1143 void
1144 lpfc_fdmi_tmo(unsigned long ptr)
1146 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1147 unsigned long iflag;
1149 spin_lock_irqsave(phba->host->host_lock, iflag);
1150 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1151 phba->work_hba_events |= WORKER_FDMI_TMO;
1152 if (phba->work_wait)
1153 wake_up(phba->work_wait);
1155 spin_unlock_irqrestore(phba->host->host_lock,iflag);
1158 void
1159 lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1161 struct lpfc_nodelist *ndlp;
1163 ndlp = lpfc_findnode_did(phba, FDMI_DID);
1164 if (ndlp) {
1165 if (init_utsname()->nodename[0] != '\0') {
1166 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1167 } else {
1168 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1171 return;
1175 void
1176 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1178 struct lpfc_sli *psli = &phba->sli;
1179 lpfc_vpd_t *vp = &phba->vpd;
1180 uint32_t b1, b2, b3, b4, i, rev;
1181 char c;
1182 uint32_t *ptr, str[4];
1183 uint8_t *fwname;
1185 if (vp->rev.rBit) {
1186 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1187 rev = vp->rev.sli2FwRev;
1188 else
1189 rev = vp->rev.sli1FwRev;
1191 b1 = (rev & 0x0000f000) >> 12;
1192 b2 = (rev & 0x00000f00) >> 8;
1193 b3 = (rev & 0x000000c0) >> 6;
1194 b4 = (rev & 0x00000030) >> 4;
1196 switch (b4) {
1197 case 0:
1198 c = 'N';
1199 break;
1200 case 1:
1201 c = 'A';
1202 break;
1203 case 2:
1204 c = 'B';
1205 break;
1206 default:
1207 c = 0;
1208 break;
1210 b4 = (rev & 0x0000000f);
1212 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1213 fwname = vp->rev.sli2FwName;
1214 else
1215 fwname = vp->rev.sli1FwName;
1217 for (i = 0; i < 16; i++)
1218 if (fwname[i] == 0x20)
1219 fwname[i] = 0;
1221 ptr = (uint32_t*)fwname;
1223 for (i = 0; i < 3; i++)
1224 str[i] = be32_to_cpu(*ptr++);
1226 if (c == 0) {
1227 if (flag)
1228 sprintf(fwrevision, "%d.%d%d (%s)",
1229 b1, b2, b3, (char *)str);
1230 else
1231 sprintf(fwrevision, "%d.%d%d", b1,
1232 b2, b3);
1233 } else {
1234 if (flag)
1235 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1236 b1, b2, b3, c,
1237 b4, (char *)str);
1238 else
1239 sprintf(fwrevision, "%d.%d%d%c%d",
1240 b1, b2, b3, c, b4);
1242 } else {
1243 rev = vp->rev.smFwRev;
1245 b1 = (rev & 0xff000000) >> 24;
1246 b2 = (rev & 0x00f00000) >> 20;
1247 b3 = (rev & 0x000f0000) >> 16;
1248 c = (rev & 0x0000ff00) >> 8;
1249 b4 = (rev & 0x000000ff);
1251 if (flag)
1252 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1253 b2, b3, c, b4);
1254 else
1255 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1256 b2, b3, c, b4);
1258 return;