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