Merge mulgrave-w:git/scsi-misc-2.6
[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         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);
140                 }
141                 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
142                 kfree(pmbuf);
143         }
144         return;
145 }
146
147 static void
148 lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
149 {
150         struct lpfc_dmabuf *mlast, *next_mlast;
151
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);
156         }
157         lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
158         kfree(mlist);
159         return;
160 }
161
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)
165 {
166         struct lpfc_dmabuf *mlist = NULL;
167         struct lpfc_dmabuf *mp;
168         int cnt, i = 0;
169
170         /* We get chucks of FCELSSIZE */
171         cnt = size > FCELSSIZE ? FCELSSIZE: size;
172
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;
180                 }
181
182                 INIT_LIST_HEAD(&mp->list);
183
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));
188
189                 if (!mp->virt) {
190                         kfree(mp);
191                         lpfc_free_ct_rsp(phba, mlist);
192                         return NULL;
193                 }
194
195                 /* Queue it to a linked list */
196                 if (!mlist)
197                         mlist = mp;
198                 else
199                         list_add_tail(&mp->list, &mlist->list);
200
201                 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
202                 /* build buffer ptr list for IOCB */
203                 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
204                 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
205                 bpl->tus.f.bdeSize = (uint16_t) cnt;
206                 bpl->tus.w = le32_to_cpu(bpl->tus.w);
207                 bpl++;
208
209                 i++;
210                 size -= cnt;
211         }
212
213         *entries = i;
214         return mlist;
215 }
216
217 static int
218 lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
219              struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
220              void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
221                      struct lpfc_iocbq *),
222              struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
223              uint32_t tmo)
224 {
225
226         struct lpfc_sli *psli = &phba->sli;
227         struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
228         IOCB_t *icmd;
229         struct lpfc_iocbq *geniocb;
230
231         /* Allocate buffer for  command iocb */
232         spin_lock_irq(phba->host->host_lock);
233         geniocb = lpfc_sli_get_iocbq(phba);
234         spin_unlock_irq(phba->host->host_lock);
235
236         if (geniocb == NULL)
237                 return 1;
238
239         icmd = &geniocb->iocb;
240         icmd->un.genreq64.bdl.ulpIoTag32 = 0;
241         icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
242         icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
243         icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
244         icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
245
246         if (usr_flg)
247                 geniocb->context3 = NULL;
248         else
249                 geniocb->context3 = (uint8_t *) bmp;
250
251         /* Save for completion so we can release these resources */
252         geniocb->context1 = (uint8_t *) inp;
253         geniocb->context2 = (uint8_t *) outp;
254
255         /* Fill in payload, bp points to frame payload */
256         icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
257
258         /* Fill in rest of iocb */
259         icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
260         icmd->un.genreq64.w5.hcsw.Dfctl = 0;
261         icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
262         icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
263
264         if (!tmo) {
265                  /* FC spec states we need 3 * ratov for CT requests */
266                 tmo = (3 * phba->fc_ratov);
267         }
268         icmd->ulpTimeout = tmo;
269         icmd->ulpBdeCount = 1;
270         icmd->ulpLe = 1;
271         icmd->ulpClass = CLASS3;
272         icmd->ulpContext = ndlp->nlp_rpi;
273
274         /* Issue GEN REQ IOCB for NPORT <did> */
275         lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
276                         "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
277                         "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
278                         icmd->ulpIoTag, phba->hba_state);
279         geniocb->iocb_cmpl = cmpl;
280         geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
281         spin_lock_irq(phba->host->host_lock);
282         if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
283                 lpfc_sli_release_iocbq(phba, geniocb);
284                 spin_unlock_irq(phba->host->host_lock);
285                 return 1;
286         }
287         spin_unlock_irq(phba->host->host_lock);
288
289         return 0;
290 }
291
292 static int
293 lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
294             struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
295             void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
296                           struct lpfc_iocbq *),
297             uint32_t rsp_size)
298 {
299         struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
300         struct lpfc_dmabuf *outmp;
301         int cnt = 0, status;
302         int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
303                 CommandResponse.bits.CmdRsp;
304
305         bpl++;                  /* Skip past ct request */
306
307         /* Put buffer(s) for ct rsp in bpl */
308         outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
309         if (!outmp)
310                 return -ENOMEM;
311
312         status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
313                               cnt+1, 0);
314         if (status) {
315                 lpfc_free_ct_rsp(phba, outmp);
316                 return -ENOMEM;
317         }
318         return 0;
319 }
320
321 static int
322 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
323 {
324         struct lpfc_sli_ct_request *Response =
325                 (struct lpfc_sli_ct_request *) mp->virt;
326         struct lpfc_nodelist *ndlp = NULL;
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;
333
334         lpfc_set_disctmo(phba);
335
336         Cnt = Size  > FCELSSIZE ? FCELSSIZE : Size;
337
338         list_add_tail(&head, &mp->list);
339         list_for_each_entry_safe(mp, next_mp, &head, list) {
340                 mlast = mp;
341
342                 Size -= Cnt;
343
344                 if (!ctptr)
345                         ctptr = (uint32_t *) mlast->virt;
346                 else
347                         Cnt -= 16;      /* subtract length of CT header */
348
349                 /* Loop through entire NameServer list of DIDs */
350                 while (Cnt) {
351
352                         /* Get next DID from NameServer List */
353                         CTentry = *ctptr++;
354                         Did = ((be32_to_cpu(CTentry)) & Mask_DID);
355
356                         ndlp = NULL;
357                         if (Did != phba->fc_myDID) {
358                                 /* Check for rscn processing or not */
359                                 ndlp = lpfc_setup_disc_node(phba, Did);
360                         }
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);
382                         }
383
384                         if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
385                                 goto nsout1;
386                         Cnt -= sizeof (uint32_t);
387                 }
388                 ctptr = NULL;
389
390         }
391
392 nsout1:
393         list_del(&head);
394
395         /*
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.
399          */
400         if (phba->hba_state == LPFC_HBA_READY) {
401                 lpfc_els_flush_rscn(phba);
402                 spin_lock_irq(phba->host->host_lock);
403                 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
404                 spin_unlock_irq(phba->host->host_lock);
405         }
406         return 0;
407 }
408
409
410
411
412 static void
413 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
414                         struct lpfc_iocbq * rspiocb)
415 {
416         IOCB_t *irsp;
417         struct lpfc_sli *psli;
418         struct lpfc_dmabuf *bmp;
419         struct lpfc_dmabuf *inp;
420         struct lpfc_dmabuf *outp;
421         struct lpfc_nodelist *ndlp;
422         struct lpfc_sli_ct_request *CTrsp;
423
424         psli = &phba->sli;
425         /* we pass cmdiocb to state machine which needs rspiocb as well */
426         cmdiocb->context_un.rsp_iocb = rspiocb;
427
428         inp = (struct lpfc_dmabuf *) cmdiocb->context1;
429         outp = (struct lpfc_dmabuf *) cmdiocb->context2;
430         bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
431
432         irsp = &rspiocb->iocb;
433         if (irsp->ulpStatus) {
434                 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
435                         ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
436                          (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
437                         goto out;
438                 }
439
440                 /* Check for retry */
441                 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
442                         phba->fc_ns_retry++;
443                         /* CT command is being retried */
444                         ndlp =
445                             lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
446                                               NameServer_DID);
447                         if (ndlp) {
448                                 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
449                                     0) {
450                                         goto out;
451                                 }
452                         }
453                 }
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);
489                 }
490         }
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;
503 }
504
505 static void
506 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
507                         struct lpfc_iocbq * rspiocb)
508 {
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;
515
516         psli = &phba->sli;
517         /* we pass cmdiocb to state machine which needs rspiocb as well */
518         cmdiocb->context_un.rsp_iocb = rspiocb;
519
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;
524
525         CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
526
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);
532
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;
542 }
543
544 static void
545 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
546                         struct lpfc_iocbq * rspiocb)
547 {
548         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
549         return;
550 }
551
552 static void
553 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
554                          struct lpfc_iocbq * rspiocb)
555 {
556         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
557         return;
558 }
559
560 void
561 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
562 {
563         char fwrev[16];
564
565         lpfc_decode_firmware_rev(phba, fwrev, 0);
566
567         sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
568                 fwrev, lpfc_release_version);
569         return;
570 }
571
572 /*
573  * lpfc_ns_cmd
574  * Description:
575  *    Issue Cmd to NameServer
576  *       SLI_CTNS_GID_FT
577  *       LI_CTNS_RFT_ID
578  */
579 int
580 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
581 {
582         struct lpfc_dmabuf *mp, *bmp;
583         struct lpfc_sli_ct_request *CtReq;
584         struct ulp_bde64 *bpl;
585         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
586                       struct lpfc_iocbq *) = NULL;
587         uint32_t rsp_size = 1024;
588
589         /* fill in BDEs for command */
590         /* Allocate buffer for command payload */
591         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
592         if (!mp)
593                 goto ns_cmd_exit;
594
595         INIT_LIST_HEAD(&mp->list);
596         mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
597         if (!mp->virt)
598                 goto ns_cmd_free_mp;
599
600         /* Allocate buffer for Buffer ptr list */
601         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
602         if (!bmp)
603                 goto ns_cmd_free_mpvirt;
604
605         INIT_LIST_HEAD(&bmp->list);
606         bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
607         if (!bmp->virt)
608                 goto ns_cmd_free_bmp;
609
610         /* NameServer Req */
611         lpfc_printf_log(phba,
612                         KERN_INFO,
613                         LOG_DISCOVERY,
614                         "%d:0236 NameServer Req Data: x%x x%x x%x\n",
615                         phba->brd_no, cmdcode, phba->fc_flag,
616                         phba->fc_rscn_id_cnt);
617
618         bpl = (struct ulp_bde64 *) bmp->virt;
619         memset(bpl, 0, sizeof(struct ulp_bde64));
620         bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
621         bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
622         bpl->tus.f.bdeFlags = 0;
623         if (cmdcode == SLI_CTNS_GID_FT)
624                 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
625         else if (cmdcode == SLI_CTNS_RFT_ID)
626                 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
627         else if (cmdcode == SLI_CTNS_RNN_ID)
628                 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
629         else if (cmdcode == SLI_CTNS_RSNN_NN)
630                 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
631         else
632                 bpl->tus.f.bdeSize = 0;
633         bpl->tus.w = le32_to_cpu(bpl->tus.w);
634
635         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
636         memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
637         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
638         CtReq->RevisionId.bits.InId = 0;
639         CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
640         CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
641         CtReq->CommandResponse.bits.Size = 0;
642         switch (cmdcode) {
643         case SLI_CTNS_GID_FT:
644                 CtReq->CommandResponse.bits.CmdRsp =
645                     be16_to_cpu(SLI_CTNS_GID_FT);
646                 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
647                 if (phba->hba_state < LPFC_HBA_READY)
648                         phba->hba_state = LPFC_NS_QRY;
649                 lpfc_set_disctmo(phba);
650                 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
651                 rsp_size = FC_MAX_NS_RSP;
652                 break;
653
654         case SLI_CTNS_RFT_ID:
655                 CtReq->CommandResponse.bits.CmdRsp =
656                     be16_to_cpu(SLI_CTNS_RFT_ID);
657                 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
658                 CtReq->un.rft.fcpReg = 1;
659                 cmpl = lpfc_cmpl_ct_cmd_rft_id;
660                 break;
661
662         case SLI_CTNS_RNN_ID:
663                 CtReq->CommandResponse.bits.CmdRsp =
664                     be16_to_cpu(SLI_CTNS_RNN_ID);
665                 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
666                 memcpy(CtReq->un.rnn.wwnn,  &phba->fc_nodename,
667                        sizeof (struct lpfc_name));
668                 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
669                 break;
670
671         case SLI_CTNS_RSNN_NN:
672                 CtReq->CommandResponse.bits.CmdRsp =
673                     be16_to_cpu(SLI_CTNS_RSNN_NN);
674                 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
675                        sizeof (struct lpfc_name));
676                 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
677                 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
678                 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
679                 break;
680         }
681
682         if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
683                 /* On success, The cmpl function will free the buffers */
684                 return 0;
685
686         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
687 ns_cmd_free_bmp:
688         kfree(bmp);
689 ns_cmd_free_mpvirt:
690         lpfc_mbuf_free(phba, mp->virt, mp->phys);
691 ns_cmd_free_mp:
692         kfree(mp);
693 ns_cmd_exit:
694         return 1;
695 }
696
697 static void
698 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
699                       struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
700 {
701         struct lpfc_dmabuf *bmp = cmdiocb->context3;
702         struct lpfc_dmabuf *inp = cmdiocb->context1;
703         struct lpfc_dmabuf *outp = cmdiocb->context2;
704         struct lpfc_sli_ct_request *CTrsp = outp->virt;
705         struct lpfc_sli_ct_request *CTcmd = inp->virt;
706         struct lpfc_nodelist *ndlp;
707         uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
708         uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
709
710         ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
711         if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
712                 /* FDMI rsp failed */
713                 lpfc_printf_log(phba,
714                                 KERN_INFO,
715                                 LOG_DISCOVERY,
716                                 "%d:0220 FDMI rsp failed Data: x%x\n",
717                                 phba->brd_no,
718                                be16_to_cpu(fdmi_cmd));
719         }
720
721         switch (be16_to_cpu(fdmi_cmd)) {
722         case SLI_MGMT_RHBA:
723                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
724                 break;
725
726         case SLI_MGMT_RPA:
727                 break;
728
729         case SLI_MGMT_DHBA:
730                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
731                 break;
732
733         case SLI_MGMT_DPRT:
734                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
735                 break;
736         }
737
738         lpfc_free_ct_rsp(phba, outp);
739         lpfc_mbuf_free(phba, inp->virt, inp->phys);
740         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
741         kfree(inp);
742         kfree(bmp);
743         spin_lock_irq(phba->host->host_lock);
744         lpfc_sli_release_iocbq(phba, cmdiocb);
745         spin_unlock_irq(phba->host->host_lock);
746         return;
747 }
748 int
749 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
750 {
751         struct lpfc_dmabuf *mp, *bmp;
752         struct lpfc_sli_ct_request *CtReq;
753         struct ulp_bde64 *bpl;
754         uint32_t size;
755         REG_HBA *rh;
756         PORT_ENTRY *pe;
757         REG_PORT_ATTRIBUTE *pab;
758         ATTRIBUTE_BLOCK *ab;
759         ATTRIBUTE_ENTRY *ae;
760         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
761                       struct lpfc_iocbq *);
762
763
764         /* fill in BDEs for command */
765         /* Allocate buffer for command payload */
766         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
767         if (!mp)
768                 goto fdmi_cmd_exit;
769
770         mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
771         if (!mp->virt)
772                 goto fdmi_cmd_free_mp;
773
774         /* Allocate buffer for Buffer ptr list */
775         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
776         if (!bmp)
777                 goto fdmi_cmd_free_mpvirt;
778
779         bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
780         if (!bmp->virt)
781                 goto fdmi_cmd_free_bmp;
782
783         INIT_LIST_HEAD(&mp->list);
784         INIT_LIST_HEAD(&bmp->list);
785
786         /* FDMI request */
787         lpfc_printf_log(phba,
788                         KERN_INFO,
789                         LOG_DISCOVERY,
790                         "%d:0218 FDMI Request Data: x%x x%x x%x\n",
791                         phba->brd_no,
792                        phba->fc_flag, phba->hba_state, cmdcode);
793
794         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
795
796         memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
797         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
798         CtReq->RevisionId.bits.InId = 0;
799
800         CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
801         CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
802         size = 0;
803
804         switch (cmdcode) {
805         case SLI_MGMT_RHBA:
806                 {
807                         lpfc_vpd_t *vp = &phba->vpd;
808                         uint32_t i, j, incr;
809                         int len;
810
811                         CtReq->CommandResponse.bits.CmdRsp =
812                             be16_to_cpu(SLI_MGMT_RHBA);
813                         CtReq->CommandResponse.bits.Size = 0;
814                         rh = (REG_HBA *) & CtReq->un.PortID;
815                         memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
816                                sizeof (struct lpfc_name));
817                         /* One entry (port) per adapter */
818                         rh->rpl.EntryCnt = be32_to_cpu(1);
819                         memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
820                                sizeof (struct lpfc_name));
821
822                         /* point to the HBA attribute block */
823                         size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
824                         ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
825                         ab->EntryCnt = 0;
826
827                         /* Point to the beginning of the first HBA attribute
828                            entry */
829                         /* #1 HBA attribute entry */
830                         size += FOURBYTES;
831                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
832                         ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
833                         ae->ad.bits.AttrLen =  be16_to_cpu(FOURBYTES
834                                                 + sizeof (struct lpfc_name));
835                         memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
836                                sizeof (struct lpfc_name));
837                         ab->EntryCnt++;
838                         size += FOURBYTES + sizeof (struct lpfc_name);
839
840                         /* #2 HBA attribute entry */
841                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
842                         ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
843                         strcpy(ae->un.Manufacturer, "Emulex Corporation");
844                         len = strlen(ae->un.Manufacturer);
845                         len += (len & 3) ? (4 - (len & 3)) : 4;
846                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
847                         ab->EntryCnt++;
848                         size += FOURBYTES + len;
849
850                         /* #3 HBA attribute entry */
851                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
852                         ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
853                         strcpy(ae->un.SerialNumber, phba->SerialNumber);
854                         len = strlen(ae->un.SerialNumber);
855                         len += (len & 3) ? (4 - (len & 3)) : 4;
856                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
857                         ab->EntryCnt++;
858                         size += FOURBYTES + len;
859
860                         /* #4 HBA attribute entry */
861                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
862                         ae->ad.bits.AttrType = be16_to_cpu(MODEL);
863                         strcpy(ae->un.Model, phba->ModelName);
864                         len = strlen(ae->un.Model);
865                         len += (len & 3) ? (4 - (len & 3)) : 4;
866                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
867                         ab->EntryCnt++;
868                         size += FOURBYTES + len;
869
870                         /* #5 HBA attribute entry */
871                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
872                         ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
873                         strcpy(ae->un.ModelDescription, phba->ModelDesc);
874                         len = strlen(ae->un.ModelDescription);
875                         len += (len & 3) ? (4 - (len & 3)) : 4;
876                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
877                         ab->EntryCnt++;
878                         size += FOURBYTES + len;
879
880                         /* #6 HBA attribute entry */
881                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
882                         ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
883                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
884                         /* Convert JEDEC ID to ascii for hardware version */
885                         incr = vp->rev.biuRev;
886                         for (i = 0; i < 8; i++) {
887                                 j = (incr & 0xf);
888                                 if (j <= 9)
889                                         ae->un.HardwareVersion[7 - i] =
890                                             (char)((uint8_t) 0x30 +
891                                                    (uint8_t) j);
892                                 else
893                                         ae->un.HardwareVersion[7 - i] =
894                                             (char)((uint8_t) 0x61 +
895                                                    (uint8_t) (j - 10));
896                                 incr = (incr >> 4);
897                         }
898                         ab->EntryCnt++;
899                         size += FOURBYTES + 8;
900
901                         /* #7 HBA attribute entry */
902                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
903                         ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
904                         strcpy(ae->un.DriverVersion, lpfc_release_version);
905                         len = strlen(ae->un.DriverVersion);
906                         len += (len & 3) ? (4 - (len & 3)) : 4;
907                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
908                         ab->EntryCnt++;
909                         size += FOURBYTES + len;
910
911                         /* #8 HBA attribute entry */
912                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
913                         ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
914                         strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
915                         len = strlen(ae->un.OptionROMVersion);
916                         len += (len & 3) ? (4 - (len & 3)) : 4;
917                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
918                         ab->EntryCnt++;
919                         size += FOURBYTES + len;
920
921                         /* #9 HBA attribute entry */
922                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
923                         ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
924                         lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
925                                 1);
926                         len = strlen(ae->un.FirmwareVersion);
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;
931
932                         /* #10 HBA attribute entry */
933                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
934                         ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
935                         sprintf(ae->un.OsNameVersion, "%s %s %s",
936                                 system_utsname.sysname, system_utsname.release,
937                                 system_utsname.version);
938                         len = strlen(ae->un.OsNameVersion);
939                         len += (len & 3) ? (4 - (len & 3)) : 4;
940                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
941                         ab->EntryCnt++;
942                         size += FOURBYTES + len;
943
944                         /* #11 HBA attribute entry */
945                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
946                         ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
947                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
948                         ae->un.MaxCTPayloadLen = (65 * 4096);
949                         ab->EntryCnt++;
950                         size += FOURBYTES + 4;
951
952                         ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
953                         /* Total size */
954                         size = GID_REQUEST_SZ - 4 + size;
955                 }
956                 break;
957
958         case SLI_MGMT_RPA:
959                 {
960                         lpfc_vpd_t *vp;
961                         struct serv_parm *hsp;
962                         int len;
963
964                         vp = &phba->vpd;
965
966                         CtReq->CommandResponse.bits.CmdRsp =
967                             be16_to_cpu(SLI_MGMT_RPA);
968                         CtReq->CommandResponse.bits.Size = 0;
969                         pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
970                         size = sizeof (struct lpfc_name) + FOURBYTES;
971                         memcpy((uint8_t *) & pab->PortName,
972                                (uint8_t *) & phba->fc_sparam.portName,
973                                sizeof (struct lpfc_name));
974                         pab->ab.EntryCnt = 0;
975
976                         /* #1 Port attribute entry */
977                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
978                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
979                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
980                         ae->un.SupportFC4Types[2] = 1;
981                         ae->un.SupportFC4Types[7] = 1;
982                         pab->ab.EntryCnt++;
983                         size += FOURBYTES + 32;
984
985                         /* #2 Port attribute entry */
986                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
987                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
988                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
989
990                         ae->un.SupportSpeed = 0;
991                         if (phba->lmt & LMT_10Gb)
992                                 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
993                         if (phba->lmt & LMT_8Gb)
994                                 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
995                         if (phba->lmt & LMT_4Gb)
996                                 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
997                         if (phba->lmt & LMT_2Gb)
998                                 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
999                         if (phba->lmt & LMT_1Gb)
1000                                 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1001
1002                         pab->ab.EntryCnt++;
1003                         size += FOURBYTES + 4;
1004
1005                         /* #3 Port attribute entry */
1006                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1007                         ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1008                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1009                         switch(phba->fc_linkspeed) {
1010                                 case LA_1GHZ_LINK:
1011                                         ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1012                                 break;
1013                                 case LA_2GHZ_LINK:
1014                                         ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1015                                 break;
1016                                 case LA_4GHZ_LINK:
1017                                         ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1018                                 break;
1019                                 default:
1020                                         ae->un.PortSpeed =
1021                                                 HBA_PORTSPEED_UNKNOWN;
1022                                 break;
1023                         }
1024                         pab->ab.EntryCnt++;
1025                         size += FOURBYTES + 4;
1026
1027                         /* #4 Port attribute entry */
1028                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1029                         ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1030                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1031                         hsp = (struct serv_parm *) & phba->fc_sparam;
1032                         ae->un.MaxFrameSize =
1033                             (((uint32_t) hsp->cmn.
1034                               bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1035                             bbRcvSizeLsb;
1036                         pab->ab.EntryCnt++;
1037                         size += FOURBYTES + 4;
1038
1039                         /* #5 Port attribute entry */
1040                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1041                         ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1042                         strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1043                         len = strlen((char *)ae->un.OsDeviceName);
1044                         len += (len & 3) ? (4 - (len & 3)) : 4;
1045                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1046                         pab->ab.EntryCnt++;
1047                         size += FOURBYTES + len;
1048
1049                         if (phba->cfg_fdmi_on == 2) {
1050                                 /* #6 Port attribute entry */
1051                                 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1052                                                           size);
1053                                 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1054                                 sprintf(ae->un.HostName, "%s",
1055                                         system_utsname.nodename);
1056                                 len = strlen(ae->un.HostName);
1057                                 len += (len & 3) ? (4 - (len & 3)) : 4;
1058                                 ae->ad.bits.AttrLen =
1059                                     be16_to_cpu(FOURBYTES + len);
1060                                 pab->ab.EntryCnt++;
1061                                 size += FOURBYTES + len;
1062                         }
1063
1064                         pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1065                         /* Total size */
1066                         size = GID_REQUEST_SZ - 4 + size;
1067                 }
1068                 break;
1069
1070         case SLI_MGMT_DHBA:
1071                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1072                 CtReq->CommandResponse.bits.Size = 0;
1073                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1074                 memcpy((uint8_t *) & pe->PortName,
1075                        (uint8_t *) & phba->fc_sparam.portName,
1076                        sizeof (struct lpfc_name));
1077                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1078                 break;
1079
1080         case SLI_MGMT_DPRT:
1081                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1082                 CtReq->CommandResponse.bits.Size = 0;
1083                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1084                 memcpy((uint8_t *) & pe->PortName,
1085                        (uint8_t *) & phba->fc_sparam.portName,
1086                        sizeof (struct lpfc_name));
1087                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1088                 break;
1089         }
1090
1091         bpl = (struct ulp_bde64 *) bmp->virt;
1092         bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1093         bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1094         bpl->tus.f.bdeFlags = 0;
1095         bpl->tus.f.bdeSize = size;
1096         bpl->tus.w = le32_to_cpu(bpl->tus.w);
1097
1098         cmpl = lpfc_cmpl_ct_cmd_fdmi;
1099
1100         if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1101                 return 0;
1102
1103         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1104 fdmi_cmd_free_bmp:
1105         kfree(bmp);
1106 fdmi_cmd_free_mpvirt:
1107         lpfc_mbuf_free(phba, mp->virt, mp->phys);
1108 fdmi_cmd_free_mp:
1109         kfree(mp);
1110 fdmi_cmd_exit:
1111         /* Issue FDMI request failed */
1112         lpfc_printf_log(phba,
1113                         KERN_INFO,
1114                         LOG_DISCOVERY,
1115                         "%d:0244 Issue FDMI request failed Data: x%x\n",
1116                         phba->brd_no,
1117                         cmdcode);
1118         return 1;
1119 }
1120
1121 void
1122 lpfc_fdmi_tmo(unsigned long ptr)
1123 {
1124         struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1125         unsigned long iflag;
1126
1127         spin_lock_irqsave(phba->host->host_lock, iflag);
1128         if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1129                 phba->work_hba_events |= WORKER_FDMI_TMO;
1130                 if (phba->work_wait)
1131                         wake_up(phba->work_wait);
1132         }
1133         spin_unlock_irqrestore(phba->host->host_lock,iflag);
1134 }
1135
1136 void
1137 lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1138 {
1139         struct lpfc_nodelist *ndlp;
1140
1141         ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1142         if (ndlp) {
1143                 if (system_utsname.nodename[0] != '\0') {
1144                         lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1145                 } else {
1146                         mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1147                 }
1148         }
1149         return;
1150 }
1151
1152
1153 void
1154 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1155 {
1156         struct lpfc_sli *psli = &phba->sli;
1157         lpfc_vpd_t *vp = &phba->vpd;
1158         uint32_t b1, b2, b3, b4, i, rev;
1159         char c;
1160         uint32_t *ptr, str[4];
1161         uint8_t *fwname;
1162
1163         if (vp->rev.rBit) {
1164                 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1165                         rev = vp->rev.sli2FwRev;
1166                 else
1167                         rev = vp->rev.sli1FwRev;
1168
1169                 b1 = (rev & 0x0000f000) >> 12;
1170                 b2 = (rev & 0x00000f00) >> 8;
1171                 b3 = (rev & 0x000000c0) >> 6;
1172                 b4 = (rev & 0x00000030) >> 4;
1173
1174                 switch (b4) {
1175                 case 0:
1176                         c = 'N';
1177                         break;
1178                 case 1:
1179                         c = 'A';
1180                         break;
1181                 case 2:
1182                         c = 'B';
1183                         break;
1184                 default:
1185                         c = 0;
1186                         break;
1187                 }
1188                 b4 = (rev & 0x0000000f);
1189
1190                 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1191                         fwname = vp->rev.sli2FwName;
1192                 else
1193                         fwname = vp->rev.sli1FwName;
1194
1195                 for (i = 0; i < 16; i++)
1196                         if (fwname[i] == 0x20)
1197                                 fwname[i] = 0;
1198
1199                 ptr = (uint32_t*)fwname;
1200
1201                 for (i = 0; i < 3; i++)
1202                         str[i] = be32_to_cpu(*ptr++);
1203
1204                 if (c == 0) {
1205                         if (flag)
1206                                 sprintf(fwrevision, "%d.%d%d (%s)",
1207                                         b1, b2, b3, (char *)str);
1208                         else
1209                                 sprintf(fwrevision, "%d.%d%d", b1,
1210                                         b2, b3);
1211                 } else {
1212                         if (flag)
1213                                 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1214                                         b1, b2, b3, c,
1215                                         b4, (char *)str);
1216                         else
1217                                 sprintf(fwrevision, "%d.%d%d%c%d",
1218                                         b1, b2, b3, c, b4);
1219                 }
1220         } else {
1221                 rev = vp->rev.smFwRev;
1222
1223                 b1 = (rev & 0xff000000) >> 24;
1224                 b2 = (rev & 0x00f00000) >> 20;
1225                 b3 = (rev & 0x000f0000) >> 16;
1226                 c  = (rev & 0x0000ff00) >> 8;
1227                 b4 = (rev & 0x000000ff);
1228
1229                 if (flag)
1230                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1231                                 b2, b3, c, b4);
1232                 else
1233                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1234                                 b2, b3, c, b4);
1235         }
1236         return;
1237 }