[SCSI] lpfc 8.2.2 : Error messages and debugfs updates
[safe/jmp/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-2007 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 #include "lpfc_vport.h"
44 #include "lpfc_debugfs.h"
45
46 #define HBA_PORTSPEED_UNKNOWN               0   /* Unknown - transceiver
47                                                  * incapable of reporting */
48 #define HBA_PORTSPEED_1GBIT                 1   /* 1 GBit/sec */
49 #define HBA_PORTSPEED_2GBIT                 2   /* 2 GBit/sec */
50 #define HBA_PORTSPEED_4GBIT                 8   /* 4 GBit/sec */
51 #define HBA_PORTSPEED_8GBIT                16   /* 8 GBit/sec */
52 #define HBA_PORTSPEED_10GBIT                4   /* 10 GBit/sec */
53 #define HBA_PORTSPEED_NOT_NEGOTIATED        5   /* Speed not established */
54
55 #define FOURBYTES       4
56
57
58 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
59
60 /*
61  * lpfc_ct_unsol_event
62  */
63 static void
64 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
65                      struct lpfc_dmabuf *mp, uint32_t size)
66 {
67         if (!mp) {
68                 printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
69                        "piocbq = %p, status = x%x, mp = %p, size = %d\n",
70                        __FUNCTION__, __LINE__,
71                        piocbq, piocbq->iocb.ulpStatus, mp, size);
72         }
73
74         printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
75                "buffer = %p, size = %d, status = x%x\n",
76                __FUNCTION__, __LINE__,
77                piocbq, mp, size,
78                piocbq->iocb.ulpStatus);
79
80 }
81
82 static void
83 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
84                           struct lpfc_dmabuf *mp, uint32_t size)
85 {
86         if (!mp) {
87                 printk(KERN_ERR "%s (%d): Unsolited CT, no "
88                        "HBQ buffer, piocbq = %p, status = x%x\n",
89                        __FUNCTION__, __LINE__,
90                        piocbq, piocbq->iocb.ulpStatus);
91         } else {
92                 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
93                 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
94                        "piocbq = %p, buffer = %p, size = %d, "
95                        "status = x%x\n",
96                        __FUNCTION__, __LINE__,
97                        piocbq, mp, size, piocbq->iocb.ulpStatus);
98         }
99 }
100
101 void
102 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
103                     struct lpfc_iocbq *piocbq)
104 {
105
106         struct lpfc_dmabuf *mp = NULL;
107         IOCB_t *icmd = &piocbq->iocb;
108         int i;
109         struct lpfc_iocbq *iocbq;
110         dma_addr_t paddr;
111         uint32_t size;
112         struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
113         struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
114
115         piocbq->context2 = NULL;
116         piocbq->context3 = NULL;
117
118         if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
119                 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
120         } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
121                 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
122                 /* Not enough posted buffers; Try posting more buffers */
123                 phba->fc_stat.NoRcvBuf++;
124                 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
125                         lpfc_post_buffer(phba, pring, 0, 1);
126                 return;
127         }
128
129         /* If there are no BDEs associated with this IOCB,
130          * there is nothing to do.
131          */
132         if (icmd->ulpBdeCount == 0)
133                 return;
134
135         if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
136                 list_for_each_entry(iocbq, &piocbq->list, list) {
137                         icmd = &iocbq->iocb;
138                         if (icmd->ulpBdeCount == 0) {
139                                 printk(KERN_ERR "%s (%d): Unsolited CT, no "
140                                        "BDE, iocbq = %p, status = x%x\n",
141                                        __FUNCTION__, __LINE__,
142                                        iocbq, iocbq->iocb.ulpStatus);
143                                 continue;
144                         }
145
146                         size  = icmd->un.cont64[0].tus.f.bdeSize;
147                         lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf1, size);
148                         lpfc_in_buf_free(phba, bdeBuf1);
149                         if (icmd->ulpBdeCount == 2) {
150                                 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf2,
151                                                           size);
152                                 lpfc_in_buf_free(phba, bdeBuf2);
153                         }
154                 }
155         } else {
156                 struct lpfc_iocbq  *next;
157
158                 list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
159                         icmd = &iocbq->iocb;
160                         if (icmd->ulpBdeCount == 0) {
161                                 printk(KERN_ERR "%s (%d): Unsolited CT, no "
162                                        "BDE, iocbq = %p, status = x%x\n",
163                                        __FUNCTION__, __LINE__,
164                                        iocbq, iocbq->iocb.ulpStatus);
165                                 continue;
166                         }
167
168                         for (i = 0; i < icmd->ulpBdeCount; i++) {
169                                 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
170                                                  icmd->un.cont64[i].addrLow);
171                                 mp = lpfc_sli_ringpostbuf_get(phba, pring,
172                                                               paddr);
173                                 size = icmd->un.cont64[i].tus.f.bdeSize;
174                                 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
175                                 lpfc_in_buf_free(phba, mp);
176                         }
177                         list_del(&iocbq->list);
178                         lpfc_sli_release_iocbq(phba, iocbq);
179                 }
180         }
181 }
182
183 static void
184 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
185 {
186         struct lpfc_dmabuf *mlast, *next_mlast;
187
188         list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
189                 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
190                 list_del(&mlast->list);
191                 kfree(mlast);
192         }
193         lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
194         kfree(mlist);
195         return;
196 }
197
198 static struct lpfc_dmabuf *
199 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
200                   uint32_t size, int *entries)
201 {
202         struct lpfc_dmabuf *mlist = NULL;
203         struct lpfc_dmabuf *mp;
204         int cnt, i = 0;
205
206         /* We get chucks of FCELSSIZE */
207         cnt = size > FCELSSIZE ? FCELSSIZE: size;
208
209         while (size) {
210                 /* Allocate buffer for rsp payload */
211                 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
212                 if (!mp) {
213                         if (mlist)
214                                 lpfc_free_ct_rsp(phba, mlist);
215                         return NULL;
216                 }
217
218                 INIT_LIST_HEAD(&mp->list);
219
220                 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
221                     cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
222                         mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
223                 else
224                         mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
225
226                 if (!mp->virt) {
227                         kfree(mp);
228                         if (mlist)
229                                 lpfc_free_ct_rsp(phba, mlist);
230                         return NULL;
231                 }
232
233                 /* Queue it to a linked list */
234                 if (!mlist)
235                         mlist = mp;
236                 else
237                         list_add_tail(&mp->list, &mlist->list);
238
239                 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
240                 /* build buffer ptr list for IOCB */
241                 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
242                 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
243                 bpl->tus.f.bdeSize = (uint16_t) cnt;
244                 bpl->tus.w = le32_to_cpu(bpl->tus.w);
245                 bpl++;
246
247                 i++;
248                 size -= cnt;
249         }
250
251         *entries = i;
252         return mlist;
253 }
254
255 int
256 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
257 {
258         struct lpfc_dmabuf *buf_ptr;
259
260         if (ctiocb->context1) {
261                 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
262                 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
263                 kfree(buf_ptr);
264                 ctiocb->context1 = NULL;
265         }
266         if (ctiocb->context2) {
267                 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
268                 ctiocb->context2 = NULL;
269         }
270
271         if (ctiocb->context3) {
272                 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
273                 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
274                 kfree(buf_ptr);
275                 ctiocb->context1 = NULL;
276         }
277         lpfc_sli_release_iocbq(phba, ctiocb);
278         return 0;
279 }
280
281 static int
282 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
283              struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
284              void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
285                      struct lpfc_iocbq *),
286              struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
287              uint32_t tmo, uint8_t retry)
288 {
289         struct lpfc_hba  *phba = vport->phba;
290         struct lpfc_sli  *psli = &phba->sli;
291         struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
292         IOCB_t *icmd;
293         struct lpfc_iocbq *geniocb;
294         int rc;
295
296         /* Allocate buffer for  command iocb */
297         geniocb = lpfc_sli_get_iocbq(phba);
298
299         if (geniocb == NULL)
300                 return 1;
301
302         icmd = &geniocb->iocb;
303         icmd->un.genreq64.bdl.ulpIoTag32 = 0;
304         icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
305         icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
306         icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
307         icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
308
309         if (usr_flg)
310                 geniocb->context3 = NULL;
311         else
312                 geniocb->context3 = (uint8_t *) bmp;
313
314         /* Save for completion so we can release these resources */
315         geniocb->context1 = (uint8_t *) inp;
316         geniocb->context2 = (uint8_t *) outp;
317
318         /* Fill in payload, bp points to frame payload */
319         icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
320
321         /* Fill in rest of iocb */
322         icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
323         icmd->un.genreq64.w5.hcsw.Dfctl = 0;
324         icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
325         icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
326
327         if (!tmo) {
328                  /* FC spec states we need 3 * ratov for CT requests */
329                 tmo = (3 * phba->fc_ratov);
330         }
331         icmd->ulpTimeout = tmo;
332         icmd->ulpBdeCount = 1;
333         icmd->ulpLe = 1;
334         icmd->ulpClass = CLASS3;
335         icmd->ulpContext = ndlp->nlp_rpi;
336
337         if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
338                 /* For GEN_REQUEST64_CR, use the RPI */
339                 icmd->ulpCt_h = 0;
340                 icmd->ulpCt_l = 0;
341         }
342
343         /* Issue GEN REQ IOCB for NPORT <did> */
344         lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
345                         "%d (%d):0119 Issue GEN REQ IOCB to NPORT x%x "
346                         "Data: x%x x%x\n", phba->brd_no, vport->vpi,
347                         ndlp->nlp_DID, icmd->ulpIoTag,
348                         vport->port_state);
349         geniocb->iocb_cmpl = cmpl;
350         geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
351         geniocb->vport = vport;
352         geniocb->retry = retry;
353         rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
354
355         if (rc == IOCB_ERROR) {
356                 lpfc_sli_release_iocbq(phba, geniocb);
357                 return 1;
358         }
359
360         return 0;
361 }
362
363 static int
364 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
365             struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
366             void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
367                           struct lpfc_iocbq *),
368             uint32_t rsp_size, uint8_t retry)
369 {
370         struct lpfc_hba  *phba = vport->phba;
371         struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
372         struct lpfc_dmabuf *outmp;
373         int cnt = 0, status;
374         int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
375                 CommandResponse.bits.CmdRsp;
376
377         bpl++;                  /* Skip past ct request */
378
379         /* Put buffer(s) for ct rsp in bpl */
380         outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
381         if (!outmp)
382                 return -ENOMEM;
383
384         status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
385                               cnt+1, 0, retry);
386         if (status) {
387                 lpfc_free_ct_rsp(phba, outmp);
388                 return -ENOMEM;
389         }
390         return 0;
391 }
392
393 static struct lpfc_vport *
394 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
395
396         struct lpfc_vport *vport_curr;
397
398         list_for_each_entry(vport_curr, &phba->port_list, listentry) {
399                 if ((vport_curr->fc_myDID) &&
400                         (vport_curr->fc_myDID == did))
401                         return vport_curr;
402         }
403
404         return NULL;
405 }
406
407 static int
408 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
409 {
410         struct lpfc_hba  *phba = vport->phba;
411         struct lpfc_sli_ct_request *Response =
412                 (struct lpfc_sli_ct_request *) mp->virt;
413         struct lpfc_nodelist *ndlp = NULL;
414         struct lpfc_dmabuf *mlast, *next_mp;
415         uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
416         uint32_t Did, CTentry;
417         int Cnt;
418         struct list_head head;
419
420         lpfc_set_disctmo(vport);
421         vport->num_disc_nodes = 0;
422
423
424         list_add_tail(&head, &mp->list);
425         list_for_each_entry_safe(mp, next_mp, &head, list) {
426                 mlast = mp;
427
428                 Cnt = Size  > FCELSSIZE ? FCELSSIZE : Size;
429
430                 Size -= Cnt;
431
432                 if (!ctptr) {
433                         ctptr = (uint32_t *) mlast->virt;
434                 } else
435                         Cnt -= 16;      /* subtract length of CT header */
436
437                 /* Loop through entire NameServer list of DIDs */
438                 while (Cnt >= sizeof (uint32_t)) {
439                         /* Get next DID from NameServer List */
440                         CTentry = *ctptr++;
441                         Did = ((be32_to_cpu(CTentry)) & Mask_DID);
442
443                         ndlp = NULL;
444
445                         /*
446                          * Check for rscn processing or not
447                          * To conserve rpi's, filter out addresses for other
448                          * vports on the same physical HBAs.
449                          */
450                         if ((Did != vport->fc_myDID) &&
451                             ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
452                              phba->cfg_peer_port_login)) {
453                                 if ((vport->port_type != LPFC_NPIV_PORT) ||
454                                     (vport->fc_flag & FC_RFF_NOT_SUPPORTED) ||
455                                     (!phba->cfg_vport_restrict_login)) {
456                                         ndlp = lpfc_setup_disc_node(vport, Did);
457                                         if (ndlp) {
458                                                 lpfc_debugfs_disc_trc(vport,
459                                                 LPFC_DISC_TRC_CT,
460                                                 "Parse GID_FTrsp: "
461                                                 "did:x%x flg:x%x x%x",
462                                                 Did, ndlp->nlp_flag,
463                                                 vport->fc_flag);
464
465                                                 lpfc_printf_log(phba, KERN_INFO,
466                                                         LOG_DISCOVERY,
467                                                         "%d (%d):0238 Process "
468                                                         "x%x NameServer Rsp"
469                                                         "Data: x%x x%x x%x\n",
470                                                         phba->brd_no,
471                                                         vport->vpi, Did,
472                                                         ndlp->nlp_flag,
473                                                         vport->fc_flag,
474                                                         vport->fc_rscn_id_cnt);
475                                         } else {
476                                                 lpfc_debugfs_disc_trc(vport,
477                                                 LPFC_DISC_TRC_CT,
478                                                 "Skip1 GID_FTrsp: "
479                                                 "did:x%x flg:x%x cnt:%d",
480                                                 Did, vport->fc_flag,
481                                                 vport->fc_rscn_id_cnt);
482
483                                                 lpfc_printf_log(phba, KERN_INFO,
484                                                         LOG_DISCOVERY,
485                                                         "%d (%d):0239 Skip x%x "
486                                                         "NameServer Rsp Data: "
487                                                         "x%x x%x\n",
488                                                         phba->brd_no,
489                                                         vport->vpi, Did,
490                                                         vport->fc_flag,
491                                                         vport->fc_rscn_id_cnt);
492                                         }
493
494                                 } else {
495                                         if (!(vport->fc_flag & FC_RSCN_MODE) ||
496                                         (lpfc_rscn_payload_check(vport, Did))) {
497                                                 lpfc_debugfs_disc_trc(vport,
498                                                 LPFC_DISC_TRC_CT,
499                                                 "Query GID_FTrsp: "
500                                                 "did:x%x flg:x%x cnt:%d",
501                                                 Did, vport->fc_flag,
502                                                 vport->fc_rscn_id_cnt);
503
504                                                 if (lpfc_ns_cmd(vport,
505                                                         SLI_CTNS_GFF_ID,
506                                                         0, Did) == 0)
507                                                         vport->num_disc_nodes++;
508                                         }
509                                         else {
510                                                 lpfc_debugfs_disc_trc(vport,
511                                                 LPFC_DISC_TRC_CT,
512                                                 "Skip2 GID_FTrsp: "
513                                                 "did:x%x flg:x%x cnt:%d",
514                                                 Did, vport->fc_flag,
515                                                 vport->fc_rscn_id_cnt);
516
517                                                 lpfc_printf_log(phba, KERN_INFO,
518                                                         LOG_DISCOVERY,
519                                                         "%d (%d):0245 Skip x%x "
520                                                         "NameServer Rsp Data: "
521                                                         "x%x x%x\n",
522                                                         phba->brd_no,
523                                                         vport->vpi, Did,
524                                                         vport->fc_flag,
525                                                         vport->fc_rscn_id_cnt);
526                                         }
527                                 }
528                         }
529                         if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
530                                 goto nsout1;
531                         Cnt -= sizeof (uint32_t);
532                 }
533                 ctptr = NULL;
534
535         }
536
537 nsout1:
538         list_del(&head);
539         return 0;
540 }
541
542 static void
543 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
544                         struct lpfc_iocbq *rspiocb)
545 {
546         struct lpfc_vport *vport = cmdiocb->vport;
547         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
548         IOCB_t *irsp;
549         struct lpfc_dmabuf *bmp;
550         struct lpfc_dmabuf *outp;
551         struct lpfc_sli_ct_request *CTrsp;
552         int rc;
553
554         /* we pass cmdiocb to state machine which needs rspiocb as well */
555         cmdiocb->context_un.rsp_iocb = rspiocb;
556
557         outp = (struct lpfc_dmabuf *) cmdiocb->context2;
558         bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
559         irsp = &rspiocb->iocb;
560
561         lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
562                  "GID_FT cmpl:     status:x%x/x%x rtry:%d",
563                 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
564
565         /* Don't bother processing response if vport is being torn down. */
566         if (vport->load_flag & FC_UNLOADING)
567                 goto out;
568
569
570         if (lpfc_els_chk_latt(vport) || lpfc_error_lost_link(irsp)) {
571                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
572                                 "%d (%d):0216 Link event during NS query\n",
573                                 phba->brd_no, vport->vpi);
574                 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
575                 goto out;
576         }
577
578         if (irsp->ulpStatus) {
579                 /* Check for retry */
580                 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
581                         if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
582                                 (irsp->un.ulpWord[4] != IOERR_NO_RESOURCES))
583                                 vport->fc_ns_retry++;
584                         /* CT command is being retried */
585                         rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
586                                          vport->fc_ns_retry, 0);
587                         if (rc == 0)
588                                 goto out;
589                 }
590                 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
591                 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
592                         "%d (%d):0257 GID_FT Query error: 0x%x 0x%x\n",
593                         phba->brd_no, vport->vpi, irsp->ulpStatus,
594                         vport->fc_ns_retry);
595         } else {
596                 /* Good status, continue checking */
597                 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
598                 if (CTrsp->CommandResponse.bits.CmdRsp ==
599                     be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
600                         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
601                                         "%d (%d):0208 NameServer Rsp "
602                                         "Data: x%x\n",
603                                         phba->brd_no, vport->vpi,
604                                         vport->fc_flag);
605                         lpfc_ns_rsp(vport, outp,
606                                     (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
607                 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
608                            be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
609                         /* NameServer Rsp Error */
610                         if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
611                             && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
612                                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
613                                         "%d (%d):0269 No NameServer Entries "
614                                         "Data: x%x x%x x%x x%x\n",
615                                         phba->brd_no, vport->vpi,
616                                         CTrsp->CommandResponse.bits.CmdRsp,
617                                         (uint32_t) CTrsp->ReasonCode,
618                                         (uint32_t) CTrsp->Explanation,
619                                         vport->fc_flag);
620
621                                 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
622                                 "GID_FT no entry  cmd:x%x rsn:x%x exp:x%x",
623                                 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
624                                 (uint32_t) CTrsp->ReasonCode,
625                                 (uint32_t) CTrsp->Explanation);
626                         }
627                         else {
628                                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
629                                         "%d (%d):0240 NameServer Rsp Error "
630                                         "Data: x%x x%x x%x x%x\n",
631                                         phba->brd_no, vport->vpi,
632                                         CTrsp->CommandResponse.bits.CmdRsp,
633                                         (uint32_t) CTrsp->ReasonCode,
634                                         (uint32_t) CTrsp->Explanation,
635                                         vport->fc_flag);
636
637                                 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
638                                 "GID_FT rsp err1  cmd:x%x rsn:x%x exp:x%x",
639                                 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
640                                 (uint32_t) CTrsp->ReasonCode,
641                                 (uint32_t) CTrsp->Explanation);
642                         }
643
644
645                 } else {
646                         /* NameServer Rsp Error */
647                         lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
648                                         "%d (%d):0241 NameServer Rsp Error "
649                                         "Data: x%x x%x x%x x%x\n",
650                                         phba->brd_no, vport->vpi,
651                                         CTrsp->CommandResponse.bits.CmdRsp,
652                                         (uint32_t) CTrsp->ReasonCode,
653                                         (uint32_t) CTrsp->Explanation,
654                                         vport->fc_flag);
655
656                         lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
657                                 "GID_FT rsp err2  cmd:x%x rsn:x%x exp:x%x",
658                                 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
659                                 (uint32_t) CTrsp->ReasonCode,
660                                 (uint32_t) CTrsp->Explanation);
661                 }
662         }
663         /* Link up / RSCN discovery */
664         if (vport->num_disc_nodes == 0) {
665                 /*
666                  * The driver has cycled through all Nports in the RSCN payload.
667                  * Complete the handling by cleaning up and marking the
668                  * current driver state.
669                  */
670                 if (vport->port_state >= LPFC_DISC_AUTH) {
671                         if (vport->fc_flag & FC_RSCN_MODE) {
672                                 lpfc_els_flush_rscn(vport);
673                                 spin_lock_irq(shost->host_lock);
674                                 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
675                                 spin_unlock_irq(shost->host_lock);
676                         }
677                         else
678                                 lpfc_els_flush_rscn(vport);
679                 }
680
681                 lpfc_disc_start(vport);
682         }
683 out:
684         lpfc_ct_free_iocb(phba, cmdiocb);
685         return;
686 }
687
688 void
689 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
690                         struct lpfc_iocbq *rspiocb)
691 {
692         struct lpfc_vport *vport = cmdiocb->vport;
693         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
694         IOCB_t *irsp = &rspiocb->iocb;
695         struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
696         struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
697         struct lpfc_sli_ct_request *CTrsp;
698         int did;
699         uint8_t fbits;
700         struct lpfc_nodelist *ndlp;
701
702         did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
703         did = be32_to_cpu(did);
704
705         lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
706                 "GFF_ID cmpl:     status:x%x/x%x did:x%x",
707                 irsp->ulpStatus, irsp->un.ulpWord[4], did);
708
709         if (irsp->ulpStatus == IOSTAT_SUCCESS) {
710                 /* Good status, continue checking */
711                 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
712                 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
713
714                 if (CTrsp->CommandResponse.bits.CmdRsp ==
715                     be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
716                         if ((fbits & FC4_FEATURE_INIT) &&
717                             !(fbits & FC4_FEATURE_TARGET)) {
718                                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
719                                                 "%d (%d):0270 Skip x%x GFF "
720                                                 "NameServer Rsp Data: (init) "
721                                                 "x%x x%x\n", phba->brd_no,
722                                                 vport->vpi, did, fbits,
723                                                 vport->fc_rscn_id_cnt);
724                                 goto out;
725                         }
726                 }
727         }
728         else {
729                 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
730                                 "%d (%d):0267 NameServer GFF Rsp"
731                                 " x%x Error (%d %d) Data: x%x x%x\n",
732                                 phba->brd_no, vport->vpi, did,
733                                 irsp->ulpStatus, irsp->un.ulpWord[4],
734                                 vport->fc_flag, vport->fc_rscn_id_cnt)
735         }
736
737         /* This is a target port, unregistered port, or the GFF_ID failed */
738         ndlp = lpfc_setup_disc_node(vport, did);
739         if (ndlp) {
740                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
741                                 "%d (%d):0242 Process x%x GFF "
742                                 "NameServer Rsp Data: x%x x%x x%x\n",
743                                 phba->brd_no, vport->vpi,
744                                 did, ndlp->nlp_flag, vport->fc_flag,
745                                 vport->fc_rscn_id_cnt);
746         } else {
747                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
748                                 "%d (%d):0243 Skip x%x GFF "
749                                 "NameServer Rsp Data: x%x x%x\n",
750                                 phba->brd_no, vport->vpi, did,
751                                 vport->fc_flag, vport->fc_rscn_id_cnt);
752         }
753 out:
754         /* Link up / RSCN discovery */
755         if (vport->num_disc_nodes)
756                 vport->num_disc_nodes--;
757         if (vport->num_disc_nodes == 0) {
758                 /*
759                  * The driver has cycled through all Nports in the RSCN payload.
760                  * Complete the handling by cleaning up and marking the
761                  * current driver state.
762                  */
763                 if (vport->port_state >= LPFC_DISC_AUTH) {
764                         if (vport->fc_flag & FC_RSCN_MODE) {
765                                 lpfc_els_flush_rscn(vport);
766                                 spin_lock_irq(shost->host_lock);
767                                 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
768                                 spin_unlock_irq(shost->host_lock);
769                         }
770                         else
771                                 lpfc_els_flush_rscn(vport);
772                 }
773                 lpfc_disc_start(vport);
774         }
775         lpfc_ct_free_iocb(phba, cmdiocb);
776         return;
777 }
778
779
780 static void
781 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
782                         struct lpfc_iocbq *rspiocb)
783 {
784         struct lpfc_vport *vport = cmdiocb->vport;
785         struct lpfc_dmabuf *inp;
786         struct lpfc_dmabuf *outp;
787         IOCB_t *irsp;
788         struct lpfc_sli_ct_request *CTrsp;
789         int cmdcode, rc;
790         uint8_t retry;
791         uint32_t latt;
792
793         /* we pass cmdiocb to state machine which needs rspiocb as well */
794         cmdiocb->context_un.rsp_iocb = rspiocb;
795
796         inp = (struct lpfc_dmabuf *) cmdiocb->context1;
797         outp = (struct lpfc_dmabuf *) cmdiocb->context2;
798         irsp = &rspiocb->iocb;
799
800         cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
801                                         CommandResponse.bits.CmdRsp);
802         CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
803
804         latt = lpfc_els_chk_latt(vport);
805
806         /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
807         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
808                         "%d (%d):0209 RFT request completes, latt %d, "
809                         "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
810                         phba->brd_no, vport->vpi, latt, irsp->ulpStatus,
811                         CTrsp->CommandResponse.bits.CmdRsp,
812                         cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
813
814         lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
815                 "CT cmd cmpl:     status:x%x/x%x cmd:x%x",
816                 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
817
818         if (irsp->ulpStatus) {
819                 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
820                         "%d (%d):0268 NS cmd %x Error (%d %d)\n",
821                         phba->brd_no, vport->vpi, cmdcode,
822                         irsp->ulpStatus, irsp->un.ulpWord[4]);
823
824                 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
825                         ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
826                          (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
827                         goto out;
828
829                 retry = cmdiocb->retry;
830                 if (retry >= LPFC_MAX_NS_RETRY)
831                         goto out;
832
833                 retry++;
834                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
835                                 "%d (%d):0216 Retrying NS cmd %x\n",
836                                 phba->brd_no, vport->vpi, cmdcode);
837                 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
838                 if (rc == 0)
839                         goto out;
840         }
841
842 out:
843         lpfc_ct_free_iocb(phba, cmdiocb);
844         return;
845 }
846
847 static void
848 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
849                         struct lpfc_iocbq *rspiocb)
850 {
851         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
852         return;
853 }
854
855 static void
856 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
857                          struct lpfc_iocbq *rspiocb)
858 {
859         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
860         return;
861 }
862
863 static void
864 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
865                          struct lpfc_iocbq *rspiocb)
866 {
867         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
868         return;
869 }
870
871 static void
872 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
873                         struct lpfc_iocbq *rspiocb)
874 {
875         IOCB_t *irsp = &rspiocb->iocb;
876         struct lpfc_vport *vport = cmdiocb->vport;
877
878         if (irsp->ulpStatus != IOSTAT_SUCCESS)
879             vport->fc_flag |= FC_RFF_NOT_SUPPORTED;
880
881         lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
882         return;
883 }
884
885 int
886 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
887         size_t size)
888 {
889         int n;
890         uint8_t *wwn = vport->phba->wwpn;
891
892         n = snprintf(symbol, size,
893                      "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
894                      wwn[0], wwn[1], wwn[2], wwn[3],
895                      wwn[4], wwn[5], wwn[6], wwn[7]);
896
897         if (vport->port_type == LPFC_PHYSICAL_PORT)
898                 return n;
899
900         if (n < size)
901                 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
902
903         if (n < size && vport->vname)
904                 n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
905         return n;
906 }
907
908 int
909 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
910         size_t size)
911 {
912         char fwrev[16];
913         int n;
914
915         lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
916
917         n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
918                 vport->phba->ModelName, fwrev, lpfc_release_version);
919         return n;
920 }
921
922 /*
923  * lpfc_ns_cmd
924  * Description:
925  *    Issue Cmd to NameServer
926  *       SLI_CTNS_GID_FT
927  *       LI_CTNS_RFT_ID
928  */
929 int
930 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
931             uint8_t retry, uint32_t context)
932 {
933         struct lpfc_nodelist * ndlp;
934         struct lpfc_hba *phba = vport->phba;
935         struct lpfc_dmabuf *mp, *bmp;
936         struct lpfc_sli_ct_request *CtReq;
937         struct ulp_bde64 *bpl;
938         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
939                       struct lpfc_iocbq *) = NULL;
940         uint32_t rsp_size = 1024;
941         size_t   size;
942         int rc = 0;
943
944         ndlp = lpfc_findnode_did(vport, NameServer_DID);
945         if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
946                 rc=1;
947                 goto ns_cmd_exit;
948         }
949
950         /* fill in BDEs for command */
951         /* Allocate buffer for command payload */
952         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
953         if (!mp) {
954                 rc=2;
955                 goto ns_cmd_exit;
956         }
957
958         INIT_LIST_HEAD(&mp->list);
959         mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
960         if (!mp->virt) {
961                 rc=3;
962                 goto ns_cmd_free_mp;
963         }
964
965         /* Allocate buffer for Buffer ptr list */
966         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
967         if (!bmp) {
968                 rc=4;
969                 goto ns_cmd_free_mpvirt;
970         }
971
972         INIT_LIST_HEAD(&bmp->list);
973         bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
974         if (!bmp->virt) {
975                 rc=5;
976                 goto ns_cmd_free_bmp;
977         }
978
979         /* NameServer Req */
980         lpfc_printf_log(phba, KERN_INFO ,LOG_DISCOVERY,
981                         "%d (%d):0236 NameServer Req Data: x%x x%x x%x\n",
982                         phba->brd_no, vport->vpi, cmdcode, vport->fc_flag,
983                         vport->fc_rscn_id_cnt);
984
985         bpl = (struct ulp_bde64 *) bmp->virt;
986         memset(bpl, 0, sizeof(struct ulp_bde64));
987         bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
988         bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
989         bpl->tus.f.bdeFlags = 0;
990         if (cmdcode == SLI_CTNS_GID_FT)
991                 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
992         else if (cmdcode == SLI_CTNS_GFF_ID)
993                 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
994         else if (cmdcode == SLI_CTNS_RFT_ID)
995                 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
996         else if (cmdcode == SLI_CTNS_RNN_ID)
997                 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
998         else if (cmdcode == SLI_CTNS_RSPN_ID)
999                 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1000         else if (cmdcode == SLI_CTNS_RSNN_NN)
1001                 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1002         else if (cmdcode == SLI_CTNS_RFF_ID)
1003                 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1004         else
1005                 bpl->tus.f.bdeSize = 0;
1006         bpl->tus.w = le32_to_cpu(bpl->tus.w);
1007
1008         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1009         memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1010         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1011         CtReq->RevisionId.bits.InId = 0;
1012         CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1013         CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1014         CtReq->CommandResponse.bits.Size = 0;
1015         switch (cmdcode) {
1016         case SLI_CTNS_GID_FT:
1017                 CtReq->CommandResponse.bits.CmdRsp =
1018                     be16_to_cpu(SLI_CTNS_GID_FT);
1019                 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
1020                 if (vport->port_state < LPFC_NS_QRY)
1021                         vport->port_state = LPFC_NS_QRY;
1022                 lpfc_set_disctmo(vport);
1023                 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1024                 rsp_size = FC_MAX_NS_RSP;
1025                 break;
1026
1027         case SLI_CTNS_GFF_ID:
1028                 CtReq->CommandResponse.bits.CmdRsp =
1029                         be16_to_cpu(SLI_CTNS_GFF_ID);
1030                 CtReq->un.gff.PortId = be32_to_cpu(context);
1031                 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1032                 break;
1033
1034         case SLI_CTNS_RFT_ID:
1035                 CtReq->CommandResponse.bits.CmdRsp =
1036                     be16_to_cpu(SLI_CTNS_RFT_ID);
1037                 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
1038                 CtReq->un.rft.fcpReg = 1;
1039                 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1040                 break;
1041
1042         case SLI_CTNS_RNN_ID:
1043                 CtReq->CommandResponse.bits.CmdRsp =
1044                     be16_to_cpu(SLI_CTNS_RNN_ID);
1045                 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
1046                 memcpy(CtReq->un.rnn.wwnn,  &vport->fc_nodename,
1047                        sizeof (struct lpfc_name));
1048                 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1049                 break;
1050
1051         case SLI_CTNS_RSPN_ID:
1052                 CtReq->CommandResponse.bits.CmdRsp =
1053                     be16_to_cpu(SLI_CTNS_RSPN_ID);
1054                 CtReq->un.rspn.PortId = be32_to_cpu(vport->fc_myDID);
1055                 size = sizeof(CtReq->un.rspn.symbname);
1056                 CtReq->un.rspn.len =
1057                         lpfc_vport_symbolic_port_name(vport,
1058                         CtReq->un.rspn.symbname, size);
1059                 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1060                 break;
1061         case SLI_CTNS_RSNN_NN:
1062                 CtReq->CommandResponse.bits.CmdRsp =
1063                     be16_to_cpu(SLI_CTNS_RSNN_NN);
1064                 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1065                        sizeof (struct lpfc_name));
1066                 size = sizeof(CtReq->un.rsnn.symbname);
1067                 CtReq->un.rsnn.len =
1068                         lpfc_vport_symbolic_node_name(vport,
1069                         CtReq->un.rsnn.symbname, size);
1070                 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1071                 break;
1072         case SLI_CTNS_RFF_ID:
1073                 vport->fc_flag &= ~FC_RFF_NOT_SUPPORTED;
1074                 CtReq->CommandResponse.bits.CmdRsp =
1075                     be16_to_cpu(SLI_CTNS_RFF_ID);
1076                 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);;
1077                 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1078                 CtReq->un.rff.type_code = FC_FCP_DATA;
1079                 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1080                 break;
1081         }
1082
1083         if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1084                 /* On success, The cmpl function will free the buffers */
1085                 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1086                         "Issue CT cmd:    cmd:x%x did:x%x",
1087                         cmdcode, ndlp->nlp_DID, 0);
1088                 return 0;
1089         }
1090
1091         rc=6;
1092         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1093 ns_cmd_free_bmp:
1094         kfree(bmp);
1095 ns_cmd_free_mpvirt:
1096         lpfc_mbuf_free(phba, mp->virt, mp->phys);
1097 ns_cmd_free_mp:
1098         kfree(mp);
1099 ns_cmd_exit:
1100         lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
1101                 "%d (%d):0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1102                         phba->brd_no, vport->vpi, cmdcode, rc, vport->fc_flag,
1103                         vport->fc_rscn_id_cnt);
1104         return 1;
1105 }
1106
1107 static void
1108 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1109                       struct lpfc_iocbq * rspiocb)
1110 {
1111         struct lpfc_dmabuf *inp = cmdiocb->context1;
1112         struct lpfc_dmabuf *outp = cmdiocb->context2;
1113         struct lpfc_sli_ct_request *CTrsp = outp->virt;
1114         struct lpfc_sli_ct_request *CTcmd = inp->virt;
1115         struct lpfc_nodelist *ndlp;
1116         uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1117         uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1118         struct lpfc_vport *vport = cmdiocb->vport;
1119         IOCB_t *irsp = &rspiocb->iocb;
1120         uint32_t latt;
1121
1122         latt = lpfc_els_chk_latt(vport);
1123
1124         lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1125                 "FDMI cmpl:       status:x%x/x%x latt:%d",
1126                 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1127
1128         if (latt || irsp->ulpStatus) {
1129                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1130                                 "%d (%d):0229 FDMI cmd %04x failed, latt = %d "
1131                                 "ulpStatus: x%x, rid x%x\n",
1132                                 phba->brd_no, vport->vpi,
1133                                 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1134                                 irsp->un.ulpWord[4]);
1135                 lpfc_ct_free_iocb(phba, cmdiocb);
1136                 return;
1137         }
1138
1139         ndlp = lpfc_findnode_did(vport, FDMI_DID);
1140         if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1141                 /* FDMI rsp failed */
1142                 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1143                                 "%d (%d):0220 FDMI rsp failed Data: x%x\n",
1144                                 phba->brd_no, vport->vpi,
1145                                 be16_to_cpu(fdmi_cmd));
1146         }
1147
1148         switch (be16_to_cpu(fdmi_cmd)) {
1149         case SLI_MGMT_RHBA:
1150                 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
1151                 break;
1152
1153         case SLI_MGMT_RPA:
1154                 break;
1155
1156         case SLI_MGMT_DHBA:
1157                 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
1158                 break;
1159
1160         case SLI_MGMT_DPRT:
1161                 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
1162                 break;
1163         }
1164         lpfc_ct_free_iocb(phba, cmdiocb);
1165         return;
1166 }
1167
1168 int
1169 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
1170 {
1171         struct lpfc_hba *phba = vport->phba;
1172         struct lpfc_dmabuf *mp, *bmp;
1173         struct lpfc_sli_ct_request *CtReq;
1174         struct ulp_bde64 *bpl;
1175         uint32_t size;
1176         REG_HBA *rh;
1177         PORT_ENTRY *pe;
1178         REG_PORT_ATTRIBUTE *pab;
1179         ATTRIBUTE_BLOCK *ab;
1180         ATTRIBUTE_ENTRY *ae;
1181         void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1182                       struct lpfc_iocbq *);
1183
1184
1185         /* fill in BDEs for command */
1186         /* Allocate buffer for command payload */
1187         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1188         if (!mp)
1189                 goto fdmi_cmd_exit;
1190
1191         mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1192         if (!mp->virt)
1193                 goto fdmi_cmd_free_mp;
1194
1195         /* Allocate buffer for Buffer ptr list */
1196         bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1197         if (!bmp)
1198                 goto fdmi_cmd_free_mpvirt;
1199
1200         bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1201         if (!bmp->virt)
1202                 goto fdmi_cmd_free_bmp;
1203
1204         INIT_LIST_HEAD(&mp->list);
1205         INIT_LIST_HEAD(&bmp->list);
1206
1207         /* FDMI request */
1208         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1209                         "%d (%d):0218 FDMI Request Data: x%x x%x x%x\n",
1210                         phba->brd_no, vport->vpi, vport->fc_flag,
1211                         vport->port_state, cmdcode);
1212
1213         CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1214
1215         memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1216         CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1217         CtReq->RevisionId.bits.InId = 0;
1218
1219         CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1220         CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1221         size = 0;
1222
1223         switch (cmdcode) {
1224         case SLI_MGMT_RHBA:
1225                 {
1226                         lpfc_vpd_t *vp = &phba->vpd;
1227                         uint32_t i, j, incr;
1228                         int len;
1229
1230                         CtReq->CommandResponse.bits.CmdRsp =
1231                             be16_to_cpu(SLI_MGMT_RHBA);
1232                         CtReq->CommandResponse.bits.Size = 0;
1233                         rh = (REG_HBA *) & CtReq->un.PortID;
1234                         memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
1235                                sizeof (struct lpfc_name));
1236                         /* One entry (port) per adapter */
1237                         rh->rpl.EntryCnt = be32_to_cpu(1);
1238                         memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
1239                                sizeof (struct lpfc_name));
1240
1241                         /* point to the HBA attribute block */
1242                         size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1243                         ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1244                         ab->EntryCnt = 0;
1245
1246                         /* Point to the beginning of the first HBA attribute
1247                            entry */
1248                         /* #1 HBA attribute entry */
1249                         size += FOURBYTES;
1250                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1251                         ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1252                         ae->ad.bits.AttrLen =  be16_to_cpu(FOURBYTES
1253                                                 + sizeof (struct lpfc_name));
1254                         memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
1255                                sizeof (struct lpfc_name));
1256                         ab->EntryCnt++;
1257                         size += FOURBYTES + sizeof (struct lpfc_name);
1258
1259                         /* #2 HBA attribute entry */
1260                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1261                         ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1262                         strcpy(ae->un.Manufacturer, "Emulex Corporation");
1263                         len = strlen(ae->un.Manufacturer);
1264                         len += (len & 3) ? (4 - (len & 3)) : 4;
1265                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1266                         ab->EntryCnt++;
1267                         size += FOURBYTES + len;
1268
1269                         /* #3 HBA attribute entry */
1270                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1271                         ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1272                         strcpy(ae->un.SerialNumber, phba->SerialNumber);
1273                         len = strlen(ae->un.SerialNumber);
1274                         len += (len & 3) ? (4 - (len & 3)) : 4;
1275                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1276                         ab->EntryCnt++;
1277                         size += FOURBYTES + len;
1278
1279                         /* #4 HBA attribute entry */
1280                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1281                         ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1282                         strcpy(ae->un.Model, phba->ModelName);
1283                         len = strlen(ae->un.Model);
1284                         len += (len & 3) ? (4 - (len & 3)) : 4;
1285                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1286                         ab->EntryCnt++;
1287                         size += FOURBYTES + len;
1288
1289                         /* #5 HBA attribute entry */
1290                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1291                         ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1292                         strcpy(ae->un.ModelDescription, phba->ModelDesc);
1293                         len = strlen(ae->un.ModelDescription);
1294                         len += (len & 3) ? (4 - (len & 3)) : 4;
1295                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1296                         ab->EntryCnt++;
1297                         size += FOURBYTES + len;
1298
1299                         /* #6 HBA attribute entry */
1300                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1301                         ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1302                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1303                         /* Convert JEDEC ID to ascii for hardware version */
1304                         incr = vp->rev.biuRev;
1305                         for (i = 0; i < 8; i++) {
1306                                 j = (incr & 0xf);
1307                                 if (j <= 9)
1308                                         ae->un.HardwareVersion[7 - i] =
1309                                             (char)((uint8_t) 0x30 +
1310                                                    (uint8_t) j);
1311                                 else
1312                                         ae->un.HardwareVersion[7 - i] =
1313                                             (char)((uint8_t) 0x61 +
1314                                                    (uint8_t) (j - 10));
1315                                 incr = (incr >> 4);
1316                         }
1317                         ab->EntryCnt++;
1318                         size += FOURBYTES + 8;
1319
1320                         /* #7 HBA attribute entry */
1321                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1322                         ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1323                         strcpy(ae->un.DriverVersion, lpfc_release_version);
1324                         len = strlen(ae->un.DriverVersion);
1325                         len += (len & 3) ? (4 - (len & 3)) : 4;
1326                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1327                         ab->EntryCnt++;
1328                         size += FOURBYTES + len;
1329
1330                         /* #8 HBA attribute entry */
1331                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1332                         ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1333                         strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1334                         len = strlen(ae->un.OptionROMVersion);
1335                         len += (len & 3) ? (4 - (len & 3)) : 4;
1336                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1337                         ab->EntryCnt++;
1338                         size += FOURBYTES + len;
1339
1340                         /* #9 HBA attribute entry */
1341                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1342                         ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1343                         lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1344                                 1);
1345                         len = strlen(ae->un.FirmwareVersion);
1346                         len += (len & 3) ? (4 - (len & 3)) : 4;
1347                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1348                         ab->EntryCnt++;
1349                         size += FOURBYTES + len;
1350
1351                         /* #10 HBA attribute entry */
1352                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1353                         ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1354                         sprintf(ae->un.OsNameVersion, "%s %s %s",
1355                                 init_utsname()->sysname,
1356                                 init_utsname()->release,
1357                                 init_utsname()->version);
1358                         len = strlen(ae->un.OsNameVersion);
1359                         len += (len & 3) ? (4 - (len & 3)) : 4;
1360                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1361                         ab->EntryCnt++;
1362                         size += FOURBYTES + len;
1363
1364                         /* #11 HBA attribute entry */
1365                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1366                         ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1367                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1368                         ae->un.MaxCTPayloadLen = (65 * 4096);
1369                         ab->EntryCnt++;
1370                         size += FOURBYTES + 4;
1371
1372                         ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1373                         /* Total size */
1374                         size = GID_REQUEST_SZ - 4 + size;
1375                 }
1376                 break;
1377
1378         case SLI_MGMT_RPA:
1379                 {
1380                         lpfc_vpd_t *vp;
1381                         struct serv_parm *hsp;
1382                         int len;
1383
1384                         vp = &phba->vpd;
1385
1386                         CtReq->CommandResponse.bits.CmdRsp =
1387                             be16_to_cpu(SLI_MGMT_RPA);
1388                         CtReq->CommandResponse.bits.Size = 0;
1389                         pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1390                         size = sizeof (struct lpfc_name) + FOURBYTES;
1391                         memcpy((uint8_t *) & pab->PortName,
1392                                (uint8_t *) & vport->fc_sparam.portName,
1393                                sizeof (struct lpfc_name));
1394                         pab->ab.EntryCnt = 0;
1395
1396                         /* #1 Port attribute entry */
1397                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1398                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1399                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1400                         ae->un.SupportFC4Types[2] = 1;
1401                         ae->un.SupportFC4Types[7] = 1;
1402                         pab->ab.EntryCnt++;
1403                         size += FOURBYTES + 32;
1404
1405                         /* #2 Port attribute entry */
1406                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1407                         ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1408                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1409
1410                         ae->un.SupportSpeed = 0;
1411                         if (phba->lmt & LMT_10Gb)
1412                                 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1413                         if (phba->lmt & LMT_8Gb)
1414                                 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1415                         if (phba->lmt & LMT_4Gb)
1416                                 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1417                         if (phba->lmt & LMT_2Gb)
1418                                 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1419                         if (phba->lmt & LMT_1Gb)
1420                                 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1421
1422                         pab->ab.EntryCnt++;
1423                         size += FOURBYTES + 4;
1424
1425                         /* #3 Port attribute entry */
1426                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1427                         ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1428                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1429                         switch(phba->fc_linkspeed) {
1430                                 case LA_1GHZ_LINK:
1431                                         ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1432                                 break;
1433                                 case LA_2GHZ_LINK:
1434                                         ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1435                                 break;
1436                                 case LA_4GHZ_LINK:
1437                                         ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1438                                 break;
1439                                 case LA_8GHZ_LINK:
1440                                         ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1441                                 break;
1442                                 default:
1443                                         ae->un.PortSpeed =
1444                                                 HBA_PORTSPEED_UNKNOWN;
1445                                 break;
1446                         }
1447                         pab->ab.EntryCnt++;
1448                         size += FOURBYTES + 4;
1449
1450                         /* #4 Port attribute entry */
1451                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1452                         ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1453                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1454                         hsp = (struct serv_parm *) & vport->fc_sparam;
1455                         ae->un.MaxFrameSize =
1456                             (((uint32_t) hsp->cmn.
1457                               bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1458                             bbRcvSizeLsb;
1459                         pab->ab.EntryCnt++;
1460                         size += FOURBYTES + 4;
1461
1462                         /* #5 Port attribute entry */
1463                         ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1464                         ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1465                         strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1466                         len = strlen((char *)ae->un.OsDeviceName);
1467                         len += (len & 3) ? (4 - (len & 3)) : 4;
1468                         ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1469                         pab->ab.EntryCnt++;
1470                         size += FOURBYTES + len;
1471
1472                         if (phba->cfg_fdmi_on == 2) {
1473                                 /* #6 Port attribute entry */
1474                                 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1475                                                           size);
1476                                 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1477                                 sprintf(ae->un.HostName, "%s",
1478                                         init_utsname()->nodename);
1479                                 len = strlen(ae->un.HostName);
1480                                 len += (len & 3) ? (4 - (len & 3)) : 4;
1481                                 ae->ad.bits.AttrLen =
1482                                     be16_to_cpu(FOURBYTES + len);
1483                                 pab->ab.EntryCnt++;
1484                                 size += FOURBYTES + len;
1485                         }
1486
1487                         pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1488                         /* Total size */
1489                         size = GID_REQUEST_SZ - 4 + size;
1490                 }
1491                 break;
1492
1493         case SLI_MGMT_DHBA:
1494                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1495                 CtReq->CommandResponse.bits.Size = 0;
1496                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1497                 memcpy((uint8_t *) & pe->PortName,
1498                        (uint8_t *) & vport->fc_sparam.portName,
1499                        sizeof (struct lpfc_name));
1500                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1501                 break;
1502
1503         case SLI_MGMT_DPRT:
1504                 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1505                 CtReq->CommandResponse.bits.Size = 0;
1506                 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1507                 memcpy((uint8_t *) & pe->PortName,
1508                        (uint8_t *) & vport->fc_sparam.portName,
1509                        sizeof (struct lpfc_name));
1510                 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1511                 break;
1512         }
1513
1514         bpl = (struct ulp_bde64 *) bmp->virt;
1515         bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1516         bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1517         bpl->tus.f.bdeFlags = 0;
1518         bpl->tus.f.bdeSize = size;
1519         bpl->tus.w = le32_to_cpu(bpl->tus.w);
1520
1521         cmpl = lpfc_cmpl_ct_cmd_fdmi;
1522
1523         if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
1524                 return 0;
1525
1526         lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1527 fdmi_cmd_free_bmp:
1528         kfree(bmp);
1529 fdmi_cmd_free_mpvirt:
1530         lpfc_mbuf_free(phba, mp->virt, mp->phys);
1531 fdmi_cmd_free_mp:
1532         kfree(mp);
1533 fdmi_cmd_exit:
1534         /* Issue FDMI request failed */
1535         lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1536                         "%d (%d):0244 Issue FDMI request failed Data: x%x\n",
1537                         phba->brd_no, vport->vpi, cmdcode);
1538         return 1;
1539 }
1540
1541 void
1542 lpfc_fdmi_tmo(unsigned long ptr)
1543 {
1544         struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1545         struct lpfc_hba   *phba = vport->phba;
1546         unsigned long iflag;
1547
1548         spin_lock_irqsave(&vport->work_port_lock, iflag);
1549         if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1550                 vport->work_port_events |= WORKER_FDMI_TMO;
1551                 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1552
1553                 spin_lock_irqsave(&phba->hbalock, iflag);
1554                 if (phba->work_wait)
1555                         lpfc_worker_wake_up(phba);
1556                 spin_unlock_irqrestore(&phba->hbalock, iflag);
1557         }
1558         else
1559                 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1560 }
1561
1562 void
1563 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1564 {
1565         struct lpfc_nodelist *ndlp;
1566
1567         ndlp = lpfc_findnode_did(vport, FDMI_DID);
1568         if (ndlp) {
1569                 if (init_utsname()->nodename[0] != '\0')
1570                         lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1571                 else
1572                         mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1573         }
1574         return;
1575 }
1576
1577 void
1578 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1579 {
1580         struct lpfc_sli *psli = &phba->sli;
1581         lpfc_vpd_t *vp = &phba->vpd;
1582         uint32_t b1, b2, b3, b4, i, rev;
1583         char c;
1584         uint32_t *ptr, str[4];
1585         uint8_t *fwname;
1586
1587         if (vp->rev.rBit) {
1588                 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1589                         rev = vp->rev.sli2FwRev;
1590                 else
1591                         rev = vp->rev.sli1FwRev;
1592
1593                 b1 = (rev & 0x0000f000) >> 12;
1594                 b2 = (rev & 0x00000f00) >> 8;
1595                 b3 = (rev & 0x000000c0) >> 6;
1596                 b4 = (rev & 0x00000030) >> 4;
1597
1598                 switch (b4) {
1599                 case 0:
1600                         c = 'N';
1601                         break;
1602                 case 1:
1603                         c = 'A';
1604                         break;
1605                 case 2:
1606                         c = 'B';
1607                         break;
1608                 default:
1609                         c = 0;
1610                         break;
1611                 }
1612                 b4 = (rev & 0x0000000f);
1613
1614                 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1615                         fwname = vp->rev.sli2FwName;
1616                 else
1617                         fwname = vp->rev.sli1FwName;
1618
1619                 for (i = 0; i < 16; i++)
1620                         if (fwname[i] == 0x20)
1621                                 fwname[i] = 0;
1622
1623                 ptr = (uint32_t*)fwname;
1624
1625                 for (i = 0; i < 3; i++)
1626                         str[i] = be32_to_cpu(*ptr++);
1627
1628                 if (c == 0) {
1629                         if (flag)
1630                                 sprintf(fwrevision, "%d.%d%d (%s)",
1631                                         b1, b2, b3, (char *)str);
1632                         else
1633                                 sprintf(fwrevision, "%d.%d%d", b1,
1634                                         b2, b3);
1635                 } else {
1636                         if (flag)
1637                                 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1638                                         b1, b2, b3, c,
1639                                         b4, (char *)str);
1640                         else
1641                                 sprintf(fwrevision, "%d.%d%d%c%d",
1642                                         b1, b2, b3, c, b4);
1643                 }
1644         } else {
1645                 rev = vp->rev.smFwRev;
1646
1647                 b1 = (rev & 0xff000000) >> 24;
1648                 b2 = (rev & 0x00f00000) >> 20;
1649                 b3 = (rev & 0x000f0000) >> 16;
1650                 c  = (rev & 0x0000ff00) >> 8;
1651                 b4 = (rev & 0x000000ff);
1652
1653                 if (flag)
1654                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1655                                 b2, b3, c, b4);
1656                 else
1657                         sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1658                                 b2, b3, c, b4);
1659         }
1660         return;
1661 }