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