blob: 4164b935ea9f90419fee69a6d057d42e27b54483 [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 Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 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/*
James Smart09372822008-01-11 01:52:54 -050022 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea31012005-04-17 16:05:31 -050023 */
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"
James Smartea2151b2008-09-07 11:52:10 -040037#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_disc.h"
39#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_crtn.h"
43#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050044#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050045#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050046
47#define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
48 * incapable of reporting */
49#define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
50#define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
51#define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
52#define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
53#define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
54#define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
55
56#define FOURBYTES 4
57
58
59static char *lpfc_release_version = LPFC_DRIVER_VERSION;
60
James Smarted957682007-06-17 19:56:37 -050061static void
62lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050063 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050064{
James Smarted957682007-06-17 19:56:37 -050065 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050066 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040067 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050068 "status = x%x\n",
69 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050070 }
James Smart9c2face2008-01-11 01:53:18 -050071 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
72 "0145 Ignoring unsolicted CT HBQ Size:%d "
73 "status = x%x\n",
74 size, piocbq->iocb.ulpStatus);
75}
76
77static void
78lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
79 struct lpfc_dmabuf *mp, uint32_t size)
80{
81 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -050082}
83
dea31012005-04-17 16:05:31 -050084void
James Smart2e0fef82007-06-17 19:56:36 -050085lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
86 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -050087{
James Smart92d7f7b2007-06-17 19:56:38 -050088
James Smarted957682007-06-17 19:56:37 -050089 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -050090 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -050091 int i;
92 struct lpfc_iocbq *iocbq;
93 dma_addr_t paddr;
94 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -050095 struct list_head head;
96 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -050097
98 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
99 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
100 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
101 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500102 /* Not enough posted buffers; Try posting more buffers */
103 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500104 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400105 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500106 return;
107 }
108
109 /* If there are no BDEs associated with this IOCB,
110 * there is nothing to do.
111 */
112 if (icmd->ulpBdeCount == 0)
113 return;
114
James Smarted957682007-06-17 19:56:37 -0500115 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500116 INIT_LIST_HEAD(&head);
117 list_add_tail(&head, &piocbq->list);
118 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500119 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500120 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500121 continue;
James Smart9c2face2008-01-11 01:53:18 -0500122 bdeBuf = iocbq->context2;
123 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500124 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500125 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
126 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500127 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500128 bdeBuf = iocbq->context3;
129 iocbq->context3 = NULL;
130 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
131 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
132 size);
133 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500134 }
dea31012005-04-17 16:05:31 -0500135 }
James Smart9c2face2008-01-11 01:53:18 -0500136 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500137 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500141 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500142 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400143 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500144 for (i = 0; i < icmd->ulpBdeCount; i++) {
145 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
146 icmd->un.cont64[i].addrLow);
147 mp = lpfc_sli_ringpostbuf_get(phba, pring,
148 paddr);
149 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400150 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500151 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500152 }
James Smart495a7142008-06-14 22:52:59 -0400153 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500154 }
James Smartd7c255b2008-08-24 21:50:00 -0400155 list_del(&head);
dea31012005-04-17 16:05:31 -0500156 }
dea31012005-04-17 16:05:31 -0500157}
158
159static void
James Smart2e0fef82007-06-17 19:56:36 -0500160lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500161{
162 struct lpfc_dmabuf *mlast, *next_mlast;
163
164 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
165 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
166 list_del(&mlast->list);
167 kfree(mlast);
168 }
169 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
170 kfree(mlist);
171 return;
172}
173
174static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500175lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500176 uint32_t size, int *entries)
177{
178 struct lpfc_dmabuf *mlist = NULL;
179 struct lpfc_dmabuf *mp;
180 int cnt, i = 0;
181
James Smart09372822008-01-11 01:52:54 -0500182 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500183 cnt = size > FCELSSIZE ? FCELSSIZE: size;
184
185 while (size) {
186 /* Allocate buffer for rsp payload */
187 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
188 if (!mp) {
189 if (mlist)
190 lpfc_free_ct_rsp(phba, mlist);
191 return NULL;
192 }
193
194 INIT_LIST_HEAD(&mp->list);
195
James Smart92d7f7b2007-06-17 19:56:38 -0500196 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
197 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500198 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
199 else
200 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
201
202 if (!mp->virt) {
203 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700204 if (mlist)
205 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500206 return NULL;
207 }
208
209 /* Queue it to a linked list */
210 if (!mlist)
211 mlist = mp;
212 else
213 list_add_tail(&mp->list, &mlist->list);
214
James Smart34b02dc2008-08-24 21:49:55 -0400215 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500216 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500217 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
218 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500219 bpl->tus.f.bdeSize = (uint16_t) cnt;
220 bpl->tus.w = le32_to_cpu(bpl->tus.w);
221 bpl++;
222
223 i++;
224 size -= cnt;
225 }
226
227 *entries = i;
228 return mlist;
229}
230
James Smart858c9f62007-06-17 19:56:39 -0500231int
232lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
233{
234 struct lpfc_dmabuf *buf_ptr;
235
James Smart51ef4c22007-08-02 11:10:31 -0400236 if (ctiocb->context_un.ndlp) {
237 lpfc_nlp_put(ctiocb->context_un.ndlp);
238 ctiocb->context_un.ndlp = NULL;
239 }
James Smart858c9f62007-06-17 19:56:39 -0500240 if (ctiocb->context1) {
241 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
242 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
243 kfree(buf_ptr);
244 ctiocb->context1 = NULL;
245 }
246 if (ctiocb->context2) {
247 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
248 ctiocb->context2 = NULL;
249 }
250
251 if (ctiocb->context3) {
252 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
253 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
254 kfree(buf_ptr);
255 ctiocb->context1 = NULL;
256 }
257 lpfc_sli_release_iocbq(phba, ctiocb);
258 return 0;
259}
260
dea31012005-04-17 16:05:31 -0500261static int
James Smart2e0fef82007-06-17 19:56:36 -0500262lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500263 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
264 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
265 struct lpfc_iocbq *),
266 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500267 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500268{
James Smart2e0fef82007-06-17 19:56:36 -0500269 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500270 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400271 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500272 int rc;
dea31012005-04-17 16:05:31 -0500273
274 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400275 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500276
277 if (geniocb == NULL)
278 return 1;
dea31012005-04-17 16:05:31 -0500279
280 icmd = &geniocb->iocb;
281 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
282 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
283 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400284 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea31012005-04-17 16:05:31 -0500285 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
286
287 if (usr_flg)
288 geniocb->context3 = NULL;
289 else
290 geniocb->context3 = (uint8_t *) bmp;
291
292 /* Save for completion so we can release these resources */
293 geniocb->context1 = (uint8_t *) inp;
294 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500295 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500296
297 /* Fill in payload, bp points to frame payload */
298 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
299
300 /* Fill in rest of iocb */
301 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
302 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
303 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
304 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
305
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500306 if (!tmo) {
307 /* FC spec states we need 3 * ratov for CT requests */
308 tmo = (3 * phba->fc_ratov);
309 }
dea31012005-04-17 16:05:31 -0500310 icmd->ulpTimeout = tmo;
311 icmd->ulpBdeCount = 1;
312 icmd->ulpLe = 1;
313 icmd->ulpClass = CLASS3;
314 icmd->ulpContext = ndlp->nlp_rpi;
315
James Smart92d7f7b2007-06-17 19:56:38 -0500316 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
317 /* For GEN_REQUEST64_CR, use the RPI */
318 icmd->ulpCt_h = 0;
319 icmd->ulpCt_l = 0;
320 }
321
dea31012005-04-17 16:05:31 -0500322 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0119 Issue GEN REQ IOCB to NPORT x%x "
325 "Data: x%x x%x\n",
326 ndlp->nlp_DID, icmd->ulpIoTag,
327 vport->port_state);
dea31012005-04-17 16:05:31 -0500328 geniocb->iocb_cmpl = cmpl;
329 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500330 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500331 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400332 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500333
334 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500335 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500336 return 1;
337 }
dea31012005-04-17 16:05:31 -0500338
339 return 0;
340}
341
342static int
James Smart2e0fef82007-06-17 19:56:36 -0500343lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500344 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
345 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
346 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500347 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500348{
James Smart2e0fef82007-06-17 19:56:36 -0500349 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500350 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
351 struct lpfc_dmabuf *outmp;
352 int cnt = 0, status;
353 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
354 CommandResponse.bits.CmdRsp;
355
356 bpl++; /* Skip past ct request */
357
358 /* Put buffer(s) for ct rsp in bpl */
359 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
360 if (!outmp)
361 return -ENOMEM;
362
James Smart2e0fef82007-06-17 19:56:36 -0500363 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart92d7f7b2007-06-17 19:56:38 -0500364 cnt+1, 0, retry);
dea31012005-04-17 16:05:31 -0500365 if (status) {
366 lpfc_free_ct_rsp(phba, outmp);
367 return -ENOMEM;
368 }
369 return 0;
370}
371
James Smart549e55c2007-08-02 11:09:51 -0400372struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500373lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500374 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400375 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500376
James Smart549e55c2007-08-02 11:09:51 -0400377 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500378 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400379 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
380 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500381 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400382 }
James Smart92d7f7b2007-06-17 19:56:38 -0500383 }
James Smart549e55c2007-08-02 11:09:51 -0400384 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500385 return NULL;
386}
387
dea31012005-04-17 16:05:31 -0500388static int
James Smart2e0fef82007-06-17 19:56:36 -0500389lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500390{
James Smart2e0fef82007-06-17 19:56:36 -0500391 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500392 struct lpfc_sli_ct_request *Response =
393 (struct lpfc_sli_ct_request *) mp->virt;
394 struct lpfc_nodelist *ndlp = NULL;
395 struct lpfc_dmabuf *mlast, *next_mp;
396 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500397 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500398 int Cnt;
399 struct list_head head;
400
James Smart2e0fef82007-06-17 19:56:36 -0500401 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500402 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500403 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500404
dea31012005-04-17 16:05:31 -0500405
406 list_add_tail(&head, &mp->list);
407 list_for_each_entry_safe(mp, next_mp, &head, list) {
408 mlast = mp;
409
James Smart7054a602007-04-25 09:52:34 -0400410 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
411
dea31012005-04-17 16:05:31 -0500412 Size -= Cnt;
413
James Smart1dcb58e2007-04-25 09:51:30 -0400414 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500415 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400416 } else
dea31012005-04-17 16:05:31 -0500417 Cnt -= 16; /* subtract length of CT header */
418
419 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400420 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500421 /* Get next DID from NameServer List */
422 CTentry = *ctptr++;
423 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500424
dea31012005-04-17 16:05:31 -0500425 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500426
427 /*
428 * Check for rscn processing or not
429 * To conserve rpi's, filter out addresses for other
430 * vports on the same physical HBAs.
431 */
432 if ((Did != vport->fc_myDID) &&
433 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400434 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500435 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart98c9ea52007-10-27 13:37:33 -0400436 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
James Smart3de2a652007-08-02 11:09:59 -0400437 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500438 ndlp = lpfc_setup_disc_node(vport, Did);
James Smart58da1ff2008-04-07 10:15:56 -0400439 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500440 lpfc_debugfs_disc_trc(vport,
441 LPFC_DISC_TRC_CT,
442 "Parse GID_FTrsp: "
443 "did:x%x flg:x%x x%x",
444 Did, ndlp->nlp_flag,
445 vport->fc_flag);
446
James Smarte8b62012007-08-02 11:10:09 -0400447 lpfc_printf_vlog(vport,
448 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500449 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400450 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500451 "x%x NameServer Rsp"
452 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400453 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500454 vport->fc_flag,
455 vport->fc_rscn_id_cnt);
456 } else {
James Smart858c9f62007-06-17 19:56:39 -0500457 lpfc_debugfs_disc_trc(vport,
458 LPFC_DISC_TRC_CT,
459 "Skip1 GID_FTrsp: "
460 "did:x%x flg:x%x cnt:%d",
461 Did, vport->fc_flag,
462 vport->fc_rscn_id_cnt);
463
James Smarte8b62012007-08-02 11:10:09 -0400464 lpfc_printf_vlog(vport,
465 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500466 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400467 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500468 "NameServer Rsp Data: "
469 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400470 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500471 vport->fc_rscn_id_cnt);
472 }
473
474 } else {
475 if (!(vport->fc_flag & FC_RSCN_MODE) ||
476 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500477 lpfc_debugfs_disc_trc(vport,
478 LPFC_DISC_TRC_CT,
479 "Query GID_FTrsp: "
480 "did:x%x flg:x%x cnt:%d",
481 Did, vport->fc_flag,
482 vport->fc_rscn_id_cnt);
483
James Smart0ff10d42008-01-11 01:52:36 -0500484 /* This NPortID was previously
485 * a FCP target, * Don't even
486 * bother to send GFF_ID.
487 */
488 ndlp = lpfc_findnode_did(vport,
489 Did);
James Smarte47c9092008-02-08 18:49:26 -0500490 if (ndlp &&
491 NLP_CHK_NODE_ACT(ndlp)
492 && (ndlp->nlp_type &
493 NLP_FCP_TARGET))
James Smart0ff10d42008-01-11 01:52:36 -0500494 lpfc_setup_disc_node
495 (vport, Did);
496 else if (lpfc_ns_cmd(vport,
James Smart92d7f7b2007-06-17 19:56:38 -0500497 SLI_CTNS_GFF_ID,
498 0, Did) == 0)
499 vport->num_disc_nodes++;
500 }
501 else {
James Smart858c9f62007-06-17 19:56:39 -0500502 lpfc_debugfs_disc_trc(vport,
503 LPFC_DISC_TRC_CT,
504 "Skip2 GID_FTrsp: "
505 "did:x%x flg:x%x cnt:%d",
506 Did, vport->fc_flag,
507 vport->fc_rscn_id_cnt);
508
James Smarte8b62012007-08-02 11:10:09 -0400509 lpfc_printf_vlog(vport,
510 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500511 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400512 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500513 "NameServer Rsp Data: "
514 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400515 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500516 vport->fc_rscn_id_cnt);
517 }
518 }
dea31012005-04-17 16:05:31 -0500519 }
dea31012005-04-17 16:05:31 -0500520 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
521 goto nsout1;
522 Cnt -= sizeof (uint32_t);
523 }
524 ctptr = NULL;
525
526 }
527
528nsout1:
529 list_del(&head);
dea31012005-04-17 16:05:31 -0500530 return 0;
531}
532
dea31012005-04-17 16:05:31 -0500533static void
James Smart2e0fef82007-06-17 19:56:36 -0500534lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
535 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500536{
James Smart2e0fef82007-06-17 19:56:36 -0500537 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500539 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500540 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500541 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500542 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400543 struct lpfc_nodelist *ndlp;
James Smart58da1ff2008-04-07 10:15:56 -0400544 int rc;
dea31012005-04-17 16:05:31 -0500545
James Smart51ef4c22007-08-02 11:10:31 -0400546 /* First save ndlp, before we overwrite it */
547 ndlp = cmdiocb->context_un.ndlp;
548
dea31012005-04-17 16:05:31 -0500549 /* we pass cmdiocb to state machine which needs rspiocb as well */
550 cmdiocb->context_un.rsp_iocb = rspiocb;
551
dea31012005-04-17 16:05:31 -0500552 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
553 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500554 irsp = &rspiocb->iocb;
555
556 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
557 "GID_FT cmpl: status:x%x/x%x rtry:%d",
558 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500559
James Smart92d7f7b2007-06-17 19:56:38 -0500560 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500561 if (vport->load_flag & FC_UNLOADING) {
562 if (vport->fc_flag & FC_RSCN_MODE)
563 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500564 goto out;
James Smarteada2722008-12-04 22:39:13 -0500565 }
James Smart92d7f7b2007-06-17 19:56:38 -0500566
James Smart58da1ff2008-04-07 10:15:56 -0400567 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400568 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
569 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500570 if (vport->fc_flag & FC_RSCN_MODE)
571 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500572 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
573 goto out;
574 }
James Smart58da1ff2008-04-07 10:15:56 -0400575 if (lpfc_error_lost_link(irsp)) {
576 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
577 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500578 if (vport->fc_flag & FC_RSCN_MODE)
579 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400580 goto out;
581 }
James Smart858c9f62007-06-17 19:56:39 -0500582 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500583 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500584 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400585 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
586 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500587 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500588
James Smart58da1ff2008-04-07 10:15:56 -0400589 /* CT command is being retried */
590 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smart92d7f7b2007-06-17 19:56:38 -0500591 vport->fc_ns_retry, 0);
James Smart58da1ff2008-04-07 10:15:56 -0400592 if (rc == 0)
593 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500594 }
James Smarteada2722008-12-04 22:39:13 -0500595 if (vport->fc_flag & FC_RSCN_MODE)
596 lpfc_els_flush_rscn(vport);
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;
James Smart0ff10d42008-01-11 01:52:36 -0500701 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500702 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 Smart0ff10d42008-01-11 01:52:36 -0500732 /* Check for retry */
733 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
734 retry = 1;
735 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
736 switch (irsp->un.ulpWord[4]) {
737 case IOERR_NO_RESOURCES:
738 /* We don't increment the retry
739 * count for this case.
740 */
741 break;
742 case IOERR_LINK_DOWN:
743 case IOERR_SLI_ABORTED:
744 case IOERR_SLI_DOWN:
745 retry = 0;
746 break;
747 default:
748 cmdiocb->retry++;
749 }
750 }
751 else
752 cmdiocb->retry++;
753
754 if (retry) {
755 /* CT command is being retried */
756 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
757 cmdiocb->retry, did);
758 if (rc == 0) {
759 /* success */
760 lpfc_ct_free_iocb(phba, cmdiocb);
761 return;
762 }
763 }
764 }
James Smarte8b62012007-08-02 11:10:09 -0400765 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
766 "0267 NameServer GFF Rsp "
767 "x%x Error (%d %d) Data: x%x x%x\n",
768 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500769 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500770 }
771
James Smart92d7f7b2007-06-17 19:56:38 -0500772 /* This is a target port, unregistered port, or the GFF_ID failed */
773 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400774 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400775 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
776 "0242 Process x%x GFF "
777 "NameServer Rsp Data: x%x x%x x%x\n",
778 did, ndlp->nlp_flag, vport->fc_flag,
779 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500780 } else {
James Smarte8b62012007-08-02 11:10:09 -0400781 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
782 "0243 Skip x%x GFF "
783 "NameServer Rsp Data: x%x x%x\n", did,
784 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500785 }
786out:
787 /* Link up / RSCN discovery */
788 if (vport->num_disc_nodes)
789 vport->num_disc_nodes--;
790 if (vport->num_disc_nodes == 0) {
791 /*
792 * The driver has cycled through all Nports in the RSCN payload.
793 * Complete the handling by cleaning up and marking the
794 * current driver state.
795 */
796 if (vport->port_state >= LPFC_DISC_AUTH) {
797 if (vport->fc_flag & FC_RSCN_MODE) {
798 lpfc_els_flush_rscn(vport);
799 spin_lock_irq(shost->host_lock);
800 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
801 spin_unlock_irq(shost->host_lock);
802 }
803 else
804 lpfc_els_flush_rscn(vport);
805 }
806 lpfc_disc_start(vport);
807 }
James Smart858c9f62007-06-17 19:56:39 -0500808 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500809 return;
810}
811
812
dea31012005-04-17 16:05:31 -0500813static void
James Smart7ee5d432007-10-27 13:37:17 -0400814lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
815 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500816{
James Smart92d7f7b2007-06-17 19:56:38 -0500817 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500818 struct lpfc_dmabuf *inp;
819 struct lpfc_dmabuf *outp;
820 IOCB_t *irsp;
821 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400822 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500823 int cmdcode, rc;
824 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500825 uint32_t latt;
dea31012005-04-17 16:05:31 -0500826
James Smart51ef4c22007-08-02 11:10:31 -0400827 /* First save ndlp, before we overwrite it */
828 ndlp = cmdiocb->context_un.ndlp;
829
dea31012005-04-17 16:05:31 -0500830 /* we pass cmdiocb to state machine which needs rspiocb as well */
831 cmdiocb->context_un.rsp_iocb = rspiocb;
832
833 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
834 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500835 irsp = &rspiocb->iocb;
836
James Smart92d7f7b2007-06-17 19:56:38 -0500837 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
838 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500839 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
840
James Smart858c9f62007-06-17 19:56:39 -0500841 latt = lpfc_els_chk_latt(vport);
842
843 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400844 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400845 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400846 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
847 latt, irsp->ulpStatus,
848 CTrsp->CommandResponse.bits.CmdRsp,
849 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500850
James Smart858c9f62007-06-17 19:56:39 -0500851 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
852 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
853 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400856 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
857 "0268 NS cmd %x Error (%d %d)\n",
858 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500859
James Smart92d7f7b2007-06-17 19:56:38 -0500860 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
861 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
862 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
863 goto out;
864
865 retry = cmdiocb->retry;
866 if (retry >= LPFC_MAX_NS_RETRY)
867 goto out;
868
869 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400870 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -0400871 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500872 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
873 if (rc == 0)
874 goto out;
875 }
876
877out:
James Smart51ef4c22007-08-02 11:10:31 -0400878 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500879 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500880 return;
881}
882
883static void
James Smart7ee5d432007-10-27 13:37:17 -0400884lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
885 struct lpfc_iocbq *rspiocb)
886{
887 IOCB_t *irsp = &rspiocb->iocb;
888 struct lpfc_vport *vport = cmdiocb->vport;
889
James Smart98c9ea52007-10-27 13:37:33 -0400890 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
891 struct lpfc_dmabuf *outp;
892 struct lpfc_sli_ct_request *CTrsp;
893
894 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
895 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
896 if (CTrsp->CommandResponse.bits.CmdRsp ==
897 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
898 vport->ct_flags |= FC_CT_RFT_ID;
899 }
James Smart7ee5d432007-10-27 13:37:17 -0400900 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
901 return;
902}
903
904static void
James Smart2e0fef82007-06-17 19:56:36 -0500905lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
906 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500907{
James Smart7ee5d432007-10-27 13:37:17 -0400908 IOCB_t *irsp = &rspiocb->iocb;
909 struct lpfc_vport *vport = cmdiocb->vport;
910
James Smart98c9ea52007-10-27 13:37:33 -0400911 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
912 struct lpfc_dmabuf *outp;
913 struct lpfc_sli_ct_request *CTrsp;
914
915 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
916 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
917 if (CTrsp->CommandResponse.bits.CmdRsp ==
918 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
919 vport->ct_flags |= FC_CT_RNN_ID;
920 }
James Smart7ee5d432007-10-27 13:37:17 -0400921 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500922 return;
923}
924
925static void
James Smart92d7f7b2007-06-17 19:56:38 -0500926lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
927 struct lpfc_iocbq *rspiocb)
928{
James Smart7ee5d432007-10-27 13:37:17 -0400929 IOCB_t *irsp = &rspiocb->iocb;
930 struct lpfc_vport *vport = cmdiocb->vport;
931
James Smart98c9ea52007-10-27 13:37:33 -0400932 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
933 struct lpfc_dmabuf *outp;
934 struct lpfc_sli_ct_request *CTrsp;
935
936 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
937 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
938 if (CTrsp->CommandResponse.bits.CmdRsp ==
939 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
940 vport->ct_flags |= FC_CT_RSPN_ID;
941 }
James Smart7ee5d432007-10-27 13:37:17 -0400942 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500943 return;
944}
945
946static void
James Smart2e0fef82007-06-17 19:56:36 -0500947lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
948 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500949{
James Smart7ee5d432007-10-27 13:37:17 -0400950 IOCB_t *irsp = &rspiocb->iocb;
951 struct lpfc_vport *vport = cmdiocb->vport;
952
James Smart98c9ea52007-10-27 13:37:33 -0400953 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
954 struct lpfc_dmabuf *outp;
955 struct lpfc_sli_ct_request *CTrsp;
956
957 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
958 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
959 if (CTrsp->CommandResponse.bits.CmdRsp ==
960 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
961 vport->ct_flags |= FC_CT_RSNN_NN;
962 }
James Smart7ee5d432007-10-27 13:37:17 -0400963 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
964 return;
965}
966
967static void
968lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
969 struct lpfc_iocbq *rspiocb)
970{
971 struct lpfc_vport *vport = cmdiocb->vport;
972
973 /* even if it fails we will act as though it succeeded. */
974 vport->ct_flags = 0;
975 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500976 return;
977}
978
James Smart2fb9bd82006-12-02 13:33:57 -0500979static void
James Smart92d7f7b2007-06-17 19:56:38 -0500980lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
981 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -0500982{
James Smart92d7f7b2007-06-17 19:56:38 -0500983 IOCB_t *irsp = &rspiocb->iocb;
984 struct lpfc_vport *vport = cmdiocb->vport;
985
James Smart98c9ea52007-10-27 13:37:33 -0400986 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
987 struct lpfc_dmabuf *outp;
988 struct lpfc_sli_ct_request *CTrsp;
989
990 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
991 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
992 if (CTrsp->CommandResponse.bits.CmdRsp ==
993 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
994 vport->ct_flags |= FC_CT_RFF_ID;
995 }
James Smart7ee5d432007-10-27 13:37:17 -0400996 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -0500997 return;
998}
999
James Smart495a7142008-06-14 22:52:59 -04001000int
James Smart92d7f7b2007-06-17 19:56:38 -05001001lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1002 size_t size)
1003{
1004 int n;
1005 uint8_t *wwn = vport->phba->wwpn;
1006
1007 n = snprintf(symbol, size,
1008 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1009 wwn[0], wwn[1], wwn[2], wwn[3],
1010 wwn[4], wwn[5], wwn[6], wwn[7]);
1011
1012 if (vport->port_type == LPFC_PHYSICAL_PORT)
1013 return n;
1014
1015 if (n < size)
1016 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1017
James Smarteada2722008-12-04 22:39:13 -05001018 if (n < size &&
1019 strlen(vport->fc_vport->symbolic_name))
1020 n += snprintf(symbol + n, size - n, " VName-%s",
1021 vport->fc_vport->symbolic_name);
James Smart92d7f7b2007-06-17 19:56:38 -05001022 return n;
1023}
1024
1025int
1026lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1027 size_t size)
dea31012005-04-17 16:05:31 -05001028{
1029 char fwrev[16];
James Smart92d7f7b2007-06-17 19:56:38 -05001030 int n;
dea31012005-04-17 16:05:31 -05001031
James Smart92d7f7b2007-06-17 19:56:38 -05001032 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001033
James Smart92d7f7b2007-06-17 19:56:38 -05001034 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1035 vport->phba->ModelName, fwrev, lpfc_release_version);
1036 return n;
dea31012005-04-17 16:05:31 -05001037}
1038
1039/*
1040 * lpfc_ns_cmd
1041 * Description:
1042 * Issue Cmd to NameServer
1043 * SLI_CTNS_GID_FT
1044 * LI_CTNS_RFT_ID
1045 */
1046int
James Smart92d7f7b2007-06-17 19:56:38 -05001047lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1048 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001049{
James Smart92d7f7b2007-06-17 19:56:38 -05001050 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001051 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001052 struct lpfc_dmabuf *mp, *bmp;
1053 struct lpfc_sli_ct_request *CtReq;
1054 struct ulp_bde64 *bpl;
1055 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1056 struct lpfc_iocbq *) = NULL;
1057 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001058 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001059 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001060
1061 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001062 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1063 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001064 rc=1;
1065 goto ns_cmd_exit;
1066 }
dea31012005-04-17 16:05:31 -05001067
1068 /* fill in BDEs for command */
1069 /* Allocate buffer for command payload */
1070 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001071 if (!mp) {
1072 rc=2;
dea31012005-04-17 16:05:31 -05001073 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001074 }
dea31012005-04-17 16:05:31 -05001075
1076 INIT_LIST_HEAD(&mp->list);
1077 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001078 if (!mp->virt) {
1079 rc=3;
dea31012005-04-17 16:05:31 -05001080 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001081 }
dea31012005-04-17 16:05:31 -05001082
1083 /* Allocate buffer for Buffer ptr list */
1084 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001085 if (!bmp) {
1086 rc=4;
dea31012005-04-17 16:05:31 -05001087 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001088 }
dea31012005-04-17 16:05:31 -05001089
1090 INIT_LIST_HEAD(&bmp->list);
1091 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001092 if (!bmp->virt) {
1093 rc=5;
dea31012005-04-17 16:05:31 -05001094 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001095 }
dea31012005-04-17 16:05:31 -05001096
1097 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001098 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1099 "0236 NameServer Req Data: x%x x%x x%x\n",
1100 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001101
1102 bpl = (struct ulp_bde64 *) bmp->virt;
1103 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001104 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1105 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001106 bpl->tus.f.bdeFlags = 0;
1107 if (cmdcode == SLI_CTNS_GID_FT)
1108 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001109 else if (cmdcode == SLI_CTNS_GFF_ID)
1110 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001111 else if (cmdcode == SLI_CTNS_RFT_ID)
1112 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1113 else if (cmdcode == SLI_CTNS_RNN_ID)
1114 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001115 else if (cmdcode == SLI_CTNS_RSPN_ID)
1116 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001117 else if (cmdcode == SLI_CTNS_RSNN_NN)
1118 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001119 else if (cmdcode == SLI_CTNS_DA_ID)
1120 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001121 else if (cmdcode == SLI_CTNS_RFF_ID)
1122 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001123 else
1124 bpl->tus.f.bdeSize = 0;
1125 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1126
1127 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1128 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1129 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1130 CtReq->RevisionId.bits.InId = 0;
1131 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1132 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1133 CtReq->CommandResponse.bits.Size = 0;
1134 switch (cmdcode) {
1135 case SLI_CTNS_GID_FT:
1136 CtReq->CommandResponse.bits.CmdRsp =
1137 be16_to_cpu(SLI_CTNS_GID_FT);
1138 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001139 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001140 vport->port_state = LPFC_NS_QRY;
1141 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001142 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1143 rsp_size = FC_MAX_NS_RSP;
1144 break;
1145
James Smart92d7f7b2007-06-17 19:56:38 -05001146 case SLI_CTNS_GFF_ID:
1147 CtReq->CommandResponse.bits.CmdRsp =
1148 be16_to_cpu(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001149 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001150 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1151 break;
1152
dea31012005-04-17 16:05:31 -05001153 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001154 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001155 CtReq->CommandResponse.bits.CmdRsp =
1156 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001157 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001158 CtReq->un.rft.fcpReg = 1;
1159 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1160 break;
1161
1162 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001163 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001164 CtReq->CommandResponse.bits.CmdRsp =
1165 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001166 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001167 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001168 sizeof (struct lpfc_name));
1169 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1170 break;
1171
James Smart92d7f7b2007-06-17 19:56:38 -05001172 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001173 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001174 CtReq->CommandResponse.bits.CmdRsp =
1175 be16_to_cpu(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001176 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001177 size = sizeof(CtReq->un.rspn.symbname);
1178 CtReq->un.rspn.len =
1179 lpfc_vport_symbolic_port_name(vport,
1180 CtReq->un.rspn.symbname, size);
1181 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1182 break;
dea31012005-04-17 16:05:31 -05001183 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001184 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001185 CtReq->CommandResponse.bits.CmdRsp =
1186 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001187 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001188 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001189 size = sizeof(CtReq->un.rsnn.symbname);
1190 CtReq->un.rsnn.len =
1191 lpfc_vport_symbolic_node_name(vport,
1192 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001193 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1194 break;
James Smart7ee5d432007-10-27 13:37:17 -04001195 case SLI_CTNS_DA_ID:
1196 /* Implement DA_ID Nameserver request */
1197 CtReq->CommandResponse.bits.CmdRsp =
1198 be16_to_cpu(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001199 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001200 cmpl = lpfc_cmpl_ct_cmd_da_id;
1201 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001202 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001203 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001204 CtReq->CommandResponse.bits.CmdRsp =
1205 be16_to_cpu(SLI_CTNS_RFF_ID);
James Smart09372822008-01-11 01:52:54 -05001206 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);;
James Smart92d7f7b2007-06-17 19:56:38 -05001207 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1208 CtReq->un.rff.type_code = FC_FCP_DATA;
1209 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1210 break;
dea31012005-04-17 16:05:31 -05001211 }
James Smarte47c9092008-02-08 18:49:26 -05001212 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1213 * to hold ndlp reference for the corresponding callback function.
1214 */
James Smart858c9f62007-06-17 19:56:39 -05001215 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001216 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001217 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1218 "Issue CT cmd: cmd:x%x did:x%x",
1219 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001220 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001221 }
James Smart858c9f62007-06-17 19:56:39 -05001222 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001223
1224 /* Decrement ndlp reference count to release ndlp reference held
1225 * for the failed command's callback function.
1226 */
James Smart51ef4c22007-08-02 11:10:31 -04001227 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001228
dea31012005-04-17 16:05:31 -05001229 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1230ns_cmd_free_bmp:
1231 kfree(bmp);
1232ns_cmd_free_mpvirt:
1233 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1234ns_cmd_free_mp:
1235 kfree(mp);
1236ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001237 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1238 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1239 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001240 return 1;
1241}
1242
1243static void
James Smart2e0fef82007-06-17 19:56:36 -05001244lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1245 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001246{
dea31012005-04-17 16:05:31 -05001247 struct lpfc_dmabuf *inp = cmdiocb->context1;
1248 struct lpfc_dmabuf *outp = cmdiocb->context2;
1249 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1250 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1251 struct lpfc_nodelist *ndlp;
1252 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1253 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001254 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001255 IOCB_t *irsp = &rspiocb->iocb;
1256 uint32_t latt;
1257
1258 latt = lpfc_els_chk_latt(vport);
1259
1260 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1261 "FDMI cmpl: status:x%x/x%x latt:%d",
1262 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1263
1264 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001265 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1266 "0229 FDMI cmd %04x failed, latt = %d "
1267 "ulpStatus: x%x, rid x%x\n",
1268 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1269 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001270 lpfc_ct_free_iocb(phba, cmdiocb);
1271 return;
1272 }
dea31012005-04-17 16:05:31 -05001273
James Smart2e0fef82007-06-17 19:56:36 -05001274 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001275 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1276 goto fail_out;
1277
dea31012005-04-17 16:05:31 -05001278 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1279 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001280 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1281 "0220 FDMI rsp failed Data: x%x\n",
1282 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001283 }
1284
1285 switch (be16_to_cpu(fdmi_cmd)) {
1286 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001287 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001288 break;
1289
1290 case SLI_MGMT_RPA:
1291 break;
1292
1293 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001294 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001295 break;
1296
1297 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001298 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001299 break;
1300 }
James Smarte47c9092008-02-08 18:49:26 -05001301
1302fail_out:
James Smart858c9f62007-06-17 19:56:39 -05001303 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001304 return;
1305}
James Smart2e0fef82007-06-17 19:56:36 -05001306
dea31012005-04-17 16:05:31 -05001307int
James Smart2e0fef82007-06-17 19:56:36 -05001308lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001309{
James Smart2e0fef82007-06-17 19:56:36 -05001310 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001311 struct lpfc_dmabuf *mp, *bmp;
1312 struct lpfc_sli_ct_request *CtReq;
1313 struct ulp_bde64 *bpl;
1314 uint32_t size;
1315 REG_HBA *rh;
1316 PORT_ENTRY *pe;
1317 REG_PORT_ATTRIBUTE *pab;
1318 ATTRIBUTE_BLOCK *ab;
1319 ATTRIBUTE_ENTRY *ae;
1320 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1321 struct lpfc_iocbq *);
1322
1323
1324 /* fill in BDEs for command */
1325 /* Allocate buffer for command payload */
1326 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1327 if (!mp)
1328 goto fdmi_cmd_exit;
1329
1330 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1331 if (!mp->virt)
1332 goto fdmi_cmd_free_mp;
1333
1334 /* Allocate buffer for Buffer ptr list */
1335 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1336 if (!bmp)
1337 goto fdmi_cmd_free_mpvirt;
1338
1339 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1340 if (!bmp->virt)
1341 goto fdmi_cmd_free_bmp;
1342
1343 INIT_LIST_HEAD(&mp->list);
1344 INIT_LIST_HEAD(&bmp->list);
1345
1346 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001347 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1348 "0218 FDMI Request Data: x%x x%x x%x\n",
1349 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001350 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1351
1352 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1353 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1354 CtReq->RevisionId.bits.InId = 0;
1355
1356 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1357 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1358 size = 0;
1359
1360 switch (cmdcode) {
1361 case SLI_MGMT_RHBA:
1362 {
1363 lpfc_vpd_t *vp = &phba->vpd;
1364 uint32_t i, j, incr;
1365 int len;
1366
1367 CtReq->CommandResponse.bits.CmdRsp =
1368 be16_to_cpu(SLI_MGMT_RHBA);
1369 CtReq->CommandResponse.bits.Size = 0;
1370 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001371 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001372 sizeof (struct lpfc_name));
1373 /* One entry (port) per adapter */
1374 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001375 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001376 sizeof (struct lpfc_name));
1377
1378 /* point to the HBA attribute block */
1379 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1380 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1381 ab->EntryCnt = 0;
1382
1383 /* Point to the beginning of the first HBA attribute
1384 entry */
1385 /* #1 HBA attribute entry */
1386 size += FOURBYTES;
1387 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1388 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1389 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1390 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001391 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001392 sizeof (struct lpfc_name));
1393 ab->EntryCnt++;
1394 size += FOURBYTES + sizeof (struct lpfc_name);
1395
1396 /* #2 HBA attribute entry */
1397 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1398 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1399 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1400 len = strlen(ae->un.Manufacturer);
1401 len += (len & 3) ? (4 - (len & 3)) : 4;
1402 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1403 ab->EntryCnt++;
1404 size += FOURBYTES + len;
1405
1406 /* #3 HBA attribute entry */
1407 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1408 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1409 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1410 len = strlen(ae->un.SerialNumber);
1411 len += (len & 3) ? (4 - (len & 3)) : 4;
1412 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1413 ab->EntryCnt++;
1414 size += FOURBYTES + len;
1415
1416 /* #4 HBA attribute entry */
1417 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1418 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1419 strcpy(ae->un.Model, phba->ModelName);
1420 len = strlen(ae->un.Model);
1421 len += (len & 3) ? (4 - (len & 3)) : 4;
1422 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1423 ab->EntryCnt++;
1424 size += FOURBYTES + len;
1425
1426 /* #5 HBA attribute entry */
1427 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1428 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1429 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1430 len = strlen(ae->un.ModelDescription);
1431 len += (len & 3) ? (4 - (len & 3)) : 4;
1432 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1433 ab->EntryCnt++;
1434 size += FOURBYTES + len;
1435
1436 /* #6 HBA attribute entry */
1437 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1438 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1439 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1440 /* Convert JEDEC ID to ascii for hardware version */
1441 incr = vp->rev.biuRev;
1442 for (i = 0; i < 8; i++) {
1443 j = (incr & 0xf);
1444 if (j <= 9)
1445 ae->un.HardwareVersion[7 - i] =
1446 (char)((uint8_t) 0x30 +
1447 (uint8_t) j);
1448 else
1449 ae->un.HardwareVersion[7 - i] =
1450 (char)((uint8_t) 0x61 +
1451 (uint8_t) (j - 10));
1452 incr = (incr >> 4);
1453 }
1454 ab->EntryCnt++;
1455 size += FOURBYTES + 8;
1456
1457 /* #7 HBA attribute entry */
1458 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1459 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1460 strcpy(ae->un.DriverVersion, lpfc_release_version);
1461 len = strlen(ae->un.DriverVersion);
1462 len += (len & 3) ? (4 - (len & 3)) : 4;
1463 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1464 ab->EntryCnt++;
1465 size += FOURBYTES + len;
1466
1467 /* #8 HBA attribute entry */
1468 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1469 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1470 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1471 len = strlen(ae->un.OptionROMVersion);
1472 len += (len & 3) ? (4 - (len & 3)) : 4;
1473 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1474 ab->EntryCnt++;
1475 size += FOURBYTES + len;
1476
1477 /* #9 HBA attribute entry */
1478 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1479 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1480 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1481 1);
1482 len = strlen(ae->un.FirmwareVersion);
1483 len += (len & 3) ? (4 - (len & 3)) : 4;
1484 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1485 ab->EntryCnt++;
1486 size += FOURBYTES + len;
1487
1488 /* #10 HBA attribute entry */
1489 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1490 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1491 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001492 init_utsname()->sysname,
1493 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001494 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001495 len = strlen(ae->un.OsNameVersion);
1496 len += (len & 3) ? (4 - (len & 3)) : 4;
1497 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1498 ab->EntryCnt++;
1499 size += FOURBYTES + len;
1500
1501 /* #11 HBA attribute entry */
1502 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1503 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1504 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1505 ae->un.MaxCTPayloadLen = (65 * 4096);
1506 ab->EntryCnt++;
1507 size += FOURBYTES + 4;
1508
1509 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1510 /* Total size */
1511 size = GID_REQUEST_SZ - 4 + size;
1512 }
1513 break;
1514
1515 case SLI_MGMT_RPA:
1516 {
1517 lpfc_vpd_t *vp;
1518 struct serv_parm *hsp;
1519 int len;
1520
1521 vp = &phba->vpd;
1522
1523 CtReq->CommandResponse.bits.CmdRsp =
1524 be16_to_cpu(SLI_MGMT_RPA);
1525 CtReq->CommandResponse.bits.Size = 0;
1526 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1527 size = sizeof (struct lpfc_name) + FOURBYTES;
1528 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001529 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001530 sizeof (struct lpfc_name));
1531 pab->ab.EntryCnt = 0;
1532
1533 /* #1 Port attribute entry */
1534 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1535 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1536 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1537 ae->un.SupportFC4Types[2] = 1;
1538 ae->un.SupportFC4Types[7] = 1;
1539 pab->ab.EntryCnt++;
1540 size += FOURBYTES + 32;
1541
1542 /* #2 Port attribute entry */
1543 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1544 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1545 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001546
1547 ae->un.SupportSpeed = 0;
1548 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001549 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001550 if (phba->lmt & LMT_8Gb)
1551 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1552 if (phba->lmt & LMT_4Gb)
1553 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1554 if (phba->lmt & LMT_2Gb)
1555 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1556 if (phba->lmt & LMT_1Gb)
1557 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1558
dea31012005-04-17 16:05:31 -05001559 pab->ab.EntryCnt++;
1560 size += FOURBYTES + 4;
1561
1562 /* #3 Port attribute entry */
1563 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1564 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1565 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1566 switch(phba->fc_linkspeed) {
1567 case LA_1GHZ_LINK:
1568 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1569 break;
1570 case LA_2GHZ_LINK:
1571 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1572 break;
1573 case LA_4GHZ_LINK:
1574 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1575 break;
James Smartb87eab32007-04-25 09:53:28 -04001576 case LA_8GHZ_LINK:
1577 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1578 break;
dea31012005-04-17 16:05:31 -05001579 default:
1580 ae->un.PortSpeed =
1581 HBA_PORTSPEED_UNKNOWN;
1582 break;
1583 }
1584 pab->ab.EntryCnt++;
1585 size += FOURBYTES + 4;
1586
1587 /* #4 Port attribute entry */
1588 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1589 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1590 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001591 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001592 ae->un.MaxFrameSize =
1593 (((uint32_t) hsp->cmn.
1594 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1595 bbRcvSizeLsb;
1596 pab->ab.EntryCnt++;
1597 size += FOURBYTES + 4;
1598
1599 /* #5 Port attribute entry */
1600 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1601 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1602 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1603 len = strlen((char *)ae->un.OsDeviceName);
1604 len += (len & 3) ? (4 - (len & 3)) : 4;
1605 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1606 pab->ab.EntryCnt++;
1607 size += FOURBYTES + len;
1608
James Smart3de2a652007-08-02 11:09:59 -04001609 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001610 /* #6 Port attribute entry */
1611 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1612 size);
1613 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1614 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001615 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001616 len = strlen(ae->un.HostName);
1617 len += (len & 3) ? (4 - (len & 3)) : 4;
1618 ae->ad.bits.AttrLen =
1619 be16_to_cpu(FOURBYTES + len);
1620 pab->ab.EntryCnt++;
1621 size += FOURBYTES + len;
1622 }
1623
1624 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1625 /* Total size */
1626 size = GID_REQUEST_SZ - 4 + size;
1627 }
1628 break;
1629
1630 case SLI_MGMT_DHBA:
1631 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1632 CtReq->CommandResponse.bits.Size = 0;
1633 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1634 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001635 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001636 sizeof (struct lpfc_name));
1637 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1638 break;
1639
1640 case SLI_MGMT_DPRT:
1641 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1642 CtReq->CommandResponse.bits.Size = 0;
1643 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1644 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001645 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001646 sizeof (struct lpfc_name));
1647 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1648 break;
1649 }
1650
1651 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001652 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1653 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001654 bpl->tus.f.bdeFlags = 0;
1655 bpl->tus.f.bdeSize = size;
1656 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1657
1658 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1659
James Smarte47c9092008-02-08 18:49:26 -05001660 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1661 * to hold ndlp reference for the corresponding callback function.
1662 */
James Smart92d7f7b2007-06-17 19:56:38 -05001663 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001664 return 0;
1665
James Smarte47c9092008-02-08 18:49:26 -05001666 /* Decrement ndlp reference count to release ndlp reference held
1667 * for the failed command's callback function.
1668 */
James Smart51ef4c22007-08-02 11:10:31 -04001669 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001670
dea31012005-04-17 16:05:31 -05001671 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1672fdmi_cmd_free_bmp:
1673 kfree(bmp);
1674fdmi_cmd_free_mpvirt:
1675 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1676fdmi_cmd_free_mp:
1677 kfree(mp);
1678fdmi_cmd_exit:
1679 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001680 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1681 "0244 Issue FDMI request failed Data: x%x\n",
1682 cmdcode);
dea31012005-04-17 16:05:31 -05001683 return 1;
1684}
1685
1686void
1687lpfc_fdmi_tmo(unsigned long ptr)
1688{
James Smart2e0fef82007-06-17 19:56:36 -05001689 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1690 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001691 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05001692 unsigned long iflag;
1693
James Smart2e0fef82007-06-17 19:56:36 -05001694 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001695 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1696 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05001697 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04001698 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001699
James Smart5e9d9b82008-06-14 22:52:53 -04001700 if (!tmo_posted)
1701 lpfc_worker_wake_up(phba);
1702 return;
dea31012005-04-17 16:05:31 -05001703}
1704
1705void
James Smart2e0fef82007-06-17 19:56:36 -05001706lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001707{
1708 struct lpfc_nodelist *ndlp;
1709
James Smart2e0fef82007-06-17 19:56:36 -05001710 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001711 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001712 if (init_utsname()->nodename[0] != '\0')
1713 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1714 else
1715 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001716 }
dea31012005-04-17 16:05:31 -05001717 return;
1718}
1719
dea31012005-04-17 16:05:31 -05001720void
James Smart2e0fef82007-06-17 19:56:36 -05001721lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001722{
1723 struct lpfc_sli *psli = &phba->sli;
1724 lpfc_vpd_t *vp = &phba->vpd;
1725 uint32_t b1, b2, b3, b4, i, rev;
1726 char c;
1727 uint32_t *ptr, str[4];
1728 uint8_t *fwname;
1729
1730 if (vp->rev.rBit) {
1731 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1732 rev = vp->rev.sli2FwRev;
1733 else
1734 rev = vp->rev.sli1FwRev;
1735
1736 b1 = (rev & 0x0000f000) >> 12;
1737 b2 = (rev & 0x00000f00) >> 8;
1738 b3 = (rev & 0x000000c0) >> 6;
1739 b4 = (rev & 0x00000030) >> 4;
1740
1741 switch (b4) {
1742 case 0:
1743 c = 'N';
1744 break;
1745 case 1:
1746 c = 'A';
1747 break;
1748 case 2:
1749 c = 'B';
1750 break;
1751 default:
1752 c = 0;
1753 break;
1754 }
1755 b4 = (rev & 0x0000000f);
1756
1757 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1758 fwname = vp->rev.sli2FwName;
1759 else
1760 fwname = vp->rev.sli1FwName;
1761
1762 for (i = 0; i < 16; i++)
1763 if (fwname[i] == 0x20)
1764 fwname[i] = 0;
1765
1766 ptr = (uint32_t*)fwname;
1767
1768 for (i = 0; i < 3; i++)
1769 str[i] = be32_to_cpu(*ptr++);
1770
1771 if (c == 0) {
1772 if (flag)
1773 sprintf(fwrevision, "%d.%d%d (%s)",
1774 b1, b2, b3, (char *)str);
1775 else
1776 sprintf(fwrevision, "%d.%d%d", b1,
1777 b2, b3);
1778 } else {
1779 if (flag)
1780 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1781 b1, b2, b3, c,
1782 b4, (char *)str);
1783 else
1784 sprintf(fwrevision, "%d.%d%d%c%d",
1785 b1, b2, b3, c, b4);
1786 }
1787 } else {
1788 rev = vp->rev.smFwRev;
1789
1790 b1 = (rev & 0xff000000) >> 24;
1791 b2 = (rev & 0x00f00000) >> 20;
1792 b3 = (rev & 0x000f0000) >> 16;
1793 c = (rev & 0x0000ff00) >> 8;
1794 b4 = (rev & 0x000000ff);
1795
1796 if (flag)
1797 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1798 b2, b3, c, b4);
1799 else
1800 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1801 b2, b3, c, b4);
1802 }
1803 return;
1804}