[SCSI] lpfc 8.1.2: Code style changes for Discovery code
[pandora-kernel.git] / drivers / scsi / lpfc / lpfc_ct.c
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  *******************************************************************/
20
21 /*
22  * Fibre Channel SCSI LAN Device Driver CT support
23  */
24
25 #include <linux/blkdev.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/utsname.h>
29
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34
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"
43
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 */
52
53 #define FOURBYTES       4
54
55
56 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
57
58 /*
59  * lpfc_ct_unsol_event
60  */
61 void
62 lpfc_ct_unsol_event(struct lpfc_hba * phba,
63                     struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
64 {
65
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;
74
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;
81         }
82
83         /* If there are no BDEs associated with this IOCB,
84          * there is nothing to do.
85          */
86         if (icmd->ulpBdeCount == 0)
87                 return;
88
89         INIT_LIST_HEAD(&head);
90         list_add_tail(&head, &piocbq->list);
91
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;
98
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;
112                         }
113
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);
120
121                         size += icmd->un.cont64[i].tus.f.bdeSize;
122                         cnt++;
123                 }
124
125                 icmd->ulpBdeCount = 0;
126         }
127
128         lpfc_post_buffer(phba, pring, cnt, 1);
129         if (save_icmd->ulpStatus) {
130                 go_exit = 1;
131         }
132
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);
139                 }
140                 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
141                 kfree(pmbuf);
142         }
143         return;
144 }
145
146 static void
147 lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
148 {
149         struct lpfc_dmabuf *mlast, *next_mlast;
150
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);
155         }
156         lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
157         kfree(mlist);
158         return;
159 }
160
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)
164 {
165         struct lpfc_dmabuf *mlist = NULL;
166         struct lpfc_dmabuf *mp;
167         int cnt, i = 0;
168
169         /* We get chucks of FCELSSIZE */
170         cnt = size > FCELSSIZE ? FCELSSIZE: size;
171
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;
179                 }
180
181                 INIT_LIST_HEAD(&mp->list);
182
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));
187
188                 if (!mp->virt) {
189                         kfree(mp);
190                         lpfc_free_ct_rsp(phba, mlist);
191                         return NULL;
192                 }
193
194                 /* Queue it to a linked list */
195                 if (!mlist)
196                         mlist = mp;
197                 else
198                         list_add_tail(&mp->list, &mlist->list);
199
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++;
207
208                 i++;
209                 size -= cnt;
210         }
211
212         *entries = i;
213         return mlist;
214 }
215
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)
223 {
224
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;
229
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);
234
235         if (geniocb == NULL)
236                 return 1;
237
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));
244
245         if (usr_flg)
246                 geniocb->context3 = NULL;
247         else
248                 geniocb->context3 = (uint8_t *) bmp;
249
250         /* Save for completion so we can release these resources */
251         geniocb->context1 = (uint8_t *) inp;
252         geniocb->context2 = (uint8_t *) outp;
253
254         /* Fill in payload, bp points to frame payload */
255         icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
256
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;
262
263         if (!tmo) {
264                  /* FC spec states we need 3 * ratov for CT requests */
265                 tmo = (3 * phba->fc_ratov);
266         }
267         icmd->ulpTimeout = tmo;
268         icmd->ulpBdeCount = 1;
269         icmd->ulpLe = 1;
270         icmd->ulpClass = CLASS3;
271         icmd->ulpContext = ndlp->nlp_rpi;
272
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;
285         }
286         spin_unlock_irq(phba->host->host_lock);
287
288         return 0;
289 }
290
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)
297 {
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;
303
304         bpl++;                  /* Skip past ct request */
305
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;
310
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;
316         }
317         return 0;
318 }
319
320 static int
321 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
322 {
323         struct lpfc_sli_ct_request *Response =
324                 (struct lpfc_sli_ct_request *) mp->virt;
325         struct lpfc_nodelist *ndlp = NULL;
326         struct lpfc_dmabuf *mlast, *next_mp;
327         uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
328         uint32_t Did;
329         uint32_t CTentry;
330         int Cnt;
331         struct list_head head;
332
333         lpfc_set_disctmo(phba);
334
335         Cnt = Size  > FCELSSIZE ? FCELSSIZE : Size;
336
337         list_add_tail(&head, &mp->list);
338         list_for_each_entry_safe(mp, next_mp, &head, list) {
339                 mlast = mp;
340
341                 Size -= Cnt;
342
343                 if (!ctptr)
344                         ctptr = (uint32_t *) mlast->virt;
345                 else
346                         Cnt -= 16;      /* subtract length of CT header */
347
348                 /* Loop through entire NameServer list of DIDs */
349                 while (Cnt) {
350
351                         /* Get next DID from NameServer List */
352                         CTentry = *ctptr++;
353                         Did = ((be32_to_cpu(CTentry)) & Mask_DID);
354
355                         ndlp = NULL;
356                         if (Did != phba->fc_myDID) {
357                                 /* Check for rscn processing or not */
358                                 ndlp = lpfc_setup_disc_node(phba, Did);
359                         }
360                         /* Mark all node table entries that are in the
361                            Nameserver */
362                         if (ndlp) {
363                                 /* NameServer Rsp */
364                                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
365                                                 "%d:0238 Process x%x NameServer"
366                                                 " Rsp Data: x%x x%x x%x\n",
367                                                 phba->brd_no,
368                                                 Did, ndlp->nlp_flag,
369                                                 phba->fc_flag,
370                                                 phba->fc_rscn_id_cnt);
371                         } else {
372                                 /* NameServer Rsp */
373                                 lpfc_printf_log(phba,
374                                                 KERN_INFO,
375                                                 LOG_DISCOVERY,
376                                                 "%d:0239 Skip x%x NameServer "
377                                                 "Rsp Data: x%x x%x x%x\n",
378                                                 phba->brd_no,
379                                                 Did, Size, phba->fc_flag,
380                                                 phba->fc_rscn_id_cnt);
381                         }
382
383                         if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
384                                 goto nsout1;
385                         Cnt -= sizeof (uint32_t);
386                 }
387                 ctptr = NULL;
388
389         }
390
391 nsout1:
392         list_del(&head);
393
394         /* Here we are finished in the case RSCN */
395         if (phba->hba_state == LPFC_HBA_READY) {
396                 lpfc_els_flush_rscn(phba);
397                 spin_lock_irq(phba->host->host_lock);
398                 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
399                 spin_unlock_irq(phba->host->host_lock);
400         }
401         return 0;
402 }
403
404
405
406
407 static void
408 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
409                         struct lpfc_iocbq * rspiocb)
410 {
411         IOCB_t *irsp;
412         struct lpfc_sli *psli;
413         struct lpfc_dmabuf *bmp;
414         struct lpfc_dmabuf *inp;
415         struct lpfc_dmabuf *outp;
416         struct lpfc_nodelist *ndlp;
417         struct lpfc_sli_ct_request *CTrsp;
418
419         psli = &phba->sli;
420         /* we pass cmdiocb to state machine which needs rspiocb as well */
421         cmdiocb->context_un.rsp_iocb = rspiocb;
422
423         inp = (struct lpfc_dmabuf *) cmdiocb->context1;
424         outp = (struct lpfc_dmabuf *) cmdiocb->context2;
425         bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
426
427         irsp = &rspiocb->iocb;
428         if (irsp->ulpStatus) {
429                 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
430                         ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
431                          (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
432                         goto out;
433                 }
434
435                 /* Check for retry */
436                 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
437                         phba->fc_ns_retry++;
438                         /* CT command is being retried */
439                         ndlp =
440                             lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
441                                               NameServer_DID);
442                         if (ndlp) {
443                                 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
444                                     0) {
445                                         goto out;
446                                 }
447                         }
448                 }
449         } else {
450                 /* Good status, continue checking */
451                 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
452                 if (CTrsp->CommandResponse.bits.CmdRsp ==
453                     be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
454                         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
455                                         "%d:0239 NameServer Rsp "
456                                         "Data: x%x\n",
457                                         phba->brd_no,
458                                         phba->fc_flag);
459                         lpfc_ns_rsp(phba, outp,
460                                     (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
461                 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
462                            be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
463                         /* NameServer Rsp Error */
464                         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
465                                         "%d:0240 NameServer Rsp Error "
466                                         "Data: x%x x%x x%x x%x\n",
467                                         phba->brd_no,
468                                         CTrsp->CommandResponse.bits.CmdRsp,
469                                         (uint32_t) CTrsp->ReasonCode,
470                                         (uint32_t) CTrsp->Explanation,
471                                         phba->fc_flag);
472                 } else {
473                         /* NameServer Rsp Error */
474                         lpfc_printf_log(phba,
475                                         KERN_INFO,
476                                         LOG_DISCOVERY,
477                                         "%d:0241 NameServer Rsp Error "
478                                         "Data: x%x x%x x%x x%x\n",
479                                         phba->brd_no,
480                                         CTrsp->CommandResponse.bits.CmdRsp,
481                                         (uint32_t) CTrsp->ReasonCode,
482                                         (uint32_t) CTrsp->Explanation,
483                                         phba->fc_flag);
484                 }
485         }
486         /* Link up / RSCN discovery */
487         lpfc_disc_start(phba);
488 out:
489         lpfc_free_ct_rsp(phba, outp);
490         lpfc_mbuf_free(phba, inp->virt, inp->phys);
491         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
492         kfree(inp);
493         kfree(bmp);
494         spin_lock_irq(phba->host->host_lock);
495         lpfc_sli_release_iocbq(phba, cmdiocb);
496         spin_unlock_irq(phba->host->host_lock);
497         return;
498 }
499
500 static void
501 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
502                         struct lpfc_iocbq * rspiocb)
503 {
504         struct lpfc_sli *psli;
505         struct lpfc_dmabuf *bmp;
506         struct lpfc_dmabuf *inp;
507         struct lpfc_dmabuf *outp;
508         IOCB_t *irsp;
509         struct lpfc_sli_ct_request *CTrsp;
510
511         psli = &phba->sli;
512         /* we pass cmdiocb to state machine which needs rspiocb as well */
513         cmdiocb->context_un.rsp_iocb = rspiocb;
514
515         inp = (struct lpfc_dmabuf *) cmdiocb->context1;
516         outp = (struct lpfc_dmabuf *) cmdiocb->context2;
517         bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
518         irsp = &rspiocb->iocb;
519
520         CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
521
522         /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
523         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
524                         "%d:0209 RFT request completes ulpStatus x%x "
525                         "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
526                         CTrsp->CommandResponse.bits.CmdRsp);
527
528         lpfc_free_ct_rsp(phba, outp);
529         lpfc_mbuf_free(phba, inp->virt, inp->phys);
530         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
531         kfree(inp);
532         kfree(bmp);
533         spin_lock_irq(phba->host->host_lock);
534         lpfc_sli_release_iocbq(phba, cmdiocb);
535         spin_unlock_irq(phba->host->host_lock);
536         return;
537 }
538
539 static void
540 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
541                         struct lpfc_iocbq * rspiocb)
542 {
543         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
544         return;
545 }
546
547 static void
548 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
549                          struct lpfc_iocbq * rspiocb)
550 {
551         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
552         return;
553 }
554
555 void
556 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
557 {
558         char fwrev[16];
559
560         lpfc_decode_firmware_rev(phba, fwrev, 0);
561
562         if (phba->Port[0]) {
563                 sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
564                         phba->Port, fwrev, lpfc_release_version);
565         } else {
566                 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
567                         fwrev, lpfc_release_version);
568         }
569 }
570
571 /*
572  * lpfc_ns_cmd
573  * Description:
574  *    Issue Cmd to NameServer
575  *       SLI_CTNS_GID_FT
576  *       LI_CTNS_RFT_ID
577  */
578 int
579 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
580 {
581         struct lpfc_dmabuf *mp, *bmp;
582         struct lpfc_sli_ct_request *CtReq;
583         struct ulp_bde64 *bpl;
584         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
585                       struct lpfc_iocbq *) = NULL;
586         uint32_t rsp_size = 1024;
587
588         /* fill in BDEs for command */
589         /* Allocate buffer for command payload */
590         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
591         if (!mp)
592                 goto ns_cmd_exit;
593
594         INIT_LIST_HEAD(&mp->list);
595         mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
596         if (!mp->virt)
597                 goto ns_cmd_free_mp;
598
599         /* Allocate buffer for Buffer ptr list */
600         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
601         if (!bmp)
602                 goto ns_cmd_free_mpvirt;
603
604         INIT_LIST_HEAD(&bmp->list);
605         bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
606         if (!bmp->virt)
607                 goto ns_cmd_free_bmp;
608
609         /* NameServer Req */
610         lpfc_printf_log(phba,
611                         KERN_INFO,
612                         LOG_DISCOVERY,
613                         "%d:0236 NameServer Req Data: x%x x%x x%x\n",
614                         phba->brd_no, cmdcode, phba->fc_flag,
615                         phba->fc_rscn_id_cnt);
616
617         bpl = (struct ulp_bde64 *) bmp->virt;
618         memset(bpl, 0, sizeof(struct ulp_bde64));
619         bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
620         bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
621         bpl->tus.f.bdeFlags = 0;
622         if (cmdcode == SLI_CTNS_GID_FT)
623                 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
624         else if (cmdcode == SLI_CTNS_RFT_ID)
625                 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
626         else if (cmdcode == SLI_CTNS_RNN_ID)
627                 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
628         else if (cmdcode == SLI_CTNS_RSNN_NN)
629                 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
630         else
631                 bpl->tus.f.bdeSize = 0;
632         bpl->tus.w = le32_to_cpu(bpl->tus.w);
633
634         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
635         memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
636         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
637         CtReq->RevisionId.bits.InId = 0;
638         CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
639         CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
640         CtReq->CommandResponse.bits.Size = 0;
641         switch (cmdcode) {
642         case SLI_CTNS_GID_FT:
643                 CtReq->CommandResponse.bits.CmdRsp =
644                     be16_to_cpu(SLI_CTNS_GID_FT);
645                 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
646                 if (phba->hba_state < LPFC_HBA_READY)
647                         phba->hba_state = LPFC_NS_QRY;
648                 lpfc_set_disctmo(phba);
649                 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
650                 rsp_size = FC_MAX_NS_RSP;
651                 break;
652
653         case SLI_CTNS_RFT_ID:
654                 CtReq->CommandResponse.bits.CmdRsp =
655                     be16_to_cpu(SLI_CTNS_RFT_ID);
656                 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
657                 CtReq->un.rft.fcpReg = 1;
658                 cmpl = lpfc_cmpl_ct_cmd_rft_id;
659                 break;
660
661         case SLI_CTNS_RNN_ID:
662                 CtReq->CommandResponse.bits.CmdRsp =
663                     be16_to_cpu(SLI_CTNS_RNN_ID);
664                 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
665                 memcpy(CtReq->un.rnn.wwnn,  &phba->fc_nodename,
666                        sizeof (struct lpfc_name));
667                 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
668                 break;
669
670         case SLI_CTNS_RSNN_NN:
671                 CtReq->CommandResponse.bits.CmdRsp =
672                     be16_to_cpu(SLI_CTNS_RSNN_NN);
673                 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
674                        sizeof (struct lpfc_name));
675                 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
676                 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
677                 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
678                 break;
679         }
680
681         if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
682                 /* On success, The cmpl function will free the buffers */
683                 return 0;
684
685         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
686 ns_cmd_free_bmp:
687         kfree(bmp);
688 ns_cmd_free_mpvirt:
689         lpfc_mbuf_free(phba, mp->virt, mp->phys);
690 ns_cmd_free_mp:
691         kfree(mp);
692 ns_cmd_exit:
693         return 1;
694 }
695
696 static void
697 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
698                       struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
699 {
700         struct lpfc_dmabuf *bmp = cmdiocb->context3;
701         struct lpfc_dmabuf *inp = cmdiocb->context1;
702         struct lpfc_dmabuf *outp = cmdiocb->context2;
703         struct lpfc_sli_ct_request *CTrsp = outp->virt;
704         struct lpfc_sli_ct_request *CTcmd = inp->virt;
705         struct lpfc_nodelist *ndlp;
706         uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
707         uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
708
709         ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
710         if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
711                 /* FDMI rsp failed */
712                 lpfc_printf_log(phba,
713                                 KERN_INFO,
714                                 LOG_DISCOVERY,
715                                 "%d:0220 FDMI rsp failed Data: x%x\n",
716                                 phba->brd_no,
717                                be16_to_cpu(fdmi_cmd));
718         }
719
720         switch (be16_to_cpu(fdmi_cmd)) {
721         case SLI_MGMT_RHBA:
722                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
723                 break;
724
725         case SLI_MGMT_RPA:
726                 break;
727
728         case SLI_MGMT_DHBA:
729                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
730                 break;
731
732         case SLI_MGMT_DPRT:
733                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
734                 break;
735         }
736
737         lpfc_free_ct_rsp(phba, outp);
738         lpfc_mbuf_free(phba, inp->virt, inp->phys);
739         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
740         kfree(inp);
741         kfree(bmp);
742         spin_lock_irq(phba->host->host_lock);
743         lpfc_sli_release_iocbq(phba, cmdiocb);
744         spin_unlock_irq(phba->host->host_lock);
745         return;
746 }
747 int
748 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
749 {
750         struct lpfc_dmabuf *mp, *bmp;
751         struct lpfc_sli_ct_request *CtReq;
752         struct ulp_bde64 *bpl;
753         uint32_t size;
754         REG_HBA *rh;
755         PORT_ENTRY *pe;
756         REG_PORT_ATTRIBUTE *pab;
757         ATTRIBUTE_BLOCK *ab;
758         ATTRIBUTE_ENTRY *ae;
759         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
760                       struct lpfc_iocbq *);
761
762
763         /* fill in BDEs for command */
764         /* Allocate buffer for command payload */
765         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
766         if (!mp)
767                 goto fdmi_cmd_exit;
768
769         mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
770         if (!mp->virt)
771                 goto fdmi_cmd_free_mp;
772
773         /* Allocate buffer for Buffer ptr list */
774         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
775         if (!bmp)
776                 goto fdmi_cmd_free_mpvirt;
777
778         bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
779         if (!bmp->virt)
780                 goto fdmi_cmd_free_bmp;
781
782         INIT_LIST_HEAD(&mp->list);
783         INIT_LIST_HEAD(&bmp->list);
784
785         /* FDMI request */
786         lpfc_printf_log(phba,
787                         KERN_INFO,
788                         LOG_DISCOVERY,
789                         "%d:0218 FDMI Request Data: x%x x%x x%x\n",
790                         phba->brd_no,
791                        phba->fc_flag, phba->hba_state, cmdcode);
792
793         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
794
795         memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
796         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
797         CtReq->RevisionId.bits.InId = 0;
798
799         CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
800         CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
801         size = 0;
802
803         switch (cmdcode) {
804         case SLI_MGMT_RHBA:
805                 {
806                         lpfc_vpd_t *vp = &phba->vpd;
807                         uint32_t i, j, incr;
808                         int len;
809
810                         CtReq->CommandResponse.bits.CmdRsp =
811                             be16_to_cpu(SLI_MGMT_RHBA);
812                         CtReq->CommandResponse.bits.Size = 0;
813                         rh = (REG_HBA *) & CtReq->un.PortID;
814                         memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
815                                sizeof (struct lpfc_name));
816                         /* One entry (port) per adapter */
817                         rh->rpl.EntryCnt = be32_to_cpu(1);
818                         memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
819                                sizeof (struct lpfc_name));
820
821                         /* point to the HBA attribute block */
822                         size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
823                         ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
824                         ab->EntryCnt = 0;
825
826                         /* Point to the beginning of the first HBA attribute
827                            entry */
828                         /* #1 HBA attribute entry */
829                         size += FOURBYTES;
830                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
831                         ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
832                         ae->ad.bits.AttrLen =  be16_to_cpu(FOURBYTES
833                                                 + sizeof (struct lpfc_name));
834                         memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
835                                sizeof (struct lpfc_name));
836                         ab->EntryCnt++;
837                         size += FOURBYTES + sizeof (struct lpfc_name);
838
839                         /* #2 HBA attribute entry */
840                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
841                         ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
842                         strcpy(ae->un.Manufacturer, "Emulex Corporation");
843                         len = strlen(ae->un.Manufacturer);
844                         len += (len & 3) ? (4 - (len & 3)) : 4;
845                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
846                         ab->EntryCnt++;
847                         size += FOURBYTES + len;
848
849                         /* #3 HBA attribute entry */
850                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
851                         ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
852                         strcpy(ae->un.SerialNumber, phba->SerialNumber);
853                         len = strlen(ae->un.SerialNumber);
854                         len += (len & 3) ? (4 - (len & 3)) : 4;
855                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
856                         ab->EntryCnt++;
857                         size += FOURBYTES + len;
858
859                         /* #4 HBA attribute entry */
860                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
861                         ae->ad.bits.AttrType = be16_to_cpu(MODEL);
862                         strcpy(ae->un.Model, phba->ModelName);
863                         len = strlen(ae->un.Model);
864                         len += (len & 3) ? (4 - (len & 3)) : 4;
865                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
866                         ab->EntryCnt++;
867                         size += FOURBYTES + len;
868
869                         /* #5 HBA attribute entry */
870                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
871                         ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
872                         strcpy(ae->un.ModelDescription, phba->ModelDesc);
873                         len = strlen(ae->un.ModelDescription);
874                         len += (len & 3) ? (4 - (len & 3)) : 4;
875                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
876                         ab->EntryCnt++;
877                         size += FOURBYTES + len;
878
879                         /* #6 HBA attribute entry */
880                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
881                         ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
882                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
883                         /* Convert JEDEC ID to ascii for hardware version */
884                         incr = vp->rev.biuRev;
885                         for (i = 0; i < 8; i++) {
886                                 j = (incr & 0xf);
887                                 if (j <= 9)
888                                         ae->un.HardwareVersion[7 - i] =
889                                             (char)((uint8_t) 0x30 +
890                                                    (uint8_t) j);
891                                 else
892                                         ae->un.HardwareVersion[7 - i] =
893                                             (char)((uint8_t) 0x61 +
894                                                    (uint8_t) (j - 10));
895                                 incr = (incr >> 4);
896                         }
897                         ab->EntryCnt++;
898                         size += FOURBYTES + 8;
899
900                         /* #7 HBA attribute entry */
901                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
902                         ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
903                         strcpy(ae->un.DriverVersion, lpfc_release_version);
904                         len = strlen(ae->un.DriverVersion);
905                         len += (len & 3) ? (4 - (len & 3)) : 4;
906                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
907                         ab->EntryCnt++;
908                         size += FOURBYTES + len;
909
910                         /* #8 HBA attribute entry */
911                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
912                         ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
913                         strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
914                         len = strlen(ae->un.OptionROMVersion);
915                         len += (len & 3) ? (4 - (len & 3)) : 4;
916                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
917                         ab->EntryCnt++;
918                         size += FOURBYTES + len;
919
920                         /* #9 HBA attribute entry */
921                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
922                         ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
923                         lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
924                                 1);
925                         len = strlen(ae->un.FirmwareVersion);
926                         len += (len & 3) ? (4 - (len & 3)) : 4;
927                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
928                         ab->EntryCnt++;
929                         size += FOURBYTES + len;
930
931                         /* #10 HBA attribute entry */
932                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
933                         ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
934                         sprintf(ae->un.OsNameVersion, "%s %s %s",
935                                 system_utsname.sysname, system_utsname.release,
936                                 system_utsname.version);
937                         len = strlen(ae->un.OsNameVersion);
938                         len += (len & 3) ? (4 - (len & 3)) : 4;
939                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
940                         ab->EntryCnt++;
941                         size += FOURBYTES + len;
942
943                         /* #11 HBA attribute entry */
944                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
945                         ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
946                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
947                         ae->un.MaxCTPayloadLen = (65 * 4096);
948                         ab->EntryCnt++;
949                         size += FOURBYTES + 4;
950
951                         ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
952                         /* Total size */
953                         size = GID_REQUEST_SZ - 4 + size;
954                 }
955                 break;
956
957         case SLI_MGMT_RPA:
958                 {
959                         lpfc_vpd_t *vp;
960                         struct serv_parm *hsp;
961                         int len;
962
963                         vp = &phba->vpd;
964
965                         CtReq->CommandResponse.bits.CmdRsp =
966                             be16_to_cpu(SLI_MGMT_RPA);
967                         CtReq->CommandResponse.bits.Size = 0;
968                         pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
969                         size = sizeof (struct lpfc_name) + FOURBYTES;
970                         memcpy((uint8_t *) & pab->PortName,
971                                (uint8_t *) & phba->fc_sparam.portName,
972                                sizeof (struct lpfc_name));
973                         pab->ab.EntryCnt = 0;
974
975                         /* #1 Port attribute entry */
976                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
977                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
978                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
979                         ae->un.SupportFC4Types[2] = 1;
980                         ae->un.SupportFC4Types[7] = 1;
981                         pab->ab.EntryCnt++;
982                         size += FOURBYTES + 32;
983
984                         /* #2 Port attribute entry */
985                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
986                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
987                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
988                         if (FC_JEDEC_ID(vp->rev.biuRev) == VIPER_JEDEC_ID)
989                                 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
990                         else if (FC_JEDEC_ID(vp->rev.biuRev) == HELIOS_JEDEC_ID)
991                                 ae->un.SupportSpeed = HBA_PORTSPEED_4GBIT;
992                         else if ((FC_JEDEC_ID(vp->rev.biuRev) ==
993                                   CENTAUR_2G_JEDEC_ID)
994                                  || (FC_JEDEC_ID(vp->rev.biuRev) ==
995                                      PEGASUS_JEDEC_ID)
996                                  || (FC_JEDEC_ID(vp->rev.biuRev) ==
997                                      THOR_JEDEC_ID))
998                                 ae->un.SupportSpeed = HBA_PORTSPEED_2GBIT;
999                         else
1000                                 ae->un.SupportSpeed = HBA_PORTSPEED_1GBIT;
1001                         pab->ab.EntryCnt++;
1002                         size += FOURBYTES + 4;
1003
1004                         /* #3 Port attribute entry */
1005                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1006                         ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1007                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1008                         switch(phba->fc_linkspeed) {
1009                                 case LA_1GHZ_LINK:
1010                                         ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1011                                 break;
1012                                 case LA_2GHZ_LINK:
1013                                         ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1014                                 break;
1015                                 case LA_4GHZ_LINK:
1016                                         ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1017                                 break;
1018                                 default:
1019                                         ae->un.PortSpeed =
1020                                                 HBA_PORTSPEED_UNKNOWN;
1021                                 break;
1022                         }
1023                         pab->ab.EntryCnt++;
1024                         size += FOURBYTES + 4;
1025
1026                         /* #4 Port attribute entry */
1027                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1028                         ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1029                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1030                         hsp = (struct serv_parm *) & phba->fc_sparam;
1031                         ae->un.MaxFrameSize =
1032                             (((uint32_t) hsp->cmn.
1033                               bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1034                             bbRcvSizeLsb;
1035                         pab->ab.EntryCnt++;
1036                         size += FOURBYTES + 4;
1037
1038                         /* #5 Port attribute entry */
1039                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1040                         ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1041                         strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1042                         len = strlen((char *)ae->un.OsDeviceName);
1043                         len += (len & 3) ? (4 - (len & 3)) : 4;
1044                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1045                         pab->ab.EntryCnt++;
1046                         size += FOURBYTES + len;
1047
1048                         if (phba->cfg_fdmi_on == 2) {
1049                                 /* #6 Port attribute entry */
1050                                 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1051                                                           size);
1052                                 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1053                                 sprintf(ae->un.HostName, "%s",
1054                                         system_utsname.nodename);
1055                                 len = strlen(ae->un.HostName);
1056                                 len += (len & 3) ? (4 - (len & 3)) : 4;
1057                                 ae->ad.bits.AttrLen =
1058                                     be16_to_cpu(FOURBYTES + len);
1059                                 pab->ab.EntryCnt++;
1060                                 size += FOURBYTES + len;
1061                         }
1062
1063                         pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1064                         /* Total size */
1065                         size = GID_REQUEST_SZ - 4 + size;
1066                 }
1067                 break;
1068
1069         case SLI_MGMT_DHBA:
1070                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1071                 CtReq->CommandResponse.bits.Size = 0;
1072                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1073                 memcpy((uint8_t *) & pe->PortName,
1074                        (uint8_t *) & phba->fc_sparam.portName,
1075                        sizeof (struct lpfc_name));
1076                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1077                 break;
1078
1079         case SLI_MGMT_DPRT:
1080                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1081                 CtReq->CommandResponse.bits.Size = 0;
1082                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1083                 memcpy((uint8_t *) & pe->PortName,
1084                        (uint8_t *) & phba->fc_sparam.portName,
1085                        sizeof (struct lpfc_name));
1086                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1087                 break;
1088         }
1089
1090         bpl = (struct ulp_bde64 *) bmp->virt;
1091         bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1092         bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1093         bpl->tus.f.bdeFlags = 0;
1094         bpl->tus.f.bdeSize = size;
1095         bpl->tus.w = le32_to_cpu(bpl->tus.w);
1096
1097         cmpl = lpfc_cmpl_ct_cmd_fdmi;
1098
1099         if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1100                 return 0;
1101
1102         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1103 fdmi_cmd_free_bmp:
1104         kfree(bmp);
1105 fdmi_cmd_free_mpvirt:
1106         lpfc_mbuf_free(phba, mp->virt, mp->phys);
1107 fdmi_cmd_free_mp:
1108         kfree(mp);
1109 fdmi_cmd_exit:
1110         /* Issue FDMI request failed */
1111         lpfc_printf_log(phba,
1112                         KERN_INFO,
1113                         LOG_DISCOVERY,
1114                         "%d:0244 Issue FDMI request failed Data: x%x\n",
1115                         phba->brd_no,
1116                         cmdcode);
1117         return 1;
1118 }
1119
1120 void
1121 lpfc_fdmi_tmo(unsigned long ptr)
1122 {
1123         struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1124         unsigned long iflag;
1125
1126         spin_lock_irqsave(phba->host->host_lock, iflag);
1127         if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1128                 phba->work_hba_events |= WORKER_FDMI_TMO;
1129                 if (phba->work_wait)
1130                         wake_up(phba->work_wait);
1131         }
1132         spin_unlock_irqrestore(phba->host->host_lock,iflag);
1133 }
1134
1135 void
1136 lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1137 {
1138         struct lpfc_nodelist *ndlp;
1139
1140         spin_lock_irq(phba->host->host_lock);
1141         if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1142                 spin_unlock_irq(phba->host->host_lock);
1143                 return;
1144         }
1145         ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1146         if (ndlp) {
1147                 if (system_utsname.nodename[0] != '\0') {
1148                         lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1149                 } else {
1150                         mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1151                 }
1152         }
1153         spin_unlock_irq(phba->host->host_lock);
1154         return;
1155 }
1156
1157
1158 void
1159 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1160 {
1161         struct lpfc_sli *psli = &phba->sli;
1162         lpfc_vpd_t *vp = &phba->vpd;
1163         uint32_t b1, b2, b3, b4, i, rev;
1164         char c;
1165         uint32_t *ptr, str[4];
1166         uint8_t *fwname;
1167
1168         if (vp->rev.rBit) {
1169                 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1170                         rev = vp->rev.sli2FwRev;
1171                 else
1172                         rev = vp->rev.sli1FwRev;
1173
1174                 b1 = (rev & 0x0000f000) >> 12;
1175                 b2 = (rev & 0x00000f00) >> 8;
1176                 b3 = (rev & 0x000000c0) >> 6;
1177                 b4 = (rev & 0x00000030) >> 4;
1178
1179                 switch (b4) {
1180                 case 0:
1181                         c = 'N';
1182                         break;
1183                 case 1:
1184                         c = 'A';
1185                         break;
1186                 case 2:
1187                         c = 'B';
1188                         break;
1189                 default:
1190                         c = 0;
1191                         break;
1192                 }
1193                 b4 = (rev & 0x0000000f);
1194
1195                 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1196                         fwname = vp->rev.sli2FwName;
1197                 else
1198                         fwname = vp->rev.sli1FwName;
1199
1200                 for (i = 0; i < 16; i++)
1201                         if (fwname[i] == 0x20)
1202                                 fwname[i] = 0;
1203
1204                 ptr = (uint32_t*)fwname;
1205
1206                 for (i = 0; i < 3; i++)
1207                         str[i] = be32_to_cpu(*ptr++);
1208
1209                 if (c == 0) {
1210                         if (flag)
1211                                 sprintf(fwrevision, "%d.%d%d (%s)",
1212                                         b1, b2, b3, (char *)str);
1213                         else
1214                                 sprintf(fwrevision, "%d.%d%d", b1,
1215                                         b2, b3);
1216                 } else {
1217                         if (flag)
1218                                 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1219                                         b1, b2, b3, c,
1220                                         b4, (char *)str);
1221                         else
1222                                 sprintf(fwrevision, "%d.%d%d%c%d",
1223                                         b1, b2, b3, c, b4);
1224                 }
1225         } else {
1226                 rev = vp->rev.smFwRev;
1227
1228                 b1 = (rev & 0xff000000) >> 24;
1229                 b2 = (rev & 0x00f00000) >> 20;
1230                 b3 = (rev & 0x000f0000) >> 16;
1231                 c  = (rev & 0x0000ff00) >> 8;
1232                 b4 = (rev & 0x000000ff);
1233
1234                 if (flag)
1235                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1236                                 b2, b3, c, b4);
1237                 else
1238                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1239                                 b2, b3, c, b4);
1240         }
1241         return;
1242 }