blob: dbe020e66b0971067c556ac6c2f1e33ce13e0df6 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * 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. *
dea31012005-04-17 16:05:31 -050019 *******************************************************************/
20
21/*
dea31012005-04-17 16:05:31 -050022 * 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
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040033#include <scsi/scsi_transport_fc.h>
dea31012005-04-17 16:05:31 -050034
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"
James Smart92d7f7b2007-06-17 19:56:38 -050043#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050044#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050045
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
58static char *lpfc_release_version = LPFC_DRIVER_VERSION;
59
60/*
61 * lpfc_ct_unsol_event
62 */
James Smarted957682007-06-17 19:56:37 -050063static void
64lpfc_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);
James Smart92d7f7b2007-06-17 19:56:38 -050079
James Smarted957682007-06-17 19:56:37 -050080}
81
82static void
83lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050084 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050085{
James Smarted957682007-06-17 19:56:37 -050086 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
dea31012005-04-17 16:05:31 -0500101void
James Smart2e0fef82007-06-17 19:56:36 -0500102lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
103 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -0500104{
James Smart92d7f7b2007-06-17 19:56:38 -0500105
James Smarted957682007-06-17 19:56:37 -0500106 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -0500107 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -0500108 int i;
109 struct lpfc_iocbq *iocbq;
110 dma_addr_t paddr;
111 uint32_t size;
James Smart92d7f7b2007-06-17 19:56:38 -0500112 struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
113 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
dea31012005-04-17 16:05:31 -0500114
James Smart92d7f7b2007-06-17 19:56:38 -0500115 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)) {
dea31012005-04-17 16:05:31 -0500122 /* Not enough posted buffers; Try posting more buffers */
123 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500124 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -0500125 lpfc_post_buffer(phba, pring, 0, 1);
dea31012005-04-17 16:05:31 -0500126 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
James Smarted957682007-06-17 19:56:37 -0500135 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;
dea31012005-04-17 16:05:31 -0500144 }
145
James Smarted957682007-06-17 19:56:37 -0500146 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart92d7f7b2007-06-17 19:56:38 -0500147 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf1, size);
148 lpfc_in_buf_free(phba, bdeBuf1);
James Smarted957682007-06-17 19:56:37 -0500149 if (icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -0500150 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf2,
James Smarted957682007-06-17 19:56:37 -0500151 size);
James Smart92d7f7b2007-06-17 19:56:38 -0500152 lpfc_in_buf_free(phba, bdeBuf2);
James Smarted957682007-06-17 19:56:37 -0500153 }
dea31012005-04-17 16:05:31 -0500154 }
James Smarted957682007-06-17 19:56:37 -0500155 } else {
156 struct lpfc_iocbq *next;
dea31012005-04-17 16:05:31 -0500157
James Smarted957682007-06-17 19:56:37 -0500158 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 }
dea31012005-04-17 16:05:31 -0500167
James Smarted957682007-06-17 19:56:37 -0500168 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);
James Smart92d7f7b2007-06-17 19:56:38 -0500175 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500176 }
177 list_del(&iocbq->list);
178 lpfc_sli_release_iocbq(phba, iocbq);
dea31012005-04-17 16:05:31 -0500179 }
dea31012005-04-17 16:05:31 -0500180 }
dea31012005-04-17 16:05:31 -0500181}
182
183static void
James Smart2e0fef82007-06-17 19:56:36 -0500184lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500185{
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
198static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500199lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500200 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
James Smart92d7f7b2007-06-17 19:56:38 -0500220 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
221 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500222 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);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700228 if (mlist)
229 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500230 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 */
James Smart92d7f7b2007-06-17 19:56:38 -0500241 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
242 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500243 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
James Smart858c9f62007-06-17 19:56:39 -0500255int
256lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
257{
258 struct lpfc_dmabuf *buf_ptr;
259
James Smart51ef4c22007-08-02 11:10:31 -0400260 if (ctiocb->context_un.ndlp) {
261 lpfc_nlp_put(ctiocb->context_un.ndlp);
262 ctiocb->context_un.ndlp = NULL;
263 }
James Smart858c9f62007-06-17 19:56:39 -0500264 if (ctiocb->context1) {
265 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
266 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
267 kfree(buf_ptr);
268 ctiocb->context1 = NULL;
269 }
270 if (ctiocb->context2) {
271 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
272 ctiocb->context2 = NULL;
273 }
274
275 if (ctiocb->context3) {
276 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
277 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
278 kfree(buf_ptr);
279 ctiocb->context1 = NULL;
280 }
281 lpfc_sli_release_iocbq(phba, ctiocb);
282 return 0;
283}
284
dea31012005-04-17 16:05:31 -0500285static int
James Smart2e0fef82007-06-17 19:56:36 -0500286lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500287 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
288 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
289 struct lpfc_iocbq *),
290 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500291 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500292{
James Smart2e0fef82007-06-17 19:56:36 -0500293 struct lpfc_hba *phba = vport->phba;
294 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500295 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500296 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400297 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500298 int rc;
dea31012005-04-17 16:05:31 -0500299
300 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400301 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500302
303 if (geniocb == NULL)
304 return 1;
dea31012005-04-17 16:05:31 -0500305
306 icmd = &geniocb->iocb;
307 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
308 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
309 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
310 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
311 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
312
313 if (usr_flg)
314 geniocb->context3 = NULL;
315 else
316 geniocb->context3 = (uint8_t *) bmp;
317
318 /* Save for completion so we can release these resources */
319 geniocb->context1 = (uint8_t *) inp;
320 geniocb->context2 = (uint8_t *) outp;
James Smart51ef4c22007-08-02 11:10:31 -0400321 geniocb->context_un.ndlp = ndlp;
dea31012005-04-17 16:05:31 -0500322
323 /* Fill in payload, bp points to frame payload */
324 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
325
326 /* Fill in rest of iocb */
327 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
328 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
329 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
330 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
331
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500332 if (!tmo) {
333 /* FC spec states we need 3 * ratov for CT requests */
334 tmo = (3 * phba->fc_ratov);
335 }
dea31012005-04-17 16:05:31 -0500336 icmd->ulpTimeout = tmo;
337 icmd->ulpBdeCount = 1;
338 icmd->ulpLe = 1;
339 icmd->ulpClass = CLASS3;
340 icmd->ulpContext = ndlp->nlp_rpi;
341
James Smart92d7f7b2007-06-17 19:56:38 -0500342 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
343 /* For GEN_REQUEST64_CR, use the RPI */
344 icmd->ulpCt_h = 0;
345 icmd->ulpCt_l = 0;
346 }
347
dea31012005-04-17 16:05:31 -0500348 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400349 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
350 "0119 Issue GEN REQ IOCB to NPORT x%x "
351 "Data: x%x x%x\n",
352 ndlp->nlp_DID, icmd->ulpIoTag,
353 vport->port_state);
dea31012005-04-17 16:05:31 -0500354 geniocb->iocb_cmpl = cmpl;
355 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500356 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500357 geniocb->retry = retry;
358 rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
359
360 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500361 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500362 return 1;
363 }
dea31012005-04-17 16:05:31 -0500364
365 return 0;
366}
367
368static int
James Smart2e0fef82007-06-17 19:56:36 -0500369lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500370 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
371 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
372 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500373 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500374{
James Smart2e0fef82007-06-17 19:56:36 -0500375 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500376 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
377 struct lpfc_dmabuf *outmp;
378 int cnt = 0, status;
379 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
380 CommandResponse.bits.CmdRsp;
381
382 bpl++; /* Skip past ct request */
383
384 /* Put buffer(s) for ct rsp in bpl */
385 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
386 if (!outmp)
387 return -ENOMEM;
388
James Smart2e0fef82007-06-17 19:56:36 -0500389 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart92d7f7b2007-06-17 19:56:38 -0500390 cnt+1, 0, retry);
dea31012005-04-17 16:05:31 -0500391 if (status) {
392 lpfc_free_ct_rsp(phba, outmp);
393 return -ENOMEM;
394 }
395 return 0;
396}
397
James Smart549e55c2007-08-02 11:09:51 -0400398struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500399lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500400 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400401 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500402
James Smart549e55c2007-08-02 11:09:51 -0400403 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500404 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400405 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
406 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500407 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400408 }
James Smart92d7f7b2007-06-17 19:56:38 -0500409 }
James Smart549e55c2007-08-02 11:09:51 -0400410 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return NULL;
412}
413
dea31012005-04-17 16:05:31 -0500414static int
James Smart2e0fef82007-06-17 19:56:36 -0500415lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500416{
James Smart2e0fef82007-06-17 19:56:36 -0500417 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500418 struct lpfc_sli_ct_request *Response =
419 (struct lpfc_sli_ct_request *) mp->virt;
420 struct lpfc_nodelist *ndlp = NULL;
421 struct lpfc_dmabuf *mlast, *next_mp;
422 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500423 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500424 int Cnt;
425 struct list_head head;
426
James Smart2e0fef82007-06-17 19:56:36 -0500427 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500428 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -0500429
dea31012005-04-17 16:05:31 -0500430
431 list_add_tail(&head, &mp->list);
432 list_for_each_entry_safe(mp, next_mp, &head, list) {
433 mlast = mp;
434
James Smart7054a602007-04-25 09:52:34 -0400435 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
436
dea31012005-04-17 16:05:31 -0500437 Size -= Cnt;
438
James Smart1dcb58e2007-04-25 09:51:30 -0400439 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500440 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400441 } else
dea31012005-04-17 16:05:31 -0500442 Cnt -= 16; /* subtract length of CT header */
443
444 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400445 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500446 /* Get next DID from NameServer List */
447 CTentry = *ctptr++;
448 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500449
dea31012005-04-17 16:05:31 -0500450 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500451
452 /*
453 * Check for rscn processing or not
454 * To conserve rpi's, filter out addresses for other
455 * vports on the same physical HBAs.
456 */
457 if ((Did != vport->fc_myDID) &&
458 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400459 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500460 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart7ee5d432007-10-27 13:37:17 -0400461 (!vport->ct_flags & FC_CT_RFF_ID) ||
James Smart3de2a652007-08-02 11:09:59 -0400462 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500463 ndlp = lpfc_setup_disc_node(vport, Did);
464 if (ndlp) {
James Smart858c9f62007-06-17 19:56:39 -0500465 lpfc_debugfs_disc_trc(vport,
466 LPFC_DISC_TRC_CT,
467 "Parse GID_FTrsp: "
468 "did:x%x flg:x%x x%x",
469 Did, ndlp->nlp_flag,
470 vport->fc_flag);
471
James Smarte8b62012007-08-02 11:10:09 -0400472 lpfc_printf_vlog(vport,
473 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500474 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400475 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500476 "x%x NameServer Rsp"
477 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400478 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500479 vport->fc_flag,
480 vport->fc_rscn_id_cnt);
481 } else {
James Smart858c9f62007-06-17 19:56:39 -0500482 lpfc_debugfs_disc_trc(vport,
483 LPFC_DISC_TRC_CT,
484 "Skip1 GID_FTrsp: "
485 "did:x%x flg:x%x cnt:%d",
486 Did, vport->fc_flag,
487 vport->fc_rscn_id_cnt);
488
James Smarte8b62012007-08-02 11:10:09 -0400489 lpfc_printf_vlog(vport,
490 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500491 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400492 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500493 "NameServer Rsp Data: "
494 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400495 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500496 vport->fc_rscn_id_cnt);
497 }
498
499 } else {
500 if (!(vport->fc_flag & FC_RSCN_MODE) ||
501 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500502 lpfc_debugfs_disc_trc(vport,
503 LPFC_DISC_TRC_CT,
504 "Query GID_FTrsp: "
505 "did:x%x flg:x%x cnt:%d",
506 Did, vport->fc_flag,
507 vport->fc_rscn_id_cnt);
508
James Smart92d7f7b2007-06-17 19:56:38 -0500509 if (lpfc_ns_cmd(vport,
510 SLI_CTNS_GFF_ID,
511 0, Did) == 0)
512 vport->num_disc_nodes++;
513 }
514 else {
James Smart858c9f62007-06-17 19:56:39 -0500515 lpfc_debugfs_disc_trc(vport,
516 LPFC_DISC_TRC_CT,
517 "Skip2 GID_FTrsp: "
518 "did:x%x flg:x%x cnt:%d",
519 Did, vport->fc_flag,
520 vport->fc_rscn_id_cnt);
521
James Smarte8b62012007-08-02 11:10:09 -0400522 lpfc_printf_vlog(vport,
523 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500524 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400525 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500526 "NameServer Rsp Data: "
527 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400528 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500529 vport->fc_rscn_id_cnt);
530 }
531 }
dea31012005-04-17 16:05:31 -0500532 }
dea31012005-04-17 16:05:31 -0500533 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
534 goto nsout1;
535 Cnt -= sizeof (uint32_t);
536 }
537 ctptr = NULL;
538
539 }
540
541nsout1:
542 list_del(&head);
dea31012005-04-17 16:05:31 -0500543 return 0;
544}
545
dea31012005-04-17 16:05:31 -0500546static void
James Smart2e0fef82007-06-17 19:56:36 -0500547lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
548 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500549{
James Smart2e0fef82007-06-17 19:56:36 -0500550 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500552 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500553 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500554 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500555 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400556 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500557 int rc;
dea31012005-04-17 16:05:31 -0500558
James Smart51ef4c22007-08-02 11:10:31 -0400559 /* First save ndlp, before we overwrite it */
560 ndlp = cmdiocb->context_un.ndlp;
561
dea31012005-04-17 16:05:31 -0500562 /* we pass cmdiocb to state machine which needs rspiocb as well */
563 cmdiocb->context_un.rsp_iocb = rspiocb;
564
dea31012005-04-17 16:05:31 -0500565 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
566 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500567 irsp = &rspiocb->iocb;
568
569 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
570 "GID_FT cmpl: status:x%x/x%x rtry:%d",
571 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500572
James Smart92d7f7b2007-06-17 19:56:38 -0500573 /* Don't bother processing response if vport is being torn down. */
574 if (vport->load_flag & FC_UNLOADING)
575 goto out;
576
dea31012005-04-17 16:05:31 -0500577
James Smart858c9f62007-06-17 19:56:39 -0500578 if (lpfc_els_chk_latt(vport) || lpfc_error_lost_link(irsp)) {
James Smarte8b62012007-08-02 11:10:09 -0400579 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
580 "0216 Link event during NS query\n");
James Smart858c9f62007-06-17 19:56:39 -0500581 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
582 goto out;
583 }
584
585 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500586 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500587 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart858c9f62007-06-17 19:56:39 -0500588 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
589 (irsp->un.ulpWord[4] != IOERR_NO_RESOURCES))
590 vport->fc_ns_retry++;
dea31012005-04-17 16:05:31 -0500591 /* CT command is being retried */
James Smart92d7f7b2007-06-17 19:56:38 -0500592 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
593 vport->fc_ns_retry, 0);
594 if (rc == 0)
595 goto out;
596 }
James Smart92d7f7b2007-06-17 19:56:38 -0500597 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400598 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
599 "0257 GID_FT Query error: 0x%x 0x%x\n",
600 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500601 } else {
602 /* Good status, continue checking */
603 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
604 if (CTrsp->CommandResponse.bits.CmdRsp ==
605 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400606 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
607 "0208 NameServer Rsp Data: x%x\n",
608 vport->fc_flag);
James Smart2e0fef82007-06-17 19:56:36 -0500609 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500610 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
611 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
612 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
613 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400614 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
615 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400616 lpfc_printf_vlog(vport, KERN_INFO,
617 LOG_DISCOVERY,
618 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400619 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400620 CTrsp->CommandResponse.bits.CmdRsp,
621 (uint32_t) CTrsp->ReasonCode,
622 (uint32_t) CTrsp->Explanation,
623 vport->fc_flag);
624
625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
626 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
627 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
628 (uint32_t) CTrsp->ReasonCode,
629 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400630 } else {
631 lpfc_printf_vlog(vport, KERN_INFO,
632 LOG_DISCOVERY,
633 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500634 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500635 CTrsp->CommandResponse.bits.CmdRsp,
636 (uint32_t) CTrsp->ReasonCode,
637 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500638 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500639
James Smarta58cbd52007-08-02 11:09:43 -0400640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500641 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
642 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
643 (uint32_t) CTrsp->ReasonCode,
644 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400645 }
646
James Smart858c9f62007-06-17 19:56:39 -0500647
dea31012005-04-17 16:05:31 -0500648 } else {
649 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400650 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
651 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500652 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500653 CTrsp->CommandResponse.bits.CmdRsp,
654 (uint32_t) CTrsp->ReasonCode,
655 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500656 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500657
658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
659 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
660 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
661 (uint32_t) CTrsp->ReasonCode,
662 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500663 }
664 }
665 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500666 if (vport->num_disc_nodes == 0) {
667 /*
668 * The driver has cycled through all Nports in the RSCN payload.
669 * Complete the handling by cleaning up and marking the
670 * current driver state.
671 */
672 if (vport->port_state >= LPFC_DISC_AUTH) {
673 if (vport->fc_flag & FC_RSCN_MODE) {
674 lpfc_els_flush_rscn(vport);
675 spin_lock_irq(shost->host_lock);
676 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
677 spin_unlock_irq(shost->host_lock);
678 }
679 else
680 lpfc_els_flush_rscn(vport);
681 }
682
683 lpfc_disc_start(vport);
684 }
dea31012005-04-17 16:05:31 -0500685out:
James Smart51ef4c22007-08-02 11:10:31 -0400686 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500687 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500688 return;
689}
690
James Smart311464e2007-08-02 11:10:37 -0400691static void
James Smart92d7f7b2007-06-17 19:56:38 -0500692lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
693 struct lpfc_iocbq *rspiocb)
694{
695 struct lpfc_vport *vport = cmdiocb->vport;
696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
697 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500698 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
699 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
700 struct lpfc_sli_ct_request *CTrsp;
701 int did;
702 uint8_t fbits;
703 struct lpfc_nodelist *ndlp;
704
705 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
706 did = be32_to_cpu(did);
707
James Smart858c9f62007-06-17 19:56:39 -0500708 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
709 "GFF_ID cmpl: status:x%x/x%x did:x%x",
710 irsp->ulpStatus, irsp->un.ulpWord[4], did);
711
James Smart92d7f7b2007-06-17 19:56:38 -0500712 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
713 /* Good status, continue checking */
714 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
715 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
716
717 if (CTrsp->CommandResponse.bits.CmdRsp ==
718 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
719 if ((fbits & FC4_FEATURE_INIT) &&
720 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400721 lpfc_printf_vlog(vport, KERN_INFO,
722 LOG_DISCOVERY,
723 "0270 Skip x%x GFF "
724 "NameServer Rsp Data: (init) "
725 "x%x x%x\n", did, fbits,
726 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500727 goto out;
728 }
729 }
730 }
James Smart858c9f62007-06-17 19:56:39 -0500731 else {
James Smarte8b62012007-08-02 11:10:09 -0400732 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
733 "0267 NameServer GFF Rsp "
734 "x%x Error (%d %d) Data: x%x x%x\n",
735 did, irsp->ulpStatus, irsp->un.ulpWord[4],
736 vport->fc_flag, vport->fc_rscn_id_cnt)
James Smart858c9f62007-06-17 19:56:39 -0500737 }
738
James Smart92d7f7b2007-06-17 19:56:38 -0500739 /* This is a target port, unregistered port, or the GFF_ID failed */
740 ndlp = lpfc_setup_disc_node(vport, did);
741 if (ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400742 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
743 "0242 Process x%x GFF "
744 "NameServer Rsp Data: x%x x%x x%x\n",
745 did, ndlp->nlp_flag, vport->fc_flag,
746 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500747 } else {
James Smarte8b62012007-08-02 11:10:09 -0400748 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
749 "0243 Skip x%x GFF "
750 "NameServer Rsp Data: x%x x%x\n", did,
751 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500752 }
753out:
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 }
James Smart858c9f62007-06-17 19:56:39 -0500775 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500776 return;
777}
778
779
dea31012005-04-17 16:05:31 -0500780static void
James Smart7ee5d432007-10-27 13:37:17 -0400781lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
782 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500783{
James Smart92d7f7b2007-06-17 19:56:38 -0500784 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500785 struct lpfc_dmabuf *inp;
786 struct lpfc_dmabuf *outp;
787 IOCB_t *irsp;
788 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400789 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500790 int cmdcode, rc;
791 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500792 uint32_t latt;
dea31012005-04-17 16:05:31 -0500793
James Smart51ef4c22007-08-02 11:10:31 -0400794 /* First save ndlp, before we overwrite it */
795 ndlp = cmdiocb->context_un.ndlp;
796
dea31012005-04-17 16:05:31 -0500797 /* we pass cmdiocb to state machine which needs rspiocb as well */
798 cmdiocb->context_un.rsp_iocb = rspiocb;
799
800 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
801 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500802 irsp = &rspiocb->iocb;
803
James Smart92d7f7b2007-06-17 19:56:38 -0500804 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
805 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500806 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
807
James Smart858c9f62007-06-17 19:56:39 -0500808 latt = lpfc_els_chk_latt(vport);
809
810 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400812 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400813 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
814 latt, irsp->ulpStatus,
815 CTrsp->CommandResponse.bits.CmdRsp,
816 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500817
James Smart858c9f62007-06-17 19:56:39 -0500818 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
819 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
820 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
821
James Smart92d7f7b2007-06-17 19:56:38 -0500822 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400823 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
824 "0268 NS cmd %x Error (%d %d)\n",
825 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500826
James Smart92d7f7b2007-06-17 19:56:38 -0500827 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
828 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
829 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
830 goto out;
831
832 retry = cmdiocb->retry;
833 if (retry >= LPFC_MAX_NS_RETRY)
834 goto out;
835
836 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400837 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
838 "0216 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500839 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
840 if (rc == 0)
841 goto out;
842 }
843
844out:
James Smart51ef4c22007-08-02 11:10:31 -0400845 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500846 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500847 return;
848}
849
850static void
James Smart7ee5d432007-10-27 13:37:17 -0400851lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
852 struct lpfc_iocbq *rspiocb)
853{
854 IOCB_t *irsp = &rspiocb->iocb;
855 struct lpfc_vport *vport = cmdiocb->vport;
856
857 if (irsp->ulpStatus == IOSTAT_SUCCESS)
858 vport->ct_flags |= FC_CT_RFT_ID;
859 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
860 return;
861}
862
863static void
James Smart2e0fef82007-06-17 19:56:36 -0500864lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
865 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500866{
James Smart7ee5d432007-10-27 13:37:17 -0400867 IOCB_t *irsp = &rspiocb->iocb;
868 struct lpfc_vport *vport = cmdiocb->vport;
869
870 if (irsp->ulpStatus == IOSTAT_SUCCESS)
871 vport->ct_flags |= FC_CT_RNN_ID;
872 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500873 return;
874}
875
876static void
James Smart92d7f7b2007-06-17 19:56:38 -0500877lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
878 struct lpfc_iocbq *rspiocb)
879{
James Smart7ee5d432007-10-27 13:37:17 -0400880 IOCB_t *irsp = &rspiocb->iocb;
881 struct lpfc_vport *vport = cmdiocb->vport;
882
883 if (irsp->ulpStatus == IOSTAT_SUCCESS)
884 vport->ct_flags |= FC_CT_RSPN_ID;
885 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500886 return;
887}
888
889static void
James Smart2e0fef82007-06-17 19:56:36 -0500890lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
891 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500892{
James Smart7ee5d432007-10-27 13:37:17 -0400893 IOCB_t *irsp = &rspiocb->iocb;
894 struct lpfc_vport *vport = cmdiocb->vport;
895
896 if (irsp->ulpStatus == IOSTAT_SUCCESS)
897 vport->ct_flags |= FC_CT_RSNN_NN;
898 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
899 return;
900}
901
902static void
903lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
904 struct lpfc_iocbq *rspiocb)
905{
906 struct lpfc_vport *vport = cmdiocb->vport;
907
908 /* even if it fails we will act as though it succeeded. */
909 vport->ct_flags = 0;
910 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500911 return;
912}
913
James Smart2fb9bd82006-12-02 13:33:57 -0500914static void
James Smart92d7f7b2007-06-17 19:56:38 -0500915lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
916 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -0500917{
James Smart92d7f7b2007-06-17 19:56:38 -0500918 IOCB_t *irsp = &rspiocb->iocb;
919 struct lpfc_vport *vport = cmdiocb->vport;
920
James Smart7ee5d432007-10-27 13:37:17 -0400921 if (irsp->ulpStatus == IOSTAT_SUCCESS)
922 vport->ct_flags |= FC_CT_RFF_ID;
923 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -0500924 return;
925}
926
James Smart311464e2007-08-02 11:10:37 -0400927static int
James Smart92d7f7b2007-06-17 19:56:38 -0500928lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
929 size_t size)
930{
931 int n;
932 uint8_t *wwn = vport->phba->wwpn;
933
934 n = snprintf(symbol, size,
935 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
936 wwn[0], wwn[1], wwn[2], wwn[3],
937 wwn[4], wwn[5], wwn[6], wwn[7]);
938
939 if (vport->port_type == LPFC_PHYSICAL_PORT)
940 return n;
941
942 if (n < size)
943 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
944
945 if (n < size && vport->vname)
946 n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
947 return n;
948}
949
950int
951lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
952 size_t size)
dea31012005-04-17 16:05:31 -0500953{
954 char fwrev[16];
James Smart92d7f7b2007-06-17 19:56:38 -0500955 int n;
dea31012005-04-17 16:05:31 -0500956
James Smart92d7f7b2007-06-17 19:56:38 -0500957 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -0500958
James Smart92d7f7b2007-06-17 19:56:38 -0500959 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
960 vport->phba->ModelName, fwrev, lpfc_release_version);
961 return n;
dea31012005-04-17 16:05:31 -0500962}
963
964/*
965 * lpfc_ns_cmd
966 * Description:
967 * Issue Cmd to NameServer
968 * SLI_CTNS_GID_FT
969 * LI_CTNS_RFT_ID
970 */
971int
James Smart92d7f7b2007-06-17 19:56:38 -0500972lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
973 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -0500974{
James Smart92d7f7b2007-06-17 19:56:38 -0500975 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500976 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500977 struct lpfc_dmabuf *mp, *bmp;
978 struct lpfc_sli_ct_request *CtReq;
979 struct ulp_bde64 *bpl;
980 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
981 struct lpfc_iocbq *) = NULL;
982 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -0500983 size_t size;
James Smart858c9f62007-06-17 19:56:39 -0500984 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500985
986 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart858c9f62007-06-17 19:56:39 -0500987 if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
988 rc=1;
989 goto ns_cmd_exit;
990 }
dea31012005-04-17 16:05:31 -0500991
992 /* fill in BDEs for command */
993 /* Allocate buffer for command payload */
994 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -0500995 if (!mp) {
996 rc=2;
dea31012005-04-17 16:05:31 -0500997 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -0500998 }
dea31012005-04-17 16:05:31 -0500999
1000 INIT_LIST_HEAD(&mp->list);
1001 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001002 if (!mp->virt) {
1003 rc=3;
dea31012005-04-17 16:05:31 -05001004 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001005 }
dea31012005-04-17 16:05:31 -05001006
1007 /* Allocate buffer for Buffer ptr list */
1008 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001009 if (!bmp) {
1010 rc=4;
dea31012005-04-17 16:05:31 -05001011 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001012 }
dea31012005-04-17 16:05:31 -05001013
1014 INIT_LIST_HEAD(&bmp->list);
1015 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001016 if (!bmp->virt) {
1017 rc=5;
dea31012005-04-17 16:05:31 -05001018 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001019 }
dea31012005-04-17 16:05:31 -05001020
1021 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001022 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1023 "0236 NameServer Req Data: x%x x%x x%x\n",
1024 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001025
1026 bpl = (struct ulp_bde64 *) bmp->virt;
1027 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001028 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1029 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001030 bpl->tus.f.bdeFlags = 0;
1031 if (cmdcode == SLI_CTNS_GID_FT)
1032 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001033 else if (cmdcode == SLI_CTNS_GFF_ID)
1034 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001035 else if (cmdcode == SLI_CTNS_RFT_ID)
1036 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1037 else if (cmdcode == SLI_CTNS_RNN_ID)
1038 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001039 else if (cmdcode == SLI_CTNS_RSPN_ID)
1040 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001041 else if (cmdcode == SLI_CTNS_RSNN_NN)
1042 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001043 else if (cmdcode == SLI_CTNS_DA_ID)
1044 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001045 else if (cmdcode == SLI_CTNS_RFF_ID)
1046 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001047 else
1048 bpl->tus.f.bdeSize = 0;
1049 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1050
1051 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1052 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1053 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1054 CtReq->RevisionId.bits.InId = 0;
1055 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1056 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1057 CtReq->CommandResponse.bits.Size = 0;
1058 switch (cmdcode) {
1059 case SLI_CTNS_GID_FT:
1060 CtReq->CommandResponse.bits.CmdRsp =
1061 be16_to_cpu(SLI_CTNS_GID_FT);
1062 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001063 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001064 vport->port_state = LPFC_NS_QRY;
1065 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001066 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1067 rsp_size = FC_MAX_NS_RSP;
1068 break;
1069
James Smart92d7f7b2007-06-17 19:56:38 -05001070 case SLI_CTNS_GFF_ID:
1071 CtReq->CommandResponse.bits.CmdRsp =
1072 be16_to_cpu(SLI_CTNS_GFF_ID);
1073 CtReq->un.gff.PortId = be32_to_cpu(context);
1074 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1075 break;
1076
dea31012005-04-17 16:05:31 -05001077 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001078 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001079 CtReq->CommandResponse.bits.CmdRsp =
1080 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart2e0fef82007-06-17 19:56:36 -05001081 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001082 CtReq->un.rft.fcpReg = 1;
1083 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1084 break;
1085
1086 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001087 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001088 CtReq->CommandResponse.bits.CmdRsp =
1089 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart2e0fef82007-06-17 19:56:36 -05001090 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
1091 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001092 sizeof (struct lpfc_name));
1093 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1094 break;
1095
James Smart92d7f7b2007-06-17 19:56:38 -05001096 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001097 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001098 CtReq->CommandResponse.bits.CmdRsp =
1099 be16_to_cpu(SLI_CTNS_RSPN_ID);
1100 CtReq->un.rspn.PortId = be32_to_cpu(vport->fc_myDID);
1101 size = sizeof(CtReq->un.rspn.symbname);
1102 CtReq->un.rspn.len =
1103 lpfc_vport_symbolic_port_name(vport,
1104 CtReq->un.rspn.symbname, size);
1105 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1106 break;
dea31012005-04-17 16:05:31 -05001107 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001108 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001109 CtReq->CommandResponse.bits.CmdRsp =
1110 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001111 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001112 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001113 size = sizeof(CtReq->un.rsnn.symbname);
1114 CtReq->un.rsnn.len =
1115 lpfc_vport_symbolic_node_name(vport,
1116 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001117 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1118 break;
James Smart7ee5d432007-10-27 13:37:17 -04001119 case SLI_CTNS_DA_ID:
1120 /* Implement DA_ID Nameserver request */
1121 CtReq->CommandResponse.bits.CmdRsp =
1122 be16_to_cpu(SLI_CTNS_DA_ID);
1123 CtReq->un.da_id.port_id = be32_to_cpu(vport->fc_myDID);
1124 cmpl = lpfc_cmpl_ct_cmd_da_id;
1125 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001126 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001127 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001128 CtReq->CommandResponse.bits.CmdRsp =
1129 be16_to_cpu(SLI_CTNS_RFF_ID);
1130 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);;
1131 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1132 CtReq->un.rff.type_code = FC_FCP_DATA;
1133 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1134 break;
dea31012005-04-17 16:05:31 -05001135 }
James Smart51ef4c22007-08-02 11:10:31 -04001136 lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001137
James Smart858c9f62007-06-17 19:56:39 -05001138 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001139 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1141 "Issue CT cmd: cmd:x%x did:x%x",
1142 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001143 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001144 }
dea31012005-04-17 16:05:31 -05001145
James Smart858c9f62007-06-17 19:56:39 -05001146 rc=6;
James Smart51ef4c22007-08-02 11:10:31 -04001147 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001148 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1149ns_cmd_free_bmp:
1150 kfree(bmp);
1151ns_cmd_free_mpvirt:
1152 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1153ns_cmd_free_mp:
1154 kfree(mp);
1155ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001156 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1157 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1158 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001159 return 1;
1160}
1161
1162static void
James Smart2e0fef82007-06-17 19:56:36 -05001163lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1164 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001165{
dea31012005-04-17 16:05:31 -05001166 struct lpfc_dmabuf *inp = cmdiocb->context1;
1167 struct lpfc_dmabuf *outp = cmdiocb->context2;
1168 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1169 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1170 struct lpfc_nodelist *ndlp;
1171 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1172 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001173 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001174 IOCB_t *irsp = &rspiocb->iocb;
1175 uint32_t latt;
1176
1177 latt = lpfc_els_chk_latt(vport);
1178
1179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1180 "FDMI cmpl: status:x%x/x%x latt:%d",
1181 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1182
1183 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001184 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1185 "0229 FDMI cmd %04x failed, latt = %d "
1186 "ulpStatus: x%x, rid x%x\n",
1187 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1188 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001189 lpfc_ct_free_iocb(phba, cmdiocb);
1190 return;
1191 }
dea31012005-04-17 16:05:31 -05001192
James Smart2e0fef82007-06-17 19:56:36 -05001193 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001194 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1195 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001196 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1197 "0220 FDMI rsp failed Data: x%x\n",
1198 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001199 }
1200
1201 switch (be16_to_cpu(fdmi_cmd)) {
1202 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001203 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001204 break;
1205
1206 case SLI_MGMT_RPA:
1207 break;
1208
1209 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001210 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001211 break;
1212
1213 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001214 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001215 break;
1216 }
James Smart858c9f62007-06-17 19:56:39 -05001217 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001218 return;
1219}
James Smart2e0fef82007-06-17 19:56:36 -05001220
dea31012005-04-17 16:05:31 -05001221int
James Smart2e0fef82007-06-17 19:56:36 -05001222lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001223{
James Smart2e0fef82007-06-17 19:56:36 -05001224 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001225 struct lpfc_dmabuf *mp, *bmp;
1226 struct lpfc_sli_ct_request *CtReq;
1227 struct ulp_bde64 *bpl;
1228 uint32_t size;
1229 REG_HBA *rh;
1230 PORT_ENTRY *pe;
1231 REG_PORT_ATTRIBUTE *pab;
1232 ATTRIBUTE_BLOCK *ab;
1233 ATTRIBUTE_ENTRY *ae;
1234 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1235 struct lpfc_iocbq *);
1236
1237
1238 /* fill in BDEs for command */
1239 /* Allocate buffer for command payload */
1240 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1241 if (!mp)
1242 goto fdmi_cmd_exit;
1243
1244 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1245 if (!mp->virt)
1246 goto fdmi_cmd_free_mp;
1247
1248 /* Allocate buffer for Buffer ptr list */
1249 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1250 if (!bmp)
1251 goto fdmi_cmd_free_mpvirt;
1252
1253 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1254 if (!bmp->virt)
1255 goto fdmi_cmd_free_bmp;
1256
1257 INIT_LIST_HEAD(&mp->list);
1258 INIT_LIST_HEAD(&bmp->list);
1259
1260 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001261 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1262 "0218 FDMI Request Data: x%x x%x x%x\n",
1263 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001264 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1265
1266 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1267 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1268 CtReq->RevisionId.bits.InId = 0;
1269
1270 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1271 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1272 size = 0;
1273
1274 switch (cmdcode) {
1275 case SLI_MGMT_RHBA:
1276 {
1277 lpfc_vpd_t *vp = &phba->vpd;
1278 uint32_t i, j, incr;
1279 int len;
1280
1281 CtReq->CommandResponse.bits.CmdRsp =
1282 be16_to_cpu(SLI_MGMT_RHBA);
1283 CtReq->CommandResponse.bits.Size = 0;
1284 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001285 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001286 sizeof (struct lpfc_name));
1287 /* One entry (port) per adapter */
1288 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001289 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001290 sizeof (struct lpfc_name));
1291
1292 /* point to the HBA attribute block */
1293 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1294 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1295 ab->EntryCnt = 0;
1296
1297 /* Point to the beginning of the first HBA attribute
1298 entry */
1299 /* #1 HBA attribute entry */
1300 size += FOURBYTES;
1301 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1302 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1303 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1304 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001305 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001306 sizeof (struct lpfc_name));
1307 ab->EntryCnt++;
1308 size += FOURBYTES + sizeof (struct lpfc_name);
1309
1310 /* #2 HBA attribute entry */
1311 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1312 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1313 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1314 len = strlen(ae->un.Manufacturer);
1315 len += (len & 3) ? (4 - (len & 3)) : 4;
1316 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1317 ab->EntryCnt++;
1318 size += FOURBYTES + len;
1319
1320 /* #3 HBA attribute entry */
1321 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1322 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1323 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1324 len = strlen(ae->un.SerialNumber);
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 /* #4 HBA attribute entry */
1331 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1332 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1333 strcpy(ae->un.Model, phba->ModelName);
1334 len = strlen(ae->un.Model);
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 /* #5 HBA attribute entry */
1341 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1342 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1343 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1344 len = strlen(ae->un.ModelDescription);
1345 len += (len & 3) ? (4 - (len & 3)) : 4;
1346 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1347 ab->EntryCnt++;
1348 size += FOURBYTES + len;
1349
1350 /* #6 HBA attribute entry */
1351 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1352 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1353 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1354 /* Convert JEDEC ID to ascii for hardware version */
1355 incr = vp->rev.biuRev;
1356 for (i = 0; i < 8; i++) {
1357 j = (incr & 0xf);
1358 if (j <= 9)
1359 ae->un.HardwareVersion[7 - i] =
1360 (char)((uint8_t) 0x30 +
1361 (uint8_t) j);
1362 else
1363 ae->un.HardwareVersion[7 - i] =
1364 (char)((uint8_t) 0x61 +
1365 (uint8_t) (j - 10));
1366 incr = (incr >> 4);
1367 }
1368 ab->EntryCnt++;
1369 size += FOURBYTES + 8;
1370
1371 /* #7 HBA attribute entry */
1372 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1373 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1374 strcpy(ae->un.DriverVersion, lpfc_release_version);
1375 len = strlen(ae->un.DriverVersion);
1376 len += (len & 3) ? (4 - (len & 3)) : 4;
1377 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1378 ab->EntryCnt++;
1379 size += FOURBYTES + len;
1380
1381 /* #8 HBA attribute entry */
1382 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1383 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1384 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1385 len = strlen(ae->un.OptionROMVersion);
1386 len += (len & 3) ? (4 - (len & 3)) : 4;
1387 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1388 ab->EntryCnt++;
1389 size += FOURBYTES + len;
1390
1391 /* #9 HBA attribute entry */
1392 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1393 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1394 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1395 1);
1396 len = strlen(ae->un.FirmwareVersion);
1397 len += (len & 3) ? (4 - (len & 3)) : 4;
1398 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1399 ab->EntryCnt++;
1400 size += FOURBYTES + len;
1401
1402 /* #10 HBA attribute entry */
1403 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1404 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1405 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001406 init_utsname()->sysname,
1407 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001408 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001409 len = strlen(ae->un.OsNameVersion);
1410 len += (len & 3) ? (4 - (len & 3)) : 4;
1411 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1412 ab->EntryCnt++;
1413 size += FOURBYTES + len;
1414
1415 /* #11 HBA attribute entry */
1416 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1417 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1418 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1419 ae->un.MaxCTPayloadLen = (65 * 4096);
1420 ab->EntryCnt++;
1421 size += FOURBYTES + 4;
1422
1423 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1424 /* Total size */
1425 size = GID_REQUEST_SZ - 4 + size;
1426 }
1427 break;
1428
1429 case SLI_MGMT_RPA:
1430 {
1431 lpfc_vpd_t *vp;
1432 struct serv_parm *hsp;
1433 int len;
1434
1435 vp = &phba->vpd;
1436
1437 CtReq->CommandResponse.bits.CmdRsp =
1438 be16_to_cpu(SLI_MGMT_RPA);
1439 CtReq->CommandResponse.bits.Size = 0;
1440 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1441 size = sizeof (struct lpfc_name) + FOURBYTES;
1442 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001443 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001444 sizeof (struct lpfc_name));
1445 pab->ab.EntryCnt = 0;
1446
1447 /* #1 Port attribute entry */
1448 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1449 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1450 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1451 ae->un.SupportFC4Types[2] = 1;
1452 ae->un.SupportFC4Types[7] = 1;
1453 pab->ab.EntryCnt++;
1454 size += FOURBYTES + 32;
1455
1456 /* #2 Port attribute entry */
1457 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1458 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1459 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001460
1461 ae->un.SupportSpeed = 0;
1462 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001463 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001464 if (phba->lmt & LMT_8Gb)
1465 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1466 if (phba->lmt & LMT_4Gb)
1467 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1468 if (phba->lmt & LMT_2Gb)
1469 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1470 if (phba->lmt & LMT_1Gb)
1471 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1472
dea31012005-04-17 16:05:31 -05001473 pab->ab.EntryCnt++;
1474 size += FOURBYTES + 4;
1475
1476 /* #3 Port attribute entry */
1477 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1478 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1479 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1480 switch(phba->fc_linkspeed) {
1481 case LA_1GHZ_LINK:
1482 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1483 break;
1484 case LA_2GHZ_LINK:
1485 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1486 break;
1487 case LA_4GHZ_LINK:
1488 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1489 break;
James Smartb87eab32007-04-25 09:53:28 -04001490 case LA_8GHZ_LINK:
1491 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1492 break;
dea31012005-04-17 16:05:31 -05001493 default:
1494 ae->un.PortSpeed =
1495 HBA_PORTSPEED_UNKNOWN;
1496 break;
1497 }
1498 pab->ab.EntryCnt++;
1499 size += FOURBYTES + 4;
1500
1501 /* #4 Port attribute entry */
1502 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1503 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1504 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001505 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001506 ae->un.MaxFrameSize =
1507 (((uint32_t) hsp->cmn.
1508 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1509 bbRcvSizeLsb;
1510 pab->ab.EntryCnt++;
1511 size += FOURBYTES + 4;
1512
1513 /* #5 Port attribute entry */
1514 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1515 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1516 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1517 len = strlen((char *)ae->un.OsDeviceName);
1518 len += (len & 3) ? (4 - (len & 3)) : 4;
1519 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1520 pab->ab.EntryCnt++;
1521 size += FOURBYTES + len;
1522
James Smart3de2a652007-08-02 11:09:59 -04001523 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001524 /* #6 Port attribute entry */
1525 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1526 size);
1527 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1528 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001529 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001530 len = strlen(ae->un.HostName);
1531 len += (len & 3) ? (4 - (len & 3)) : 4;
1532 ae->ad.bits.AttrLen =
1533 be16_to_cpu(FOURBYTES + len);
1534 pab->ab.EntryCnt++;
1535 size += FOURBYTES + len;
1536 }
1537
1538 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1539 /* Total size */
1540 size = GID_REQUEST_SZ - 4 + size;
1541 }
1542 break;
1543
1544 case SLI_MGMT_DHBA:
1545 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1546 CtReq->CommandResponse.bits.Size = 0;
1547 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1548 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001549 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001550 sizeof (struct lpfc_name));
1551 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1552 break;
1553
1554 case SLI_MGMT_DPRT:
1555 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1556 CtReq->CommandResponse.bits.Size = 0;
1557 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1558 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001559 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001560 sizeof (struct lpfc_name));
1561 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1562 break;
1563 }
1564
1565 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001566 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1567 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001568 bpl->tus.f.bdeFlags = 0;
1569 bpl->tus.f.bdeSize = size;
1570 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1571
1572 cmpl = lpfc_cmpl_ct_cmd_fdmi;
James Smart51ef4c22007-08-02 11:10:31 -04001573 lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001574
James Smart92d7f7b2007-06-17 19:56:38 -05001575 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001576 return 0;
1577
James Smart51ef4c22007-08-02 11:10:31 -04001578 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001579 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1580fdmi_cmd_free_bmp:
1581 kfree(bmp);
1582fdmi_cmd_free_mpvirt:
1583 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1584fdmi_cmd_free_mp:
1585 kfree(mp);
1586fdmi_cmd_exit:
1587 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001588 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1589 "0244 Issue FDMI request failed Data: x%x\n",
1590 cmdcode);
dea31012005-04-17 16:05:31 -05001591 return 1;
1592}
1593
1594void
1595lpfc_fdmi_tmo(unsigned long ptr)
1596{
James Smart2e0fef82007-06-17 19:56:36 -05001597 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1598 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001599 unsigned long iflag;
1600
James Smart2e0fef82007-06-17 19:56:36 -05001601 spin_lock_irqsave(&vport->work_port_lock, iflag);
1602 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1603 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05001604 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1605
1606 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001607 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001608 lpfc_worker_wake_up(phba);
1609 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001610 }
James Smart92d7f7b2007-06-17 19:56:38 -05001611 else
1612 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05001613}
1614
1615void
James Smart2e0fef82007-06-17 19:56:36 -05001616lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001617{
1618 struct lpfc_nodelist *ndlp;
1619
James Smart2e0fef82007-06-17 19:56:36 -05001620 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001621 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001622 if (init_utsname()->nodename[0] != '\0')
1623 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1624 else
1625 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001626 }
dea31012005-04-17 16:05:31 -05001627 return;
1628}
1629
dea31012005-04-17 16:05:31 -05001630void
James Smart2e0fef82007-06-17 19:56:36 -05001631lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001632{
1633 struct lpfc_sli *psli = &phba->sli;
1634 lpfc_vpd_t *vp = &phba->vpd;
1635 uint32_t b1, b2, b3, b4, i, rev;
1636 char c;
1637 uint32_t *ptr, str[4];
1638 uint8_t *fwname;
1639
1640 if (vp->rev.rBit) {
1641 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1642 rev = vp->rev.sli2FwRev;
1643 else
1644 rev = vp->rev.sli1FwRev;
1645
1646 b1 = (rev & 0x0000f000) >> 12;
1647 b2 = (rev & 0x00000f00) >> 8;
1648 b3 = (rev & 0x000000c0) >> 6;
1649 b4 = (rev & 0x00000030) >> 4;
1650
1651 switch (b4) {
1652 case 0:
1653 c = 'N';
1654 break;
1655 case 1:
1656 c = 'A';
1657 break;
1658 case 2:
1659 c = 'B';
1660 break;
1661 default:
1662 c = 0;
1663 break;
1664 }
1665 b4 = (rev & 0x0000000f);
1666
1667 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1668 fwname = vp->rev.sli2FwName;
1669 else
1670 fwname = vp->rev.sli1FwName;
1671
1672 for (i = 0; i < 16; i++)
1673 if (fwname[i] == 0x20)
1674 fwname[i] = 0;
1675
1676 ptr = (uint32_t*)fwname;
1677
1678 for (i = 0; i < 3; i++)
1679 str[i] = be32_to_cpu(*ptr++);
1680
1681 if (c == 0) {
1682 if (flag)
1683 sprintf(fwrevision, "%d.%d%d (%s)",
1684 b1, b2, b3, (char *)str);
1685 else
1686 sprintf(fwrevision, "%d.%d%d", b1,
1687 b2, b3);
1688 } else {
1689 if (flag)
1690 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1691 b1, b2, b3, c,
1692 b4, (char *)str);
1693 else
1694 sprintf(fwrevision, "%d.%d%d%c%d",
1695 b1, b2, b3, c, b4);
1696 }
1697 } else {
1698 rev = vp->rev.smFwRev;
1699
1700 b1 = (rev & 0xff000000) >> 24;
1701 b2 = (rev & 0x00f00000) >> 20;
1702 b3 = (rev & 0x000f0000) >> 16;
1703 c = (rev & 0x0000ff00) >> 8;
1704 b4 = (rev & 0x000000ff);
1705
1706 if (flag)
1707 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1708 b2, b3, c, b4);
1709 else
1710 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1711 b2, b3, c, b4);
1712 }
1713 return;
1714}