This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / scsi / lpfc / lpfc_ct.c
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Enterprise Fibre Channel Host Bus Adapters.                     *
4  * Refer to the README file included with this package for         *
5  * driver version and adapter support.                             *
6  * Copyright (C) 2004 Emulex Corporation.                          *
7  * www.emulex.com                                                  *
8  *                                                                 *
9  * This program is free software; you can redistribute it and/or   *
10  * modify it under the terms of the GNU General Public License     *
11  * as published by the Free Software Foundation; either version 2  *
12  * of the License, or (at your option) any later version.          *
13  *                                                                 *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of  *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
17  * GNU General Public License for more details, a copy of which    *
18  * can be found in the file COPYING included with this package.    *
19  *******************************************************************/
20
21 /*
22  * $Id: lpfc_ct.c 1.143 2004/11/17 14:50:38EST sf_support Exp  $
23  *
24  * Fibre Channel SCSI LAN Device Driver CT support
25  */
26
27 #include <linux/version.h>
28 #include <linux/blkdev.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/utsname.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include "lpfc_sli.h"
36 #include "lpfc_disc.h"
37 #include "lpfc_scsi.h"
38 #include "lpfc.h"
39 #include "lpfc_crtn.h"
40 #include "lpfc_hw.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_mem.h"
43 #include "lpfc_version.h"
44
45
46 #define HBA_PORTSPEED_UNKNOWN               0   /* Unknown - transceiver 
47                                                  * incapable of reporting */
48 #define HBA_PORTSPEED_1GBIT                 1   /* 1 GBit/sec */
49 #define HBA_PORTSPEED_2GBIT                 2   /* 2 GBit/sec */
50 #define HBA_PORTSPEED_4GBIT                 8   /* 4 GBit/sec */
51 #define HBA_PORTSPEED_8GBIT                16   /* 8 GBit/sec */
52 #define HBA_PORTSPEED_10GBIT                4   /* 10 GBit/sec */
53 #define HBA_PORTSPEED_NOT_NEGOTIATED        5   /* Speed not established */
54
55 #define FOURBYTES       4
56
57
58 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
59
60 /*
61  * lpfc_ct_unsol_event
62  */
63 void
64 lpfc_ct_unsol_event(struct lpfc_hba * phba,
65                     struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
66 {
67
68         struct lpfc_iocbq *next_piocbq;
69         struct lpfc_dmabuf *pmbuf = NULL;
70         struct lpfc_dmabuf *matp, *next_matp;
71         uint32_t ctx = 0, count = 0;
72         IOCB_t *icmd = &piocbq->iocb;
73         int i, status, go_exit = 0;
74         struct list_head head;
75
76         if (icmd->ulpStatus)
77                 return;
78
79         list_add_tail(&head, &piocbq->list);
80         list_for_each_entry_safe(piocbq, next_piocbq, &head, list) {
81                 icmd = &piocbq->iocb;
82                 if (ctx == 0)
83                         ctx = (uint32_t) (icmd->ulpContext);
84                 if (icmd->ulpStatus) {
85                         if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
86                                 ((icmd->un.ulpWord[4] & 0xff)
87                                  == IOERR_RCV_BUFFER_WAITING)) {
88                                 phba->fc_stat.NoRcvBuf++;
89                                 lpfc_post_buffer(phba, pring, 0, 1);
90                         }
91                         go_exit = 1;
92                         goto ct_unsol_event_exit_piocbq;
93                 }
94
95                 if (icmd->ulpBdeCount == 0)
96                         continue;
97
98                 for (i = 0; i < icmd->ulpBdeCount; i++) {
99                         matp = lpfc_sli_ringpostbuf_get(phba, pring,
100                                                         getPaddr(icmd->un.
101                                                                  cont64[i].
102                                                                  addrHigh,
103                                                                  icmd->un.
104                                                                  cont64[i].
105                                                                  addrLow));
106                         if (!matp) {
107                                 /* Insert lpfc log message here */
108                                 go_exit = 1;
109                                 goto ct_unsol_event_exit_piocbq;
110                         }
111
112                         /* Typically for Unsolicited CT requests */
113                         if (!pmbuf) {
114                                 pmbuf = matp;
115                                 INIT_LIST_HEAD(&pmbuf->list);
116                         } else
117                                 list_add_tail(&matp->list, &pmbuf->list);
118
119                         count += icmd->un.cont64[i].tus.f.bdeSize;
120                 }
121
122                 lpfc_post_buffer(phba, pring, i, 1);
123                 icmd->ulpBdeCount = 0;
124         }
125 ct_unsol_event_exit_piocbq:
126         list_del(&head);
127         /*
128          * if not early-exiting and there is pmbuf,
129          * then do  FC_REG_CT_EVENT for libdfc
130          */
131         if (!go_exit  &&  pmbuf) {
132                 status = lpfc_put_event(phba, FC_REG_CT_EVENT, ctx,
133                                        (void *)pmbuf, count, 0);
134                 if (status)
135                         /* Need to free IOCB buffer ? */
136                         return;
137         }
138         if (pmbuf) {
139                 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
140                         lpfc_mbuf_free(phba, matp->virt, matp->phys);
141                         list_del(&matp->list);
142                         kfree(matp);
143                 }
144                 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
145                 kfree(pmbuf);
146         }
147         return;
148 }
149
150 static void
151 lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
152 {
153         struct lpfc_dmabuf *mlast, *next_mlast;
154
155         list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
156                 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
157                 list_del(&mlast->list);
158                 kfree(mlast);
159         }
160         lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
161         kfree(mlist);
162         return;
163 }
164
165 static struct lpfc_dmabuf *
166 lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
167                   uint32_t size, int *entries)
168 {
169         struct lpfc_dmabuf *mlist = NULL;
170         struct lpfc_dmabuf *mp;
171         int cnt, i = 0;
172
173         /* We get chucks of FCELSSIZE */
174         cnt = size > FCELSSIZE ? FCELSSIZE: size;
175
176         while (size) {
177                 /* Allocate buffer for rsp payload */
178                 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_ATOMIC);
179                 if (!mp) {
180                         if (mlist)
181                                 lpfc_free_ct_rsp(phba, mlist);
182                         return NULL;
183                 }
184
185                 INIT_LIST_HEAD(&mp->list);
186
187                 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
188                         mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
189                 else
190                         mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
191
192                 if (!mp->virt) {
193                         kfree(mp);
194                         lpfc_free_ct_rsp(phba, mlist);
195                         return NULL;
196                 }
197
198                 /* Queue it to a linked list */
199                 if (!mlist)
200                         mlist = mp;
201                 else
202                         list_add_tail(&mp->list, &mlist->list);
203
204                 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
205                 /* build buffer ptr list for IOCB */
206                 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
207                 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
208                 bpl->tus.f.bdeSize = (uint16_t) cnt;
209                 bpl->tus.w = le32_to_cpu(bpl->tus.w);
210                 bpl++;
211
212                 i++;
213                 size -= cnt;
214         }
215
216         *entries = i;
217         return mlist;
218 }
219
220 static int
221 lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
222              struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
223              void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
224                      struct lpfc_iocbq *),
225              struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
226              uint32_t tmo)
227 {
228
229         struct lpfc_sli *psli = &phba->sli;
230         struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
231         IOCB_t *icmd;
232         struct lpfc_iocbq *geniocb;
233
234         /* Allocate buffer for  command iocb */
235         geniocb = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC);
236         if (!geniocb) {
237                 return 1;
238         }
239         memset(geniocb, 0, sizeof (struct lpfc_iocbq));
240         icmd = &geniocb->iocb;
241
242         icmd->un.genreq64.bdl.ulpIoTag32 = 0;
243         icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
244         icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
245         icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
246         icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
247
248         if (usr_flg)
249                 geniocb->context3 = NULL;
250         else
251                 geniocb->context3 = (uint8_t *) bmp;
252
253         /* Save for completion so we can release these resources */
254         geniocb->context1 = (uint8_t *) inp;
255         geniocb->context2 = (uint8_t *) outp;
256
257         /* Fill in payload, bp points to frame payload */
258         icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
259
260         pci_dma_sync_single_for_device(phba->pcidev, bmp->phys,
261                 LPFC_BPL_SIZE, PCI_DMA_TODEVICE);
262
263         icmd->ulpIoTag = lpfc_sli_next_iotag(phba, pring);
264
265         /* Fill in rest of iocb */
266         icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
267         icmd->un.genreq64.w5.hcsw.Dfctl = 0;
268         icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
269         icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
270
271         if (!tmo)
272                 tmo = (2 * phba->fc_ratov) + 1;
273         icmd->ulpTimeout = tmo;
274         icmd->ulpBdeCount = 1;
275         icmd->ulpLe = 1;
276         icmd->ulpClass = CLASS3;
277         icmd->ulpContext = ndlp->nlp_rpi;
278
279         /* Issue GEN REQ IOCB for NPORT <did> */
280         lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
281                         "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
282                         "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
283                         icmd->ulpIoTag, phba->hba_state);
284         geniocb->iocb_cmpl = cmpl;
285         geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
286         if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
287                 mempool_free( geniocb, phba->iocb_mem_pool);
288                 return 1;
289         }
290
291         return 0;
292 }
293
294 static int
295 lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
296             struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
297             void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
298                           struct lpfc_iocbq *),
299             uint32_t rsp_size)
300 {
301         struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
302         struct lpfc_dmabuf *outmp;
303         int cnt = 0, status;
304         int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
305                 CommandResponse.bits.CmdRsp;
306
307         bpl++;                  /* Skip past ct request */
308
309         /* Put buffer(s) for ct rsp in bpl */
310         outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
311         if (!outmp)
312                 return -ENOMEM;
313
314         status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
315                               cnt+1, 0);
316         if (status) {
317                 lpfc_free_ct_rsp(phba, outmp);
318                 return -ENOMEM;
319         }
320         return 0;
321 }
322
323 static int
324 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
325 {
326         struct lpfc_sli_ct_request *Response =
327                 (struct lpfc_sli_ct_request *) mp->virt;
328         struct lpfc_nodelist *ndlp = NULL;
329         struct lpfc_dmabuf *mlast, *next_mp;
330         uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
331         uint32_t Did;
332         uint32_t CTentry;
333         int Cnt;
334         struct list_head head;
335
336         lpfc_set_disctmo(phba);
337
338         Cnt = Size  > FCELSSIZE ? FCELSSIZE : Size;
339
340         list_add_tail(&head, &mp->list);
341         list_for_each_entry_safe(mp, next_mp, &head, list) {
342                 mlast = mp;
343                 pci_dma_sync_single_for_cpu(phba->pcidev, mp->phys,
344                         LPFC_BPL_SIZE, PCI_DMA_FROMDEVICE);
345
346                 Size -= Cnt;
347
348                 if (!ctptr)
349                         ctptr = (uint32_t *) mlast->virt;
350                 else
351                         Cnt -= 16;      /* subtract length of CT header */
352
353                 /* Loop through entire NameServer list of DIDs */
354                 while (Cnt) {
355
356                         /* Get next DID from NameServer List */
357                         CTentry = *ctptr++;
358                         Did = ((be32_to_cpu(CTentry)) & Mask_DID);
359
360                         ndlp = NULL;
361                         if (Did != phba->fc_myDID) {
362                                 /* Check for rscn processing or not */
363                                 ndlp = lpfc_setup_disc_node(phba, Did);
364                         }
365                         /* Mark all node table entries that are in the
366                            Nameserver */
367                         if (ndlp) {
368                                 /* NameServer Rsp */
369                                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
370                                                 "%d:0238 Process x%x NameServer"
371                                                 " Rsp Data: x%x x%x x%x\n",
372                                                 phba->brd_no,
373                                                 Did, ndlp->nlp_flag,
374                                                 phba->fc_flag,
375                                                 phba->fc_rscn_id_cnt);
376                         } else {
377                                 /* NameServer Rsp */
378                                 lpfc_printf_log(phba,
379                                                 KERN_INFO,
380                                                 LOG_DISCOVERY,
381                                                 "%d:0239 Skip x%x NameServer "
382                                                 "Rsp Data: x%x x%x x%x\n",
383                                                 phba->brd_no,
384                                                 Did, Size, phba->fc_flag,
385                                                 phba->fc_rscn_id_cnt);
386                         }
387
388                         if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
389                                 goto nsout1;
390                         Cnt -= sizeof (uint32_t);
391                 }
392                 ctptr = NULL;
393
394         }
395
396 nsout1:
397         list_del(&head);
398
399         /* Here we are finished in the case RSCN */
400         if (phba->hba_state == LPFC_HBA_READY) {
401                 lpfc_els_flush_rscn(phba);
402                 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
403         }
404         return 0;
405 }
406
407
408
409
410 static void
411 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
412                         struct lpfc_iocbq * rspiocb)
413 {
414         IOCB_t *irsp;
415         struct lpfc_sli *psli;
416         struct lpfc_dmabuf *bmp;
417         struct lpfc_dmabuf *inp;
418         struct lpfc_dmabuf *outp;
419         struct lpfc_nodelist *ndlp;
420         struct lpfc_sli_ct_request *CTrsp;
421
422         psli = &phba->sli;
423         /* we pass cmdiocb to state machine which needs rspiocb as well */
424         cmdiocb->context_un.rsp_iocb = rspiocb;
425
426         inp = (struct lpfc_dmabuf *) cmdiocb->context1;
427         outp = (struct lpfc_dmabuf *) cmdiocb->context2;
428         bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
429
430         irsp = &rspiocb->iocb;
431         if (irsp->ulpStatus) {
432                 if((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
433                         ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
434                          (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
435                         goto out;
436                 }
437
438                 /* Check for retry */
439                 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
440                         phba->fc_ns_retry++;
441                         /* CT command is being retried */
442                         ndlp =
443                             lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
444                                               NameServer_DID);
445                         if (ndlp) {
446                                 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
447                                     0) {
448                                         goto out;
449                                 }
450                         }
451                 }
452         } else {
453                 /* Good status, continue checking */
454                 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
455                 if (CTrsp->CommandResponse.bits.CmdRsp ==
456                     be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
457                         lpfc_ns_rsp(phba, outp,
458                                     (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
459                 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
460                            be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
461                         /* NameServer Rsp Error */
462                         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
463                                         "%d:0240 NameServer Rsp Error "
464                                         "Data: x%x x%x x%x x%x\n",
465                                         phba->brd_no,
466                                         CTrsp->CommandResponse.bits.CmdRsp,
467                                         (uint32_t) CTrsp->ReasonCode,
468                                         (uint32_t) CTrsp->Explanation,
469                                         phba->fc_flag);
470                 } else {
471                         /* NameServer Rsp Error */
472                         lpfc_printf_log(phba,
473                                         KERN_INFO,
474                                         LOG_DISCOVERY,
475                                         "%d:0241 NameServer Rsp Error "
476                                         "Data: x%x x%x x%x x%x\n",
477                                         phba->brd_no,
478                                         CTrsp->CommandResponse.bits.CmdRsp,
479                                         (uint32_t) CTrsp->ReasonCode,
480                                         (uint32_t) CTrsp->Explanation,
481                                         phba->fc_flag);
482                 }
483         }
484         /* Link up / RSCN discovery */
485         lpfc_disc_start(phba);
486 out:
487         lpfc_free_ct_rsp(phba, outp);
488         lpfc_mbuf_free(phba, inp->virt, inp->phys);
489         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
490         kfree(inp);
491         kfree(bmp);
492         mempool_free( cmdiocb, phba->iocb_mem_pool);
493         return;
494 }
495
496 static void
497 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
498                         struct lpfc_iocbq * rspiocb)
499 {
500         struct lpfc_sli *psli;
501         struct lpfc_dmabuf *bmp;
502         struct lpfc_dmabuf *inp;
503         struct lpfc_dmabuf *outp;
504         IOCB_t *irsp;
505         struct lpfc_sli_ct_request *CTrsp;
506
507         psli = &phba->sli;
508         /* we pass cmdiocb to state machine which needs rspiocb as well */
509         cmdiocb->context_un.rsp_iocb = rspiocb;
510
511         inp = (struct lpfc_dmabuf *) cmdiocb->context1;
512         outp = (struct lpfc_dmabuf *) cmdiocb->context2;
513         bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
514         irsp = &rspiocb->iocb;
515
516         CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
517
518         /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
519         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
520                         "%d:0209 RFT request completes ulpStatus x%x "
521                         "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
522                         CTrsp->CommandResponse.bits.CmdRsp);
523
524         lpfc_free_ct_rsp(phba, outp);
525         lpfc_mbuf_free(phba, inp->virt, inp->phys);
526         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
527         kfree(inp);
528         kfree(bmp);
529         mempool_free( cmdiocb, phba->iocb_mem_pool);
530         return;
531 }
532
533 static void
534 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
535                         struct lpfc_iocbq * rspiocb)
536 {
537         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
538         return;
539 }
540
541 static void
542 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
543                          struct lpfc_iocbq * rspiocb)
544 {
545         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
546         return;
547 }
548
549 void
550 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
551 {
552         uint8_t buf[16];
553         char fwrev[16];
554
555         lpfc_decode_firmware_rev(phba, fwrev, 0);
556         lpfc_get_hba_model_desc(phba, buf, NULL);
557         sprintf(symbp, "Emulex %s FV%s DV%s", buf, fwrev, lpfc_release_version);
558 }
559
560 /*
561  * lpfc_ns_cmd
562  * Description:
563  *    Issue Cmd to NameServer
564  *       SLI_CTNS_GID_FT
565  *       LI_CTNS_RFT_ID
566  */
567 int
568 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
569 {
570         struct lpfc_dmabuf *mp, *bmp;
571         struct lpfc_sli_ct_request *CtReq;
572         struct ulp_bde64 *bpl;
573         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
574                       struct lpfc_iocbq *) = NULL;
575         uint32_t rsp_size = 1024;
576
577         /* fill in BDEs for command */
578         /* Allocate buffer for command payload */
579         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
580         if (!mp)
581                 goto ns_cmd_exit;
582
583         INIT_LIST_HEAD(&mp->list);
584         mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
585         if (!mp->virt)
586                 goto ns_cmd_free_mp;
587
588         /* Allocate buffer for Buffer ptr list */
589         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
590         if (!bmp)
591                 goto ns_cmd_free_mpvirt;
592
593         INIT_LIST_HEAD(&bmp->list);
594         bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
595         if (!bmp->virt)
596                 goto ns_cmd_free_bmp;
597
598         /* NameServer Req */
599         lpfc_printf_log(phba,
600                         KERN_INFO,
601                         LOG_DISCOVERY,
602                         "%d:0236 NameServer Req Data: x%x x%x x%x\n",
603                         phba->brd_no, cmdcode, phba->fc_flag,
604                         phba->fc_rscn_id_cnt);
605
606         bpl = (struct ulp_bde64 *) bmp->virt;
607         memset(bpl, 0, sizeof(struct ulp_bde64));
608         bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
609         bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
610         bpl->tus.f.bdeFlags = 0;
611         if (cmdcode == SLI_CTNS_GID_FT)
612                 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
613         else if (cmdcode == SLI_CTNS_RFT_ID)
614                 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
615         else if (cmdcode == SLI_CTNS_RNN_ID)
616                 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
617         else if (cmdcode == SLI_CTNS_RSNN_NN)
618                 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
619         else
620                 bpl->tus.f.bdeSize = 0;
621         bpl->tus.w = le32_to_cpu(bpl->tus.w);
622
623         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
624         memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
625         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
626         CtReq->RevisionId.bits.InId = 0;
627         CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
628         CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
629         CtReq->CommandResponse.bits.Size = 0;
630         switch (cmdcode) {
631         case SLI_CTNS_GID_FT:
632                 CtReq->CommandResponse.bits.CmdRsp =
633                     be16_to_cpu(SLI_CTNS_GID_FT);
634                 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
635                 if (phba->hba_state < LPFC_HBA_READY)
636                         phba->hba_state = LPFC_NS_QRY;
637                 lpfc_set_disctmo(phba);
638                 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
639                 rsp_size = FC_MAX_NS_RSP;
640                 break;
641
642         case SLI_CTNS_RFT_ID:
643                 CtReq->CommandResponse.bits.CmdRsp =
644                     be16_to_cpu(SLI_CTNS_RFT_ID);
645                 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
646                 CtReq->un.rft.fcpReg = 1;
647                 cmpl = lpfc_cmpl_ct_cmd_rft_id;
648                 break;
649
650         case SLI_CTNS_RNN_ID:
651                 CtReq->CommandResponse.bits.CmdRsp =
652                     be16_to_cpu(SLI_CTNS_RNN_ID);
653                 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
654                 memcpy(CtReq->un.rnn.wwnn,  &phba->fc_nodename,
655                        sizeof (struct lpfc_name));
656                 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
657                 break;
658
659         case SLI_CTNS_RSNN_NN:
660                 CtReq->CommandResponse.bits.CmdRsp =
661                     be16_to_cpu(SLI_CTNS_RSNN_NN);
662                 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
663                        sizeof (struct lpfc_name));
664                 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
665                 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
666                 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
667                 break;
668         }
669
670         if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
671                 /* On success, The cmpl function will free the buffers */
672                 return 0;
673
674         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
675 ns_cmd_free_bmp:
676         kfree(bmp);
677 ns_cmd_free_mpvirt:
678         lpfc_mbuf_free(phba, mp->virt, mp->phys);
679 ns_cmd_free_mp:
680         kfree(mp);
681 ns_cmd_exit:
682         return 1;
683 }
684
685 static void
686 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
687                       struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
688 {
689         struct lpfc_dmabuf *bmp = cmdiocb->context3;
690         struct lpfc_dmabuf *inp = cmdiocb->context1;
691         struct lpfc_dmabuf *outp = cmdiocb->context2;
692         struct lpfc_sli_ct_request *CTrsp = outp->virt;
693         struct lpfc_sli_ct_request *CTcmd = inp->virt;
694         struct lpfc_nodelist *ndlp;
695         uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
696         uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
697
698         ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
699         if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
700                 /* FDMI rsp failed */
701                 lpfc_printf_log(phba,
702                                 KERN_INFO,
703                                 LOG_DISCOVERY,
704                                 "%d:0220 FDMI rsp failed Data: x%x\n",
705                                 phba->brd_no,
706                                be16_to_cpu(fdmi_cmd));
707         }
708
709         switch (be16_to_cpu(fdmi_cmd)) {
710         case SLI_MGMT_RHBA:
711                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
712                 break;
713
714         case SLI_MGMT_RPA:
715                 break;
716
717         case SLI_MGMT_DHBA:
718                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
719                 break;
720
721         case SLI_MGMT_DPRT:
722                 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
723                 break;
724         }
725
726         lpfc_free_ct_rsp(phba, outp);
727         lpfc_mbuf_free(phba, inp->virt, inp->phys);
728         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
729         kfree(inp);
730         kfree(bmp);
731         mempool_free(cmdiocb, phba->iocb_mem_pool);
732         return;
733 }
734 int
735 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
736 {
737         struct lpfc_dmabuf *mp, *bmp;
738         struct lpfc_sli_ct_request *CtReq;
739         struct ulp_bde64 *bpl;
740         uint32_t size;
741         REG_HBA *rh;
742         PORT_ENTRY *pe;
743         REG_PORT_ATTRIBUTE *pab;
744         ATTRIBUTE_BLOCK *ab;
745         ATTRIBUTE_ENTRY *ae;
746         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
747                       struct lpfc_iocbq *);
748
749
750         /* fill in BDEs for command */
751         /* Allocate buffer for command payload */
752         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
753         if (!mp)
754                 goto fdmi_cmd_exit;
755
756         mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
757         if (!mp->virt)
758                 goto fdmi_cmd_free_mp;
759
760         /* Allocate buffer for Buffer ptr list */
761         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
762         if (!bmp)
763                 goto fdmi_cmd_free_mpvirt;
764
765         bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
766         if (!bmp->virt)
767                 goto fdmi_cmd_free_bmp;
768
769         INIT_LIST_HEAD(&mp->list);
770         INIT_LIST_HEAD(&bmp->list);
771
772         /* FDMI request */
773         lpfc_printf_log(phba,
774                         KERN_INFO,
775                         LOG_DISCOVERY,
776                         "%d:0218 FDMI Request Data: x%x x%x x%x\n",
777                         phba->brd_no,
778                        phba->fc_flag, phba->hba_state, cmdcode);
779
780         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
781
782         memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
783         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
784         CtReq->RevisionId.bits.InId = 0;
785
786         CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
787         CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
788         size = 0;
789
790         switch (cmdcode) {
791         case SLI_MGMT_RHBA:
792                 {
793                         lpfc_vpd_t *vp = &phba->vpd;
794                         uint32_t i, j, incr;
795                         int len;
796
797                         CtReq->CommandResponse.bits.CmdRsp =
798                             be16_to_cpu(SLI_MGMT_RHBA);
799                         CtReq->CommandResponse.bits.Size = 0;
800                         rh = (REG_HBA *) & CtReq->un.PortID;
801                         memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
802                                sizeof (struct lpfc_name));
803                         /* One entry (port) per adapter */
804                         rh->rpl.EntryCnt = be32_to_cpu(1);
805                         memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
806                                sizeof (struct lpfc_name));
807
808                         /* point to the HBA attribute block */
809                         size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
810                         ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
811                         ab->EntryCnt = 0;
812
813                         /* Point to the beginning of the first HBA attribute
814                            entry */
815                         /* #1 HBA attribute entry */
816                         size += FOURBYTES;
817                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
818                         ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
819                         ae->ad.bits.AttrLen =  be16_to_cpu(FOURBYTES
820                                                 + sizeof (struct lpfc_name));
821                         memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
822                                sizeof (struct lpfc_name));
823                         ab->EntryCnt++;
824                         size += FOURBYTES + sizeof (struct lpfc_name);
825
826                         /* #2 HBA attribute entry */
827                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
828                         ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
829                         strcpy(ae->un.Manufacturer, "Emulex Corporation");
830                         len = strlen(ae->un.Manufacturer);
831                         len += (len & 3) ? (4 - (len & 3)) : 4;
832                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
833                         ab->EntryCnt++;
834                         size += FOURBYTES + len;
835
836                         /* #3 HBA attribute entry */
837                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
838                         ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
839                         strcpy(ae->un.SerialNumber, phba->SerialNumber);
840                         len = strlen(ae->un.SerialNumber);
841                         len += (len & 3) ? (4 - (len & 3)) : 4;
842                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
843                         ab->EntryCnt++;
844                         size += FOURBYTES + len;
845
846                         /* #4 HBA attribute entry */
847                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
848                         ae->ad.bits.AttrType = be16_to_cpu(MODEL);
849                         lpfc_get_hba_model_desc(phba, ae->un.Model, NULL);
850                         len = strlen(ae->un.Model);
851                         len += (len & 3) ? (4 - (len & 3)) : 4;
852                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
853                         ab->EntryCnt++;
854                         size += FOURBYTES + len;
855
856                         /* #5 HBA attribute entry */
857                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
858                         ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
859                         lpfc_get_hba_model_desc(phba, NULL,
860                                  ae->un.ModelDescription);
861                         len = strlen(ae->un.ModelDescription);
862                         len += (len & 3) ? (4 - (len & 3)) : 4;
863                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
864                         ab->EntryCnt++;
865                         size += FOURBYTES + len;
866
867                         /* #6 HBA attribute entry */
868                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
869                         ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
870                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
871                         /* Convert JEDEC ID to ascii for hardware version */
872                         incr = vp->rev.biuRev;
873                         for (i = 0; i < 8; i++) {
874                                 j = (incr & 0xf);
875                                 if (j <= 9)
876                                         ae->un.HardwareVersion[7 - i] =
877                                             (char)((uint8_t) 0x30 +
878                                                    (uint8_t) j);
879                                 else
880                                         ae->un.HardwareVersion[7 - i] =
881                                             (char)((uint8_t) 0x61 +
882                                                    (uint8_t) (j - 10));
883                                 incr = (incr >> 4);
884                         }
885                         ab->EntryCnt++;
886                         size += FOURBYTES + 8;
887
888                         /* #7 HBA attribute entry */
889                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
890                         ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
891                         strcpy(ae->un.DriverVersion, lpfc_release_version);
892                         len = strlen(ae->un.DriverVersion);
893                         len += (len & 3) ? (4 - (len & 3)) : 4;
894                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
895                         ab->EntryCnt++;
896                         size += FOURBYTES + len;
897
898                         /* #8 HBA attribute entry */
899                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
900                         ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
901                         strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
902                         len = strlen(ae->un.OptionROMVersion);
903                         len += (len & 3) ? (4 - (len & 3)) : 4;
904                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
905                         ab->EntryCnt++;
906                         size += FOURBYTES + len;
907
908                         /* #9 HBA attribute entry */
909                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
910                         ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
911                         lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
912                                 1);
913                         len = strlen(ae->un.FirmwareVersion);
914                         len += (len & 3) ? (4 - (len & 3)) : 4;
915                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
916                         ab->EntryCnt++;
917                         size += FOURBYTES + len;
918
919                         /* #10 HBA attribute entry */
920                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
921                         ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
922                         sprintf(ae->un.OsNameVersion, "%s %s %s",
923                                 system_utsname.sysname, system_utsname.release,
924                                 system_utsname.version);
925                         len = strlen(ae->un.OsNameVersion);
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                         /* #11 HBA attribute entry */
932                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
933                         ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
934                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
935                         ae->un.MaxCTPayloadLen = (65 * 4096);
936                         ab->EntryCnt++;
937                         size += FOURBYTES + 4;
938
939                         ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
940                         /* Total size */
941                         size = GID_REQUEST_SZ - 4 + size;
942                 }
943                 break;
944
945         case SLI_MGMT_RPA:
946                 {
947                         lpfc_vpd_t *vp;
948                         struct serv_parm *hsp;
949                         int len;
950
951                         vp = &phba->vpd;
952
953                         CtReq->CommandResponse.bits.CmdRsp =
954                             be16_to_cpu(SLI_MGMT_RPA);
955                         CtReq->CommandResponse.bits.Size = 0;
956                         pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
957                         size = sizeof (struct lpfc_name) + FOURBYTES;
958                         memcpy((uint8_t *) & pab->PortName,
959                                (uint8_t *) & phba->fc_sparam.portName,
960                                sizeof (struct lpfc_name));
961                         pab->ab.EntryCnt = 0;
962
963                         /* #1 Port attribute entry */
964                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
965                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
966                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
967                         ae->un.SupportFC4Types[2] = 1;
968                         ae->un.SupportFC4Types[7] = 1;
969                         pab->ab.EntryCnt++;
970                         size += FOURBYTES + 32;
971
972                         /* #2 Port attribute entry */
973                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
974                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
975                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
976                         if (FC_JEDEC_ID(vp->rev.biuRev) == VIPER_JEDEC_ID)
977                                 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
978                         else if (FC_JEDEC_ID(vp->rev.biuRev) == HELIOS_JEDEC_ID)
979                                 ae->un.SupportSpeed = HBA_PORTSPEED_4GBIT;
980                         else if ((FC_JEDEC_ID(vp->rev.biuRev) ==
981                                   CENTAUR_2G_JEDEC_ID)
982                                  || (FC_JEDEC_ID(vp->rev.biuRev) ==
983                                      PEGASUS_JEDEC_ID)
984                                  || (FC_JEDEC_ID(vp->rev.biuRev) ==
985                                      THOR_JEDEC_ID))
986                                 ae->un.SupportSpeed = HBA_PORTSPEED_2GBIT;
987                         else
988                                 ae->un.SupportSpeed = HBA_PORTSPEED_1GBIT;
989                         pab->ab.EntryCnt++;
990                         size += FOURBYTES + 4;
991
992                         /* #3 Port attribute entry */
993                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
994                         ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
995                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
996                         switch(phba->fc_linkspeed) {
997                                 case LA_1GHZ_LINK:
998                                         ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
999                                 break;
1000                                 case LA_2GHZ_LINK:
1001                                         ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1002                                 break;
1003                                 case LA_4GHZ_LINK:
1004                                         ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1005                                 break;
1006                                 default:
1007                                         ae->un.PortSpeed =
1008                                                 HBA_PORTSPEED_UNKNOWN;
1009                                 break;
1010                         }
1011                         pab->ab.EntryCnt++;
1012                         size += FOURBYTES + 4;
1013
1014                         /* #4 Port attribute entry */
1015                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1016                         ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1017                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1018                         hsp = (struct serv_parm *) & phba->fc_sparam;
1019                         ae->un.MaxFrameSize =
1020                             (((uint32_t) hsp->cmn.
1021                               bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1022                             bbRcvSizeLsb;
1023                         pab->ab.EntryCnt++;
1024                         size += FOURBYTES + 4;
1025
1026                         /* #5 Port attribute entry */
1027                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1028                         ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1029                         strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1030                         len = strlen((char *)ae->un.OsDeviceName);
1031                         len += (len & 3) ? (4 - (len & 3)) : 4;
1032                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1033                         pab->ab.EntryCnt++;
1034                         size += FOURBYTES + len;
1035
1036                         if (phba->cfg_fdmi_on == 2) {
1037                                 /* #6 Port attribute entry */
1038                                 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1039                                                           size);
1040                                 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1041                                 sprintf(ae->un.HostName, "%s",
1042                                         system_utsname.nodename);
1043                                 len = strlen(ae->un.HostName);
1044                                 len += (len & 3) ? (4 - (len & 3)) : 4;
1045                                 ae->ad.bits.AttrLen =
1046                                     be16_to_cpu(FOURBYTES + len);
1047                                 pab->ab.EntryCnt++;
1048                                 size += FOURBYTES + len;
1049                         }
1050
1051                         pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1052                         /* Total size */
1053                         size = GID_REQUEST_SZ - 4 + size;
1054                 }
1055                 break;
1056
1057         case SLI_MGMT_DHBA:
1058                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1059                 CtReq->CommandResponse.bits.Size = 0;
1060                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1061                 memcpy((uint8_t *) & pe->PortName,
1062                        (uint8_t *) & phba->fc_sparam.portName,
1063                        sizeof (struct lpfc_name));
1064                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1065                 break;
1066
1067         case SLI_MGMT_DPRT:
1068                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1069                 CtReq->CommandResponse.bits.Size = 0;
1070                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1071                 memcpy((uint8_t *) & pe->PortName,
1072                        (uint8_t *) & phba->fc_sparam.portName,
1073                        sizeof (struct lpfc_name));
1074                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1075                 break;
1076         }
1077
1078         bpl = (struct ulp_bde64 *) bmp->virt;
1079         bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1080         bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1081         bpl->tus.f.bdeFlags = 0;
1082         bpl->tus.f.bdeSize = size;
1083         bpl->tus.w = le32_to_cpu(bpl->tus.w);
1084
1085         cmpl = lpfc_cmpl_ct_cmd_fdmi;
1086
1087         if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1088                 return 0;
1089
1090         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1091 fdmi_cmd_free_bmp:
1092         kfree(bmp);
1093 fdmi_cmd_free_mpvirt:
1094         lpfc_mbuf_free(phba, mp->virt, mp->phys);
1095 fdmi_cmd_free_mp:
1096         kfree(mp);
1097 fdmi_cmd_exit:
1098         /* Issue FDMI request failed */
1099         lpfc_printf_log(phba,
1100                         KERN_INFO,
1101                         LOG_DISCOVERY,
1102                         "%d:0244 Issue FDMI request failed Data: x%x\n",
1103                         phba->brd_no,
1104                         cmdcode);
1105         return 1;
1106 }
1107
1108
1109 void
1110 lpfc_fdmi_tmo(unsigned long ptr)
1111 {
1112         struct lpfc_hba *phba = (struct lpfc_hba*)ptr;
1113         struct lpfc_nodelist *ndlp;
1114         unsigned long iflag;
1115
1116         spin_lock_irqsave(phba->host->host_lock, iflag);
1117         ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1118         if (ndlp) {
1119                 if (system_utsname.nodename[0] != '\0') {
1120                         lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1121                 } else {
1122                         mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1123                 }
1124         }
1125         spin_unlock_irqrestore(phba->host->host_lock, iflag);
1126         return;
1127 }
1128
1129
1130 void
1131 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1132 {
1133         struct lpfc_sli *psli = &phba->sli;
1134         lpfc_vpd_t *vp = &phba->vpd;
1135         uint32_t b1, b2, b3, b4, i, rev;
1136         char c;
1137         uint32_t *ptr, str[4];
1138         uint8_t *fwname;
1139
1140         if (vp->rev.rBit) {
1141                 if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)
1142                         rev = vp->rev.sli2FwRev;
1143                 else
1144                         rev = vp->rev.sli1FwRev;
1145
1146                 b1 = (rev & 0x0000f000) >> 12;
1147                 b2 = (rev & 0x00000f00) >> 8;
1148                 b3 = (rev & 0x000000c0) >> 6;
1149                 b4 = (rev & 0x00000030) >> 4;
1150
1151                 switch (b4) {
1152                 case 0:
1153                         c = 'N';
1154                         break;
1155                 case 1:
1156                         c = 'A';
1157                         break;
1158                 case 2:
1159                         c = 'B';
1160                         break;
1161                 default:
1162                         c = 0;
1163                         break;
1164                 }
1165                 b4 = (rev & 0x0000000f);
1166
1167                 if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)
1168                         fwname = vp->rev.sli2FwName;
1169                 else
1170                         fwname = vp->rev.sli1FwName;
1171
1172                 for (i = 0; i < 16; i++)
1173                         if(fwname[i] == 0x20)
1174                                 fwname[i] = 0;
1175
1176                 ptr = (uint32_t*)fwname;
1177
1178                 for (i = 0; i < 3; i++)
1179                         str[i] = be32_to_cpu(*ptr++);
1180
1181                 if (c == 0) {
1182                         if (flag)
1183                                 sprintf(fwrevision, "%d.%d%d (%s)",
1184                                         b1, b2, b3, (char *)str);
1185                         else
1186                                 sprintf(fwrevision, "%d.%d%d", b1,
1187                                         b2, b3);
1188                 } else {
1189                         if (flag)
1190                                 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1191                                         b1, b2, b3, c,
1192                                         b4, (char *)str);
1193                         else
1194                                 sprintf(fwrevision, "%d.%d%d%c%d",
1195                                         b1, b2, b3, c, b4);
1196                 }
1197         } else {
1198                 rev = vp->rev.smFwRev;
1199
1200                 b1 = (rev & 0xff000000) >> 24;
1201                 b2 = (rev & 0x00f00000) >> 20;
1202                 b3 = (rev & 0x000f0000) >> 16;
1203                 c  = (rev & 0x0000ff00) >> 8;
1204                 b4 = (rev & 0x000000ff);
1205
1206                 if (flag)
1207                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1208                                 b2, b3, c, b4);
1209                 else
1210                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1211                                 b2, b3, c, b4);
1212         }
1213         return;
1214 }
1215
1216 void
1217 lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
1218 {
1219         lpfc_vpd_t *vp;
1220         uint32_t id;
1221         char str[16];
1222
1223         vp = &phba->vpd;
1224         pci_read_config_dword(phba->pcidev, PCI_VENDOR_ID, &id);
1225
1226         switch ((id >> 16) & 0xffff) {
1227         case PCI_DEVICE_ID_SUPERFLY:
1228                 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
1229                         strcpy(str, "LP7000 1");
1230                 else
1231                         strcpy(str, "LP7000E 1");
1232                 break;
1233         case PCI_DEVICE_ID_DRAGONFLY:
1234                 strcpy(str, "LP8000 1");
1235                 break;
1236         case PCI_DEVICE_ID_CENTAUR:
1237                 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
1238                         strcpy(str, "LP9002 2");
1239                 else
1240                         strcpy(str, "LP9000 1");
1241                 break;
1242         case PCI_DEVICE_ID_RFLY:
1243                 strcpy(str, "LP952 2");
1244                 break;
1245         case PCI_DEVICE_ID_PEGASUS:
1246                 strcpy(str, "LP9802 2");
1247                 break;
1248         case PCI_DEVICE_ID_THOR:
1249                 strcpy(str, "LP10000 2");
1250                 break;
1251         case PCI_DEVICE_ID_VIPER:
1252                 strcpy(str, "LPX1000 10");
1253                 break;
1254         case PCI_DEVICE_ID_PFLY:
1255                 strcpy(str, "LP982 2");
1256                 break;
1257         case PCI_DEVICE_ID_TFLY:
1258                 strcpy(str, "LP1050 2");
1259                 break;
1260         case PCI_DEVICE_ID_HELIOS:
1261                 strcpy(str, "LP11000 4");
1262                 break;
1263         case PCI_DEVICE_ID_BMID:
1264                 strcpy(str, "LP1150 4");
1265                 break;
1266         case PCI_DEVICE_ID_BSMB:
1267                 strcpy(str, "LP111 4");
1268                 break;
1269         case PCI_DEVICE_ID_ZEPHYR:
1270                 strcpy(str, "LP11000e 4");
1271                 break;
1272         case PCI_DEVICE_ID_ZMID:
1273                 strcpy(str, "LP1150e 4");
1274                 break;
1275         case PCI_DEVICE_ID_ZSMB:
1276                 strcpy(str, "LP111e 4");
1277                 break;
1278         case PCI_DEVICE_ID_LP101:
1279                 strcpy(str, "LP101 2");
1280                 break;
1281         }
1282         if (mdp)
1283                 sscanf(str, "%s", mdp);
1284         if (descp)
1285                 sprintf(descp, "Emulex LightPulse %s Gigabit PCI Fibre "
1286                         "Channel Adapter", str);
1287 }
1288