[PATCH] percpu counter data type changes to suppport more than 2**31 ext3 free blocks...
[linux-2.6/openmoko-kernel/knife-kernel.git] / drivers / scsi / lpfc / lpfc_ct.c
blobb65ee57af53ec82378254b665cf0e0316df599d3
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 if (pmbuf) {
135 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
136 lpfc_mbuf_free(phba, matp->virt, matp->phys);
137 list_del(&matp->list);
138 kfree(matp);
140 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
141 kfree(pmbuf);
143 return;
146 static void
147 lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
149 struct lpfc_dmabuf *mlast, *next_mlast;
151 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
152 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
153 list_del(&mlast->list);
154 kfree(mlast);
156 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
157 kfree(mlist);
158 return;
161 static struct lpfc_dmabuf *
162 lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
163 uint32_t size, int *entries)
165 struct lpfc_dmabuf *mlist = NULL;
166 struct lpfc_dmabuf *mp;
167 int cnt, i = 0;
169 /* We get chucks of FCELSSIZE */
170 cnt = size > FCELSSIZE ? FCELSSIZE: size;
172 while (size) {
173 /* Allocate buffer for rsp payload */
174 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
175 if (!mp) {
176 if (mlist)
177 lpfc_free_ct_rsp(phba, mlist);
178 return NULL;
181 INIT_LIST_HEAD(&mp->list);
183 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
184 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
185 else
186 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
188 if (!mp->virt) {
189 kfree(mp);
190 lpfc_free_ct_rsp(phba, mlist);
191 return NULL;
194 /* Queue it to a linked list */
195 if (!mlist)
196 mlist = mp;
197 else
198 list_add_tail(&mp->list, &mlist->list);
200 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
201 /* build buffer ptr list for IOCB */
202 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
203 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
204 bpl->tus.f.bdeSize = (uint16_t) cnt;
205 bpl->tus.w = le32_to_cpu(bpl->tus.w);
206 bpl++;
208 i++;
209 size -= cnt;
212 *entries = i;
213 return mlist;
216 static int
217 lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
218 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
219 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
220 struct lpfc_iocbq *),
221 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
222 uint32_t tmo)
225 struct lpfc_sli *psli = &phba->sli;
226 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
227 IOCB_t *icmd;
228 struct lpfc_iocbq *geniocb;
230 /* Allocate buffer for command iocb */
231 spin_lock_irq(phba->host->host_lock);
232 geniocb = lpfc_sli_get_iocbq(phba);
233 spin_unlock_irq(phba->host->host_lock);
235 if (geniocb == NULL)
236 return 1;
238 icmd = &geniocb->iocb;
239 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
240 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
241 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
242 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
243 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
245 if (usr_flg)
246 geniocb->context3 = NULL;
247 else
248 geniocb->context3 = (uint8_t *) bmp;
250 /* Save for completion so we can release these resources */
251 geniocb->context1 = (uint8_t *) inp;
252 geniocb->context2 = (uint8_t *) outp;
254 /* Fill in payload, bp points to frame payload */
255 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
257 /* Fill in rest of iocb */
258 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
259 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
260 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
261 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
263 if (!tmo) {
264 /* FC spec states we need 3 * ratov for CT requests */
265 tmo = (3 * phba->fc_ratov);
267 icmd->ulpTimeout = tmo;
268 icmd->ulpBdeCount = 1;
269 icmd->ulpLe = 1;
270 icmd->ulpClass = CLASS3;
271 icmd->ulpContext = ndlp->nlp_rpi;
273 /* Issue GEN REQ IOCB for NPORT <did> */
274 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
275 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
276 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
277 icmd->ulpIoTag, phba->hba_state);
278 geniocb->iocb_cmpl = cmpl;
279 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
280 spin_lock_irq(phba->host->host_lock);
281 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
282 lpfc_sli_release_iocbq(phba, geniocb);
283 spin_unlock_irq(phba->host->host_lock);
284 return 1;
286 spin_unlock_irq(phba->host->host_lock);
288 return 0;
291 static int
292 lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
293 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
294 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
295 struct lpfc_iocbq *),
296 uint32_t rsp_size)
298 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
299 struct lpfc_dmabuf *outmp;
300 int cnt = 0, status;
301 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
302 CommandResponse.bits.CmdRsp;
304 bpl++; /* Skip past ct request */
306 /* Put buffer(s) for ct rsp in bpl */
307 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
308 if (!outmp)
309 return -ENOMEM;
311 status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
312 cnt+1, 0);
313 if (status) {
314 lpfc_free_ct_rsp(phba, outmp);
315 return -ENOMEM;
317 return 0;
320 static int
321 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
323 struct lpfc_sli_ct_request *Response =
324 (struct lpfc_sli_ct_request *) mp->virt;
325 struct lpfc_nodelist *ndlp = NULL;
326 struct lpfc_nodelist *next_ndlp;
327 struct lpfc_dmabuf *mlast, *next_mp;
328 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
329 uint32_t Did;
330 uint32_t CTentry;
331 int Cnt;
332 struct list_head head;
334 lpfc_set_disctmo(phba);
336 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
338 list_add_tail(&head, &mp->list);
339 list_for_each_entry_safe(mp, next_mp, &head, list) {
340 mlast = mp;
342 Size -= Cnt;
344 if (!ctptr)
345 ctptr = (uint32_t *) mlast->virt;
346 else
347 Cnt -= 16; /* subtract length of CT header */
349 /* Loop through entire NameServer list of DIDs */
350 while (Cnt) {
352 /* Get next DID from NameServer List */
353 CTentry = *ctptr++;
354 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
356 ndlp = NULL;
357 if (Did != phba->fc_myDID) {
358 /* Check for rscn processing or not */
359 ndlp = lpfc_setup_disc_node(phba, Did);
361 /* Mark all node table entries that are in the
362 Nameserver */
363 if (ndlp) {
364 /* NameServer Rsp */
365 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
366 "%d:0238 Process x%x NameServer"
367 " Rsp Data: x%x x%x x%x\n",
368 phba->brd_no,
369 Did, ndlp->nlp_flag,
370 phba->fc_flag,
371 phba->fc_rscn_id_cnt);
372 } else {
373 /* NameServer Rsp */
374 lpfc_printf_log(phba,
375 KERN_INFO,
376 LOG_DISCOVERY,
377 "%d:0239 Skip x%x NameServer "
378 "Rsp Data: x%x x%x x%x\n",
379 phba->brd_no,
380 Did, Size, phba->fc_flag,
381 phba->fc_rscn_id_cnt);
384 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
385 goto nsout1;
386 Cnt -= sizeof (uint32_t);
388 ctptr = NULL;
392 nsout1:
393 list_del(&head);
396 * The driver has cycled through all Nports in the RSCN payload.
397 * Complete the handling by cleaning up and marking the
398 * current driver state.
400 if (phba->hba_state == LPFC_HBA_READY) {
403 * Switch ports that connect a loop of multiple targets need
404 * special consideration. The driver wants to unregister the
405 * rpi only on the target that was pulled from the loop. On
406 * RSCN, the driver wants to rediscover an NPort only if the
407 * driver flagged it as NLP_NPR_2B_DISC. Provided adisc is
408 * not enabled and the NPort is not capable of retransmissions
409 * (FC Tape) prevent timing races with the scsi error handler by
410 * unregistering the Nport's RPI. This action causes all
411 * outstanding IO to flush back to the midlayer.
413 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
414 nlp_listp) {
415 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
416 (lpfc_rscn_payload_check(phba, ndlp->nlp_DID))) {
417 if ((phba->cfg_use_adisc == 0) &&
418 !(ndlp->nlp_fcp_info &
419 NLP_FCP_2_DEVICE)) {
420 lpfc_unreg_rpi(phba, ndlp);
421 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
425 lpfc_els_flush_rscn(phba);
426 spin_lock_irq(phba->host->host_lock);
427 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
428 spin_unlock_irq(phba->host->host_lock);
430 return 0;
436 static void
437 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
438 struct lpfc_iocbq * rspiocb)
440 IOCB_t *irsp;
441 struct lpfc_sli *psli;
442 struct lpfc_dmabuf *bmp;
443 struct lpfc_dmabuf *inp;
444 struct lpfc_dmabuf *outp;
445 struct lpfc_nodelist *ndlp;
446 struct lpfc_sli_ct_request *CTrsp;
448 psli = &phba->sli;
449 /* we pass cmdiocb to state machine which needs rspiocb as well */
450 cmdiocb->context_un.rsp_iocb = rspiocb;
452 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
453 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
454 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
456 irsp = &rspiocb->iocb;
457 if (irsp->ulpStatus) {
458 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
459 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
460 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
461 goto out;
464 /* Check for retry */
465 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
466 phba->fc_ns_retry++;
467 /* CT command is being retried */
468 ndlp =
469 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
470 NameServer_DID);
471 if (ndlp) {
472 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
473 0) {
474 goto out;
478 } else {
479 /* Good status, continue checking */
480 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
481 if (CTrsp->CommandResponse.bits.CmdRsp ==
482 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
483 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
484 "%d:0239 NameServer Rsp "
485 "Data: x%x\n",
486 phba->brd_no,
487 phba->fc_flag);
488 lpfc_ns_rsp(phba, outp,
489 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
490 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
491 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
492 /* NameServer Rsp Error */
493 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
494 "%d:0240 NameServer Rsp Error "
495 "Data: x%x x%x x%x x%x\n",
496 phba->brd_no,
497 CTrsp->CommandResponse.bits.CmdRsp,
498 (uint32_t) CTrsp->ReasonCode,
499 (uint32_t) CTrsp->Explanation,
500 phba->fc_flag);
501 } else {
502 /* NameServer Rsp Error */
503 lpfc_printf_log(phba,
504 KERN_INFO,
505 LOG_DISCOVERY,
506 "%d:0241 NameServer Rsp Error "
507 "Data: x%x x%x x%x x%x\n",
508 phba->brd_no,
509 CTrsp->CommandResponse.bits.CmdRsp,
510 (uint32_t) CTrsp->ReasonCode,
511 (uint32_t) CTrsp->Explanation,
512 phba->fc_flag);
515 /* Link up / RSCN discovery */
516 lpfc_disc_start(phba);
517 out:
518 lpfc_free_ct_rsp(phba, outp);
519 lpfc_mbuf_free(phba, inp->virt, inp->phys);
520 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
521 kfree(inp);
522 kfree(bmp);
523 spin_lock_irq(phba->host->host_lock);
524 lpfc_sli_release_iocbq(phba, cmdiocb);
525 spin_unlock_irq(phba->host->host_lock);
526 return;
529 static void
530 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
531 struct lpfc_iocbq * rspiocb)
533 struct lpfc_sli *psli;
534 struct lpfc_dmabuf *bmp;
535 struct lpfc_dmabuf *inp;
536 struct lpfc_dmabuf *outp;
537 IOCB_t *irsp;
538 struct lpfc_sli_ct_request *CTrsp;
540 psli = &phba->sli;
541 /* we pass cmdiocb to state machine which needs rspiocb as well */
542 cmdiocb->context_un.rsp_iocb = rspiocb;
544 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
545 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
546 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
547 irsp = &rspiocb->iocb;
549 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
551 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
552 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
553 "%d:0209 RFT request completes ulpStatus x%x "
554 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
555 CTrsp->CommandResponse.bits.CmdRsp);
557 lpfc_free_ct_rsp(phba, outp);
558 lpfc_mbuf_free(phba, inp->virt, inp->phys);
559 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
560 kfree(inp);
561 kfree(bmp);
562 spin_lock_irq(phba->host->host_lock);
563 lpfc_sli_release_iocbq(phba, cmdiocb);
564 spin_unlock_irq(phba->host->host_lock);
565 return;
568 static void
569 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
570 struct lpfc_iocbq * rspiocb)
572 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
573 return;
576 static void
577 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
578 struct lpfc_iocbq * rspiocb)
580 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
581 return;
584 void
585 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
587 char fwrev[16];
589 lpfc_decode_firmware_rev(phba, fwrev, 0);
591 if (phba->Port[0]) {
592 sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
593 phba->Port, fwrev, lpfc_release_version);
594 } else {
595 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
596 fwrev, lpfc_release_version);
601 * lpfc_ns_cmd
602 * Description:
603 * Issue Cmd to NameServer
604 * SLI_CTNS_GID_FT
605 * LI_CTNS_RFT_ID
608 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
610 struct lpfc_dmabuf *mp, *bmp;
611 struct lpfc_sli_ct_request *CtReq;
612 struct ulp_bde64 *bpl;
613 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
614 struct lpfc_iocbq *) = NULL;
615 uint32_t rsp_size = 1024;
617 /* fill in BDEs for command */
618 /* Allocate buffer for command payload */
619 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
620 if (!mp)
621 goto ns_cmd_exit;
623 INIT_LIST_HEAD(&mp->list);
624 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
625 if (!mp->virt)
626 goto ns_cmd_free_mp;
628 /* Allocate buffer for Buffer ptr list */
629 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
630 if (!bmp)
631 goto ns_cmd_free_mpvirt;
633 INIT_LIST_HEAD(&bmp->list);
634 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
635 if (!bmp->virt)
636 goto ns_cmd_free_bmp;
638 /* NameServer Req */
639 lpfc_printf_log(phba,
640 KERN_INFO,
641 LOG_DISCOVERY,
642 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
643 phba->brd_no, cmdcode, phba->fc_flag,
644 phba->fc_rscn_id_cnt);
646 bpl = (struct ulp_bde64 *) bmp->virt;
647 memset(bpl, 0, sizeof(struct ulp_bde64));
648 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
649 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
650 bpl->tus.f.bdeFlags = 0;
651 if (cmdcode == SLI_CTNS_GID_FT)
652 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
653 else if (cmdcode == SLI_CTNS_RFT_ID)
654 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
655 else if (cmdcode == SLI_CTNS_RNN_ID)
656 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
657 else if (cmdcode == SLI_CTNS_RSNN_NN)
658 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
659 else
660 bpl->tus.f.bdeSize = 0;
661 bpl->tus.w = le32_to_cpu(bpl->tus.w);
663 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
664 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
665 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
666 CtReq->RevisionId.bits.InId = 0;
667 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
668 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
669 CtReq->CommandResponse.bits.Size = 0;
670 switch (cmdcode) {
671 case SLI_CTNS_GID_FT:
672 CtReq->CommandResponse.bits.CmdRsp =
673 be16_to_cpu(SLI_CTNS_GID_FT);
674 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
675 if (phba->hba_state < LPFC_HBA_READY)
676 phba->hba_state = LPFC_NS_QRY;
677 lpfc_set_disctmo(phba);
678 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
679 rsp_size = FC_MAX_NS_RSP;
680 break;
682 case SLI_CTNS_RFT_ID:
683 CtReq->CommandResponse.bits.CmdRsp =
684 be16_to_cpu(SLI_CTNS_RFT_ID);
685 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
686 CtReq->un.rft.fcpReg = 1;
687 cmpl = lpfc_cmpl_ct_cmd_rft_id;
688 break;
690 case SLI_CTNS_RNN_ID:
691 CtReq->CommandResponse.bits.CmdRsp =
692 be16_to_cpu(SLI_CTNS_RNN_ID);
693 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
694 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
695 sizeof (struct lpfc_name));
696 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
697 break;
699 case SLI_CTNS_RSNN_NN:
700 CtReq->CommandResponse.bits.CmdRsp =
701 be16_to_cpu(SLI_CTNS_RSNN_NN);
702 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
703 sizeof (struct lpfc_name));
704 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
705 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
706 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
707 break;
710 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
711 /* On success, The cmpl function will free the buffers */
712 return 0;
714 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
715 ns_cmd_free_bmp:
716 kfree(bmp);
717 ns_cmd_free_mpvirt:
718 lpfc_mbuf_free(phba, mp->virt, mp->phys);
719 ns_cmd_free_mp:
720 kfree(mp);
721 ns_cmd_exit:
722 return 1;
725 static void
726 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
727 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
729 struct lpfc_dmabuf *bmp = cmdiocb->context3;
730 struct lpfc_dmabuf *inp = cmdiocb->context1;
731 struct lpfc_dmabuf *outp = cmdiocb->context2;
732 struct lpfc_sli_ct_request *CTrsp = outp->virt;
733 struct lpfc_sli_ct_request *CTcmd = inp->virt;
734 struct lpfc_nodelist *ndlp;
735 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
736 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
738 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
739 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
740 /* FDMI rsp failed */
741 lpfc_printf_log(phba,
742 KERN_INFO,
743 LOG_DISCOVERY,
744 "%d:0220 FDMI rsp failed Data: x%x\n",
745 phba->brd_no,
746 be16_to_cpu(fdmi_cmd));
749 switch (be16_to_cpu(fdmi_cmd)) {
750 case SLI_MGMT_RHBA:
751 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
752 break;
754 case SLI_MGMT_RPA:
755 break;
757 case SLI_MGMT_DHBA:
758 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
759 break;
761 case SLI_MGMT_DPRT:
762 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
763 break;
766 lpfc_free_ct_rsp(phba, outp);
767 lpfc_mbuf_free(phba, inp->virt, inp->phys);
768 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
769 kfree(inp);
770 kfree(bmp);
771 spin_lock_irq(phba->host->host_lock);
772 lpfc_sli_release_iocbq(phba, cmdiocb);
773 spin_unlock_irq(phba->host->host_lock);
774 return;
777 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
779 struct lpfc_dmabuf *mp, *bmp;
780 struct lpfc_sli_ct_request *CtReq;
781 struct ulp_bde64 *bpl;
782 uint32_t size;
783 REG_HBA *rh;
784 PORT_ENTRY *pe;
785 REG_PORT_ATTRIBUTE *pab;
786 ATTRIBUTE_BLOCK *ab;
787 ATTRIBUTE_ENTRY *ae;
788 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
789 struct lpfc_iocbq *);
792 /* fill in BDEs for command */
793 /* Allocate buffer for command payload */
794 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
795 if (!mp)
796 goto fdmi_cmd_exit;
798 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
799 if (!mp->virt)
800 goto fdmi_cmd_free_mp;
802 /* Allocate buffer for Buffer ptr list */
803 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
804 if (!bmp)
805 goto fdmi_cmd_free_mpvirt;
807 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
808 if (!bmp->virt)
809 goto fdmi_cmd_free_bmp;
811 INIT_LIST_HEAD(&mp->list);
812 INIT_LIST_HEAD(&bmp->list);
814 /* FDMI request */
815 lpfc_printf_log(phba,
816 KERN_INFO,
817 LOG_DISCOVERY,
818 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
819 phba->brd_no,
820 phba->fc_flag, phba->hba_state, cmdcode);
822 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
824 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
825 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
826 CtReq->RevisionId.bits.InId = 0;
828 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
829 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
830 size = 0;
832 switch (cmdcode) {
833 case SLI_MGMT_RHBA:
835 lpfc_vpd_t *vp = &phba->vpd;
836 uint32_t i, j, incr;
837 int len;
839 CtReq->CommandResponse.bits.CmdRsp =
840 be16_to_cpu(SLI_MGMT_RHBA);
841 CtReq->CommandResponse.bits.Size = 0;
842 rh = (REG_HBA *) & CtReq->un.PortID;
843 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
844 sizeof (struct lpfc_name));
845 /* One entry (port) per adapter */
846 rh->rpl.EntryCnt = be32_to_cpu(1);
847 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
848 sizeof (struct lpfc_name));
850 /* point to the HBA attribute block */
851 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
852 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
853 ab->EntryCnt = 0;
855 /* Point to the beginning of the first HBA attribute
856 entry */
857 /* #1 HBA attribute entry */
858 size += FOURBYTES;
859 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
860 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
861 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
862 + sizeof (struct lpfc_name));
863 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
864 sizeof (struct lpfc_name));
865 ab->EntryCnt++;
866 size += FOURBYTES + sizeof (struct lpfc_name);
868 /* #2 HBA attribute entry */
869 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
870 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
871 strcpy(ae->un.Manufacturer, "Emulex Corporation");
872 len = strlen(ae->un.Manufacturer);
873 len += (len & 3) ? (4 - (len & 3)) : 4;
874 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
875 ab->EntryCnt++;
876 size += FOURBYTES + len;
878 /* #3 HBA attribute entry */
879 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
880 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
881 strcpy(ae->un.SerialNumber, phba->SerialNumber);
882 len = strlen(ae->un.SerialNumber);
883 len += (len & 3) ? (4 - (len & 3)) : 4;
884 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
885 ab->EntryCnt++;
886 size += FOURBYTES + len;
888 /* #4 HBA attribute entry */
889 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
890 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
891 strcpy(ae->un.Model, phba->ModelName);
892 len = strlen(ae->un.Model);
893 len += (len & 3) ? (4 - (len & 3)) : 4;
894 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
895 ab->EntryCnt++;
896 size += FOURBYTES + len;
898 /* #5 HBA attribute entry */
899 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
900 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
901 strcpy(ae->un.ModelDescription, phba->ModelDesc);
902 len = strlen(ae->un.ModelDescription);
903 len += (len & 3) ? (4 - (len & 3)) : 4;
904 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
905 ab->EntryCnt++;
906 size += FOURBYTES + len;
908 /* #6 HBA attribute entry */
909 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
910 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
911 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
912 /* Convert JEDEC ID to ascii for hardware version */
913 incr = vp->rev.biuRev;
914 for (i = 0; i < 8; i++) {
915 j = (incr & 0xf);
916 if (j <= 9)
917 ae->un.HardwareVersion[7 - i] =
918 (char)((uint8_t) 0x30 +
919 (uint8_t) j);
920 else
921 ae->un.HardwareVersion[7 - i] =
922 (char)((uint8_t) 0x61 +
923 (uint8_t) (j - 10));
924 incr = (incr >> 4);
926 ab->EntryCnt++;
927 size += FOURBYTES + 8;
929 /* #7 HBA attribute entry */
930 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
931 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
932 strcpy(ae->un.DriverVersion, lpfc_release_version);
933 len = strlen(ae->un.DriverVersion);
934 len += (len & 3) ? (4 - (len & 3)) : 4;
935 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
936 ab->EntryCnt++;
937 size += FOURBYTES + len;
939 /* #8 HBA attribute entry */
940 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
941 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
942 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
943 len = strlen(ae->un.OptionROMVersion);
944 len += (len & 3) ? (4 - (len & 3)) : 4;
945 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
946 ab->EntryCnt++;
947 size += FOURBYTES + len;
949 /* #9 HBA attribute entry */
950 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
951 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
952 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
954 len = strlen(ae->un.FirmwareVersion);
955 len += (len & 3) ? (4 - (len & 3)) : 4;
956 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
957 ab->EntryCnt++;
958 size += FOURBYTES + len;
960 /* #10 HBA attribute entry */
961 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
962 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
963 sprintf(ae->un.OsNameVersion, "%s %s %s",
964 system_utsname.sysname, system_utsname.release,
965 system_utsname.version);
966 len = strlen(ae->un.OsNameVersion);
967 len += (len & 3) ? (4 - (len & 3)) : 4;
968 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
969 ab->EntryCnt++;
970 size += FOURBYTES + len;
972 /* #11 HBA attribute entry */
973 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
974 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
975 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
976 ae->un.MaxCTPayloadLen = (65 * 4096);
977 ab->EntryCnt++;
978 size += FOURBYTES + 4;
980 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
981 /* Total size */
982 size = GID_REQUEST_SZ - 4 + size;
984 break;
986 case SLI_MGMT_RPA:
988 lpfc_vpd_t *vp;
989 struct serv_parm *hsp;
990 int len;
992 vp = &phba->vpd;
994 CtReq->CommandResponse.bits.CmdRsp =
995 be16_to_cpu(SLI_MGMT_RPA);
996 CtReq->CommandResponse.bits.Size = 0;
997 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
998 size = sizeof (struct lpfc_name) + FOURBYTES;
999 memcpy((uint8_t *) & pab->PortName,
1000 (uint8_t *) & phba->fc_sparam.portName,
1001 sizeof (struct lpfc_name));
1002 pab->ab.EntryCnt = 0;
1004 /* #1 Port attribute entry */
1005 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1006 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1007 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1008 ae->un.SupportFC4Types[2] = 1;
1009 ae->un.SupportFC4Types[7] = 1;
1010 pab->ab.EntryCnt++;
1011 size += FOURBYTES + 32;
1013 /* #2 Port attribute entry */
1014 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1015 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1016 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1018 ae->un.SupportSpeed = 0;
1019 if (phba->lmt & LMT_10Gb)
1020 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1021 if (phba->lmt & LMT_8Gb)
1022 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1023 if (phba->lmt & LMT_4Gb)
1024 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1025 if (phba->lmt & LMT_2Gb)
1026 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1027 if (phba->lmt & LMT_1Gb)
1028 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1030 pab->ab.EntryCnt++;
1031 size += FOURBYTES + 4;
1033 /* #3 Port attribute entry */
1034 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1035 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1036 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1037 switch(phba->fc_linkspeed) {
1038 case LA_1GHZ_LINK:
1039 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1040 break;
1041 case LA_2GHZ_LINK:
1042 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1043 break;
1044 case LA_4GHZ_LINK:
1045 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1046 break;
1047 default:
1048 ae->un.PortSpeed =
1049 HBA_PORTSPEED_UNKNOWN;
1050 break;
1052 pab->ab.EntryCnt++;
1053 size += FOURBYTES + 4;
1055 /* #4 Port attribute entry */
1056 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1057 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1058 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1059 hsp = (struct serv_parm *) & phba->fc_sparam;
1060 ae->un.MaxFrameSize =
1061 (((uint32_t) hsp->cmn.
1062 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1063 bbRcvSizeLsb;
1064 pab->ab.EntryCnt++;
1065 size += FOURBYTES + 4;
1067 /* #5 Port attribute entry */
1068 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1069 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1070 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1071 len = strlen((char *)ae->un.OsDeviceName);
1072 len += (len & 3) ? (4 - (len & 3)) : 4;
1073 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1074 pab->ab.EntryCnt++;
1075 size += FOURBYTES + len;
1077 if (phba->cfg_fdmi_on == 2) {
1078 /* #6 Port attribute entry */
1079 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1080 size);
1081 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1082 sprintf(ae->un.HostName, "%s",
1083 system_utsname.nodename);
1084 len = strlen(ae->un.HostName);
1085 len += (len & 3) ? (4 - (len & 3)) : 4;
1086 ae->ad.bits.AttrLen =
1087 be16_to_cpu(FOURBYTES + len);
1088 pab->ab.EntryCnt++;
1089 size += FOURBYTES + len;
1092 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1093 /* Total size */
1094 size = GID_REQUEST_SZ - 4 + size;
1096 break;
1098 case SLI_MGMT_DHBA:
1099 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1100 CtReq->CommandResponse.bits.Size = 0;
1101 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1102 memcpy((uint8_t *) & pe->PortName,
1103 (uint8_t *) & phba->fc_sparam.portName,
1104 sizeof (struct lpfc_name));
1105 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1106 break;
1108 case SLI_MGMT_DPRT:
1109 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1110 CtReq->CommandResponse.bits.Size = 0;
1111 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1112 memcpy((uint8_t *) & pe->PortName,
1113 (uint8_t *) & phba->fc_sparam.portName,
1114 sizeof (struct lpfc_name));
1115 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1116 break;
1119 bpl = (struct ulp_bde64 *) bmp->virt;
1120 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1121 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1122 bpl->tus.f.bdeFlags = 0;
1123 bpl->tus.f.bdeSize = size;
1124 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1126 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1128 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1129 return 0;
1131 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1132 fdmi_cmd_free_bmp:
1133 kfree(bmp);
1134 fdmi_cmd_free_mpvirt:
1135 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1136 fdmi_cmd_free_mp:
1137 kfree(mp);
1138 fdmi_cmd_exit:
1139 /* Issue FDMI request failed */
1140 lpfc_printf_log(phba,
1141 KERN_INFO,
1142 LOG_DISCOVERY,
1143 "%d:0244 Issue FDMI request failed Data: x%x\n",
1144 phba->brd_no,
1145 cmdcode);
1146 return 1;
1149 void
1150 lpfc_fdmi_tmo(unsigned long ptr)
1152 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1153 unsigned long iflag;
1155 spin_lock_irqsave(phba->host->host_lock, iflag);
1156 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1157 phba->work_hba_events |= WORKER_FDMI_TMO;
1158 if (phba->work_wait)
1159 wake_up(phba->work_wait);
1161 spin_unlock_irqrestore(phba->host->host_lock,iflag);
1164 void
1165 lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1167 struct lpfc_nodelist *ndlp;
1169 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1170 if (ndlp) {
1171 if (system_utsname.nodename[0] != '\0') {
1172 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1173 } else {
1174 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1177 return;
1181 void
1182 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1184 struct lpfc_sli *psli = &phba->sli;
1185 lpfc_vpd_t *vp = &phba->vpd;
1186 uint32_t b1, b2, b3, b4, i, rev;
1187 char c;
1188 uint32_t *ptr, str[4];
1189 uint8_t *fwname;
1191 if (vp->rev.rBit) {
1192 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1193 rev = vp->rev.sli2FwRev;
1194 else
1195 rev = vp->rev.sli1FwRev;
1197 b1 = (rev & 0x0000f000) >> 12;
1198 b2 = (rev & 0x00000f00) >> 8;
1199 b3 = (rev & 0x000000c0) >> 6;
1200 b4 = (rev & 0x00000030) >> 4;
1202 switch (b4) {
1203 case 0:
1204 c = 'N';
1205 break;
1206 case 1:
1207 c = 'A';
1208 break;
1209 case 2:
1210 c = 'B';
1211 break;
1212 default:
1213 c = 0;
1214 break;
1216 b4 = (rev & 0x0000000f);
1218 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1219 fwname = vp->rev.sli2FwName;
1220 else
1221 fwname = vp->rev.sli1FwName;
1223 for (i = 0; i < 16; i++)
1224 if (fwname[i] == 0x20)
1225 fwname[i] = 0;
1227 ptr = (uint32_t*)fwname;
1229 for (i = 0; i < 3; i++)
1230 str[i] = be32_to_cpu(*ptr++);
1232 if (c == 0) {
1233 if (flag)
1234 sprintf(fwrevision, "%d.%d%d (%s)",
1235 b1, b2, b3, (char *)str);
1236 else
1237 sprintf(fwrevision, "%d.%d%d", b1,
1238 b2, b3);
1239 } else {
1240 if (flag)
1241 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1242 b1, b2, b3, c,
1243 b4, (char *)str);
1244 else
1245 sprintf(fwrevision, "%d.%d%d%c%d",
1246 b1, b2, b3, c, b4);
1248 } else {
1249 rev = vp->rev.smFwRev;
1251 b1 = (rev & 0xff000000) >> 24;
1252 b2 = (rev & 0x00f00000) >> 20;
1253 b3 = (rev & 0x000f0000) >> 16;
1254 c = (rev & 0x0000ff00) >> 8;
1255 b4 = (rev & 0x000000ff);
1257 if (flag)
1258 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1259 b2, b3, c, b4);
1260 else
1261 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1262 b2, b3, c, b4);
1264 return;