blob: 65f9fb6862e6b36ddde7cbf80074eefcb2593e31 [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 Smart4fede782010-01-26 23:08:55 -05004 * Copyright (C) 2004-2010 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050029#include <linux/utsname.h>
30
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040034#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040035#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050036
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_crtn.h"
47#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050048#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050049#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050050
James Smart76a95d72010-11-20 23:11:48 -050051/* FDMI Port Speed definitions */
52#define HBA_PORTSPEED_1GBIT 0x0001 /* 1 GBit/sec */
53#define HBA_PORTSPEED_2GBIT 0x0002 /* 2 GBit/sec */
54#define HBA_PORTSPEED_4GBIT 0x0008 /* 4 GBit/sec */
55#define HBA_PORTSPEED_10GBIT 0x0004 /* 10 GBit/sec */
56#define HBA_PORTSPEED_8GBIT 0x0010 /* 8 GBit/sec */
57#define HBA_PORTSPEED_16GBIT 0x0020 /* 16 GBit/sec */
58#define HBA_PORTSPEED_UNKNOWN 0x0800 /* Unknown */
dea31012005-04-17 16:05:31 -050059
60#define FOURBYTES 4
61
62
63static char *lpfc_release_version = LPFC_DRIVER_VERSION;
64
James Smarted957682007-06-17 19:56:37 -050065static void
66lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050067 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050068{
James Smarted957682007-06-17 19:56:37 -050069 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040071 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050072 "status = x%x\n",
73 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050074 }
James Smart9c2face2008-01-11 01:53:18 -050075 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
76 "0145 Ignoring unsolicted CT HBQ Size:%d "
77 "status = x%x\n",
78 size, piocbq->iocb.ulpStatus);
79}
80
81static void
82lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
83 struct lpfc_dmabuf *mp, uint32_t size)
84{
85 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -050086}
87
dea31012005-04-17 16:05:31 -050088void
James Smart2e0fef82007-06-17 19:56:36 -050089lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
90 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -050091{
James Smarted957682007-06-17 19:56:37 -050092 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -050093 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -050094 int i;
95 struct lpfc_iocbq *iocbq;
96 dma_addr_t paddr;
97 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -050098 struct list_head head;
99 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -0500100
James Smart4fede782010-01-26 23:08:55 -0500101 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
102 return;
James Smartf1c3b0f2009-07-19 10:01:32 -0400103
James Smart92d7f7b2007-06-17 19:56:38 -0500104 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
105 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
106 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400107 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
108 IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500109 /* Not enough posted buffers; Try posting more buffers */
110 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500111 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400112 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500113 return;
114 }
115
116 /* If there are no BDEs associated with this IOCB,
117 * there is nothing to do.
118 */
119 if (icmd->ulpBdeCount == 0)
120 return;
121
James Smarted957682007-06-17 19:56:37 -0500122 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500123 INIT_LIST_HEAD(&head);
124 list_add_tail(&head, &piocbq->list);
125 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500126 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500127 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500128 continue;
James Smart9c2face2008-01-11 01:53:18 -0500129 bdeBuf = iocbq->context2;
130 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500131 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500132 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
133 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500134 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500135 bdeBuf = iocbq->context3;
136 iocbq->context3 = NULL;
137 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
138 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
139 size);
140 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500141 }
dea31012005-04-17 16:05:31 -0500142 }
James Smart9c2face2008-01-11 01:53:18 -0500143 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500144 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400145 INIT_LIST_HEAD(&head);
146 list_add_tail(&head, &piocbq->list);
147 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500148 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500149 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400150 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500151 for (i = 0; i < icmd->ulpBdeCount; i++) {
152 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
153 icmd->un.cont64[i].addrLow);
154 mp = lpfc_sli_ringpostbuf_get(phba, pring,
155 paddr);
156 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400157 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500158 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500159 }
James Smart495a7142008-06-14 22:52:59 -0400160 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500161 }
James Smartd7c255b2008-08-24 21:50:00 -0400162 list_del(&head);
dea31012005-04-17 16:05:31 -0500163 }
dea31012005-04-17 16:05:31 -0500164}
165
James Smart6669f9b2009-10-02 15:16:45 -0400166/**
167 * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort
168 * @phba: Pointer to HBA context object.
169 * @pring: Pointer to the driver internal I/O ring.
170 * @piocbq: Pointer to the IOCBQ.
171 *
172 * This function serves as the default handler for the sli4 unsolicited
173 * abort event. It shall be invoked when there is no application interface
174 * registered unsolicited abort handler. This handler does nothing but
175 * just simply releases the dma buffer used by the unsol abort event.
176 **/
177void
178lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
179 struct lpfc_sli_ring *pring,
180 struct lpfc_iocbq *piocbq)
181{
182 IOCB_t *icmd = &piocbq->iocb;
183 struct lpfc_dmabuf *bdeBuf;
184 uint32_t size;
185
186 /* Forward abort event to any process registered to receive ct event */
James Smart4fede782010-01-26 23:08:55 -0500187 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
188 return;
James Smart6669f9b2009-10-02 15:16:45 -0400189
190 /* If there is no BDE associated with IOCB, there is nothing to do */
191 if (icmd->ulpBdeCount == 0)
192 return;
193 bdeBuf = piocbq->context2;
194 piocbq->context2 = NULL;
195 size = icmd->un.cont64[0].tus.f.bdeSize;
196 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
197 lpfc_in_buf_free(phba, bdeBuf);
198}
199
dea31012005-04-17 16:05:31 -0500200static void
James Smart2e0fef82007-06-17 19:56:36 -0500201lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500202{
203 struct lpfc_dmabuf *mlast, *next_mlast;
204
205 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
206 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
207 list_del(&mlast->list);
208 kfree(mlast);
209 }
210 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
211 kfree(mlist);
212 return;
213}
214
215static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500216lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500217 uint32_t size, int *entries)
218{
219 struct lpfc_dmabuf *mlist = NULL;
220 struct lpfc_dmabuf *mp;
221 int cnt, i = 0;
222
James Smart09372822008-01-11 01:52:54 -0500223 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500224 cnt = size > FCELSSIZE ? FCELSSIZE: size;
225
226 while (size) {
227 /* Allocate buffer for rsp payload */
228 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
229 if (!mp) {
230 if (mlist)
231 lpfc_free_ct_rsp(phba, mlist);
232 return NULL;
233 }
234
235 INIT_LIST_HEAD(&mp->list);
236
James Smart92d7f7b2007-06-17 19:56:38 -0500237 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
238 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500239 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
240 else
241 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
242
243 if (!mp->virt) {
244 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700245 if (mlist)
246 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500247 return NULL;
248 }
249
250 /* Queue it to a linked list */
251 if (!mlist)
252 mlist = mp;
253 else
254 list_add_tail(&mp->list, &mlist->list);
255
James Smart34b02dc2008-08-24 21:49:55 -0400256 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500257 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500258 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
259 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500260 bpl->tus.f.bdeSize = (uint16_t) cnt;
261 bpl->tus.w = le32_to_cpu(bpl->tus.w);
262 bpl++;
263
264 i++;
265 size -= cnt;
266 }
267
268 *entries = i;
269 return mlist;
270}
271
James Smart858c9f62007-06-17 19:56:39 -0500272int
273lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
274{
275 struct lpfc_dmabuf *buf_ptr;
276
James Smart51ef4c22007-08-02 11:10:31 -0400277 if (ctiocb->context_un.ndlp) {
278 lpfc_nlp_put(ctiocb->context_un.ndlp);
279 ctiocb->context_un.ndlp = NULL;
280 }
James Smart858c9f62007-06-17 19:56:39 -0500281 if (ctiocb->context1) {
282 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
283 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
284 kfree(buf_ptr);
285 ctiocb->context1 = NULL;
286 }
287 if (ctiocb->context2) {
288 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
289 ctiocb->context2 = NULL;
290 }
291
292 if (ctiocb->context3) {
293 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
294 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
295 kfree(buf_ptr);
296 ctiocb->context1 = NULL;
297 }
298 lpfc_sli_release_iocbq(phba, ctiocb);
299 return 0;
300}
301
dea31012005-04-17 16:05:31 -0500302static int
James Smart2e0fef82007-06-17 19:56:36 -0500303lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500304 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
305 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
306 struct lpfc_iocbq *),
307 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500308 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500309{
James Smart2e0fef82007-06-17 19:56:36 -0500310 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500311 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400312 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500313 int rc;
dea31012005-04-17 16:05:31 -0500314
315 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400316 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500317
318 if (geniocb == NULL)
319 return 1;
dea31012005-04-17 16:05:31 -0500320
321 icmd = &geniocb->iocb;
322 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
323 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
324 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400325 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea31012005-04-17 16:05:31 -0500326 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
327
328 if (usr_flg)
329 geniocb->context3 = NULL;
330 else
331 geniocb->context3 = (uint8_t *) bmp;
332
333 /* Save for completion so we can release these resources */
334 geniocb->context1 = (uint8_t *) inp;
335 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500336 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500337
338 /* Fill in payload, bp points to frame payload */
339 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
340
341 /* Fill in rest of iocb */
342 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
343 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
James Smart6a9c52c2009-10-02 15:16:51 -0400344 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
345 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -0500346
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500347 if (!tmo) {
348 /* FC spec states we need 3 * ratov for CT requests */
349 tmo = (3 * phba->fc_ratov);
350 }
dea31012005-04-17 16:05:31 -0500351 icmd->ulpTimeout = tmo;
352 icmd->ulpBdeCount = 1;
353 icmd->ulpLe = 1;
354 icmd->ulpClass = CLASS3;
355 icmd->ulpContext = ndlp->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -0400356 if (phba->sli_rev == LPFC_SLI_REV4)
357 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea31012005-04-17 16:05:31 -0500358
James Smart92d7f7b2007-06-17 19:56:38 -0500359 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
360 /* For GEN_REQUEST64_CR, use the RPI */
361 icmd->ulpCt_h = 0;
362 icmd->ulpCt_l = 0;
363 }
364
dea31012005-04-17 16:05:31 -0500365 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400366 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
367 "0119 Issue GEN REQ IOCB to NPORT x%x "
368 "Data: x%x x%x\n",
369 ndlp->nlp_DID, icmd->ulpIoTag,
370 vport->port_state);
dea31012005-04-17 16:05:31 -0500371 geniocb->iocb_cmpl = cmpl;
372 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500373 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500374 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500376
377 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500378 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500379 return 1;
380 }
dea31012005-04-17 16:05:31 -0500381
382 return 0;
383}
384
385static int
James Smart2e0fef82007-06-17 19:56:36 -0500386lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500387 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
388 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
389 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500390 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500391{
James Smart2e0fef82007-06-17 19:56:36 -0500392 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500393 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
394 struct lpfc_dmabuf *outmp;
395 int cnt = 0, status;
396 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
397 CommandResponse.bits.CmdRsp;
398
399 bpl++; /* Skip past ct request */
400
401 /* Put buffer(s) for ct rsp in bpl */
402 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
403 if (!outmp)
404 return -ENOMEM;
James Smart6a9c52c2009-10-02 15:16:51 -0400405 /*
406 * Form the CT IOCB. The total number of BDEs in this IOCB
407 * is the single command plus response count from
408 * lpfc_alloc_ct_rsp.
409 */
410 cnt += 1;
James Smart2e0fef82007-06-17 19:56:36 -0500411 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart6a9c52c2009-10-02 15:16:51 -0400412 cnt, 0, retry);
dea31012005-04-17 16:05:31 -0500413 if (status) {
414 lpfc_free_ct_rsp(phba, outmp);
415 return -ENOMEM;
416 }
417 return 0;
418}
419
James Smart549e55c2007-08-02 11:09:51 -0400420struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500421lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500422 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400423 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500424
James Smart549e55c2007-08-02 11:09:51 -0400425 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500426 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400427 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
428 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500429 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400430 }
James Smart92d7f7b2007-06-17 19:56:38 -0500431 }
James Smart549e55c2007-08-02 11:09:51 -0400432 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500433 return NULL;
434}
435
dea31012005-04-17 16:05:31 -0500436static int
James Smart2e0fef82007-06-17 19:56:36 -0500437lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500438{
James Smart2e0fef82007-06-17 19:56:36 -0500439 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500440 struct lpfc_sli_ct_request *Response =
441 (struct lpfc_sli_ct_request *) mp->virt;
442 struct lpfc_nodelist *ndlp = NULL;
443 struct lpfc_dmabuf *mlast, *next_mp;
444 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500445 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500446 int Cnt;
447 struct list_head head;
448
James Smart2e0fef82007-06-17 19:56:36 -0500449 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500450 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500451 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500452
dea31012005-04-17 16:05:31 -0500453
454 list_add_tail(&head, &mp->list);
455 list_for_each_entry_safe(mp, next_mp, &head, list) {
456 mlast = mp;
457
James Smart7054a602007-04-25 09:52:34 -0400458 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
459
dea31012005-04-17 16:05:31 -0500460 Size -= Cnt;
461
James Smart1dcb58e2007-04-25 09:51:30 -0400462 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500463 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400464 } else
dea31012005-04-17 16:05:31 -0500465 Cnt -= 16; /* subtract length of CT header */
466
467 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400468 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500469 /* Get next DID from NameServer List */
470 CTentry = *ctptr++;
471 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500472
dea31012005-04-17 16:05:31 -0500473 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500474
475 /*
476 * Check for rscn processing or not
477 * To conserve rpi's, filter out addresses for other
478 * vports on the same physical HBAs.
479 */
480 if ((Did != vport->fc_myDID) &&
481 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400482 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500483 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart98c9ea52007-10-27 13:37:33 -0400484 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
James Smart3de2a652007-08-02 11:09:59 -0400485 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500486 ndlp = lpfc_setup_disc_node(vport, Did);
James Smart58da1ff2008-04-07 10:15:56 -0400487 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500488 lpfc_debugfs_disc_trc(vport,
489 LPFC_DISC_TRC_CT,
490 "Parse GID_FTrsp: "
491 "did:x%x flg:x%x x%x",
492 Did, ndlp->nlp_flag,
493 vport->fc_flag);
494
James Smarte8b62012007-08-02 11:10:09 -0400495 lpfc_printf_vlog(vport,
496 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500497 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400498 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500499 "x%x NameServer Rsp"
500 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400501 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500502 vport->fc_flag,
503 vport->fc_rscn_id_cnt);
504 } else {
James Smart858c9f62007-06-17 19:56:39 -0500505 lpfc_debugfs_disc_trc(vport,
506 LPFC_DISC_TRC_CT,
507 "Skip1 GID_FTrsp: "
508 "did:x%x flg:x%x cnt:%d",
509 Did, vport->fc_flag,
510 vport->fc_rscn_id_cnt);
511
James Smarte8b62012007-08-02 11:10:09 -0400512 lpfc_printf_vlog(vport,
513 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500514 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400515 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500516 "NameServer Rsp Data: "
517 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400518 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500519 vport->fc_rscn_id_cnt);
520 }
521
522 } else {
523 if (!(vport->fc_flag & FC_RSCN_MODE) ||
524 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500525 lpfc_debugfs_disc_trc(vport,
526 LPFC_DISC_TRC_CT,
527 "Query GID_FTrsp: "
528 "did:x%x flg:x%x cnt:%d",
529 Did, vport->fc_flag,
530 vport->fc_rscn_id_cnt);
531
James Smart0ff10d42008-01-11 01:52:36 -0500532 /* This NPortID was previously
533 * a FCP target, * Don't even
534 * bother to send GFF_ID.
535 */
536 ndlp = lpfc_findnode_did(vport,
537 Did);
James Smarte47c9092008-02-08 18:49:26 -0500538 if (ndlp &&
539 NLP_CHK_NODE_ACT(ndlp)
540 && (ndlp->nlp_type &
541 NLP_FCP_TARGET))
James Smart0ff10d42008-01-11 01:52:36 -0500542 lpfc_setup_disc_node
543 (vport, Did);
544 else if (lpfc_ns_cmd(vport,
James Smart92d7f7b2007-06-17 19:56:38 -0500545 SLI_CTNS_GFF_ID,
546 0, Did) == 0)
547 vport->num_disc_nodes++;
James Smart6a9c52c2009-10-02 15:16:51 -0400548 else
549 lpfc_setup_disc_node
550 (vport, Did);
James Smart92d7f7b2007-06-17 19:56:38 -0500551 }
552 else {
James Smart858c9f62007-06-17 19:56:39 -0500553 lpfc_debugfs_disc_trc(vport,
554 LPFC_DISC_TRC_CT,
555 "Skip2 GID_FTrsp: "
556 "did:x%x flg:x%x cnt:%d",
557 Did, vport->fc_flag,
558 vport->fc_rscn_id_cnt);
559
James Smarte8b62012007-08-02 11:10:09 -0400560 lpfc_printf_vlog(vport,
561 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500562 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400563 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500564 "NameServer Rsp Data: "
565 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400566 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500567 vport->fc_rscn_id_cnt);
568 }
569 }
dea31012005-04-17 16:05:31 -0500570 }
dea31012005-04-17 16:05:31 -0500571 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
572 goto nsout1;
573 Cnt -= sizeof (uint32_t);
574 }
575 ctptr = NULL;
576
577 }
578
579nsout1:
580 list_del(&head);
dea31012005-04-17 16:05:31 -0500581 return 0;
582}
583
dea31012005-04-17 16:05:31 -0500584static void
James Smart2e0fef82007-06-17 19:56:36 -0500585lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
586 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500587{
James Smart2e0fef82007-06-17 19:56:36 -0500588 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500589 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500590 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500591 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500592 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500593 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400594 struct lpfc_nodelist *ndlp;
James Smart58da1ff2008-04-07 10:15:56 -0400595 int rc;
dea31012005-04-17 16:05:31 -0500596
James Smart51ef4c22007-08-02 11:10:31 -0400597 /* First save ndlp, before we overwrite it */
598 ndlp = cmdiocb->context_un.ndlp;
599
dea31012005-04-17 16:05:31 -0500600 /* we pass cmdiocb to state machine which needs rspiocb as well */
601 cmdiocb->context_un.rsp_iocb = rspiocb;
602
dea31012005-04-17 16:05:31 -0500603 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
604 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500605 irsp = &rspiocb->iocb;
606
607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
608 "GID_FT cmpl: status:x%x/x%x rtry:%d",
609 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500610
James Smart92d7f7b2007-06-17 19:56:38 -0500611 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500612 if (vport->load_flag & FC_UNLOADING) {
613 if (vport->fc_flag & FC_RSCN_MODE)
614 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500615 goto out;
James Smarteada2722008-12-04 22:39:13 -0500616 }
James Smart92d7f7b2007-06-17 19:56:38 -0500617
James Smart58da1ff2008-04-07 10:15:56 -0400618 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400619 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
620 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500621 if (vport->fc_flag & FC_RSCN_MODE)
622 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500623 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
624 goto out;
625 }
James Smart58da1ff2008-04-07 10:15:56 -0400626 if (lpfc_error_lost_link(irsp)) {
627 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
628 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500629 if (vport->fc_flag & FC_RSCN_MODE)
630 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400631 goto out;
632 }
James Smart858c9f62007-06-17 19:56:39 -0500633 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500634 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500635 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400636 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
James Smartedb22f02012-10-31 14:45:21 -0400637 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
James Smarte3d2b802012-08-14 14:25:43 -0400638 IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500639 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500640
James Smart58da1ff2008-04-07 10:15:56 -0400641 /* CT command is being retried */
642 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smart92d7f7b2007-06-17 19:56:38 -0500643 vport->fc_ns_retry, 0);
James Smart58da1ff2008-04-07 10:15:56 -0400644 if (rc == 0)
645 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500646 }
James Smarteada2722008-12-04 22:39:13 -0500647 if (vport->fc_flag & FC_RSCN_MODE)
648 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500649 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400650 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
651 "0257 GID_FT Query error: 0x%x 0x%x\n",
652 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500653 } else {
654 /* Good status, continue checking */
655 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
656 if (CTrsp->CommandResponse.bits.CmdRsp ==
657 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400658 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
659 "0208 NameServer Rsp Data: x%x\n",
660 vport->fc_flag);
James Smart2e0fef82007-06-17 19:56:36 -0500661 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500662 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
663 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
664 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
665 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400666 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
667 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400668 lpfc_printf_vlog(vport, KERN_INFO,
669 LOG_DISCOVERY,
670 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400671 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400672 CTrsp->CommandResponse.bits.CmdRsp,
673 (uint32_t) CTrsp->ReasonCode,
674 (uint32_t) CTrsp->Explanation,
675 vport->fc_flag);
676
677 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
678 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
679 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
680 (uint32_t) CTrsp->ReasonCode,
681 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400682 } else {
683 lpfc_printf_vlog(vport, KERN_INFO,
684 LOG_DISCOVERY,
685 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500686 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500687 CTrsp->CommandResponse.bits.CmdRsp,
688 (uint32_t) CTrsp->ReasonCode,
689 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500690 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500691
James Smarta58cbd52007-08-02 11:09:43 -0400692 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500693 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
694 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
695 (uint32_t) CTrsp->ReasonCode,
696 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400697 }
698
James Smart858c9f62007-06-17 19:56:39 -0500699
dea31012005-04-17 16:05:31 -0500700 } else {
701 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400702 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
703 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500704 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500705 CTrsp->CommandResponse.bits.CmdRsp,
706 (uint32_t) CTrsp->ReasonCode,
707 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500708 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500709
710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
711 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
712 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
713 (uint32_t) CTrsp->ReasonCode,
714 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500715 }
716 }
717 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500718 if (vport->num_disc_nodes == 0) {
719 /*
720 * The driver has cycled through all Nports in the RSCN payload.
721 * Complete the handling by cleaning up and marking the
722 * current driver state.
723 */
724 if (vport->port_state >= LPFC_DISC_AUTH) {
725 if (vport->fc_flag & FC_RSCN_MODE) {
726 lpfc_els_flush_rscn(vport);
727 spin_lock_irq(shost->host_lock);
728 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
729 spin_unlock_irq(shost->host_lock);
730 }
731 else
732 lpfc_els_flush_rscn(vport);
733 }
734
735 lpfc_disc_start(vport);
736 }
dea31012005-04-17 16:05:31 -0500737out:
James Smart51ef4c22007-08-02 11:10:31 -0400738 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500739 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500740 return;
741}
742
James Smart311464e2007-08-02 11:10:37 -0400743static void
James Smart92d7f7b2007-06-17 19:56:38 -0500744lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
745 struct lpfc_iocbq *rspiocb)
746{
747 struct lpfc_vport *vport = cmdiocb->vport;
748 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
749 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500750 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
751 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
752 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500753 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500754 uint8_t fbits;
755 struct lpfc_nodelist *ndlp;
756
757 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
758 did = be32_to_cpu(did);
759
James Smart858c9f62007-06-17 19:56:39 -0500760 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
761 "GFF_ID cmpl: status:x%x/x%x did:x%x",
762 irsp->ulpStatus, irsp->un.ulpWord[4], did);
763
James Smart92d7f7b2007-06-17 19:56:38 -0500764 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
765 /* Good status, continue checking */
766 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
767 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
768
769 if (CTrsp->CommandResponse.bits.CmdRsp ==
770 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
771 if ((fbits & FC4_FEATURE_INIT) &&
772 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400773 lpfc_printf_vlog(vport, KERN_INFO,
774 LOG_DISCOVERY,
775 "0270 Skip x%x GFF "
776 "NameServer Rsp Data: (init) "
777 "x%x x%x\n", did, fbits,
778 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500779 goto out;
780 }
781 }
782 }
James Smart858c9f62007-06-17 19:56:39 -0500783 else {
James Smart0ff10d42008-01-11 01:52:36 -0500784 /* Check for retry */
785 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
786 retry = 1;
787 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
James Smarte3d2b802012-08-14 14:25:43 -0400788 switch ((irsp->un.ulpWord[4] &
789 IOERR_PARAM_MASK)) {
790
James Smart0ff10d42008-01-11 01:52:36 -0500791 case IOERR_NO_RESOURCES:
792 /* We don't increment the retry
793 * count for this case.
794 */
795 break;
796 case IOERR_LINK_DOWN:
797 case IOERR_SLI_ABORTED:
798 case IOERR_SLI_DOWN:
799 retry = 0;
800 break;
801 default:
802 cmdiocb->retry++;
803 }
804 }
805 else
806 cmdiocb->retry++;
807
808 if (retry) {
809 /* CT command is being retried */
810 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
811 cmdiocb->retry, did);
812 if (rc == 0) {
813 /* success */
814 lpfc_ct_free_iocb(phba, cmdiocb);
815 return;
816 }
817 }
818 }
James Smarte8b62012007-08-02 11:10:09 -0400819 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
820 "0267 NameServer GFF Rsp "
821 "x%x Error (%d %d) Data: x%x x%x\n",
822 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500823 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500824 }
825
James Smart92d7f7b2007-06-17 19:56:38 -0500826 /* This is a target port, unregistered port, or the GFF_ID failed */
827 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400828 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400829 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
830 "0242 Process x%x GFF "
831 "NameServer Rsp Data: x%x x%x x%x\n",
832 did, ndlp->nlp_flag, vport->fc_flag,
833 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500834 } else {
James Smarte8b62012007-08-02 11:10:09 -0400835 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
836 "0243 Skip x%x GFF "
837 "NameServer Rsp Data: x%x x%x\n", did,
838 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500839 }
840out:
841 /* Link up / RSCN discovery */
842 if (vport->num_disc_nodes)
843 vport->num_disc_nodes--;
844 if (vport->num_disc_nodes == 0) {
845 /*
846 * The driver has cycled through all Nports in the RSCN payload.
847 * Complete the handling by cleaning up and marking the
848 * current driver state.
849 */
850 if (vport->port_state >= LPFC_DISC_AUTH) {
851 if (vport->fc_flag & FC_RSCN_MODE) {
852 lpfc_els_flush_rscn(vport);
853 spin_lock_irq(shost->host_lock);
854 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
855 spin_unlock_irq(shost->host_lock);
856 }
857 else
858 lpfc_els_flush_rscn(vport);
859 }
860 lpfc_disc_start(vport);
861 }
James Smart858c9f62007-06-17 19:56:39 -0500862 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500863 return;
864}
865
866
dea31012005-04-17 16:05:31 -0500867static void
James Smart7ee5d432007-10-27 13:37:17 -0400868lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
869 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500870{
James Smart92d7f7b2007-06-17 19:56:38 -0500871 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500872 struct lpfc_dmabuf *inp;
873 struct lpfc_dmabuf *outp;
874 IOCB_t *irsp;
875 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400876 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500877 int cmdcode, rc;
878 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500879 uint32_t latt;
dea31012005-04-17 16:05:31 -0500880
James Smart51ef4c22007-08-02 11:10:31 -0400881 /* First save ndlp, before we overwrite it */
882 ndlp = cmdiocb->context_un.ndlp;
883
dea31012005-04-17 16:05:31 -0500884 /* we pass cmdiocb to state machine which needs rspiocb as well */
885 cmdiocb->context_un.rsp_iocb = rspiocb;
886
887 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
888 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500889 irsp = &rspiocb->iocb;
890
James Smart92d7f7b2007-06-17 19:56:38 -0500891 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
892 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500893 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
894
James Smart858c9f62007-06-17 19:56:39 -0500895 latt = lpfc_els_chk_latt(vport);
896
897 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400898 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400899 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400900 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
901 latt, irsp->ulpStatus,
902 CTrsp->CommandResponse.bits.CmdRsp,
903 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500904
James Smart858c9f62007-06-17 19:56:39 -0500905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
906 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
907 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
908
James Smart92d7f7b2007-06-17 19:56:38 -0500909 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400910 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
911 "0268 NS cmd %x Error (%d %d)\n",
912 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500913
James Smart92d7f7b2007-06-17 19:56:38 -0500914 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400915 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
916 IOERR_SLI_DOWN) ||
917 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
918 IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -0500919 goto out;
920
921 retry = cmdiocb->retry;
922 if (retry >= LPFC_MAX_NS_RETRY)
923 goto out;
924
925 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400926 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -0400927 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500928 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
929 if (rc == 0)
930 goto out;
931 }
932
933out:
James Smart51ef4c22007-08-02 11:10:31 -0400934 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500935 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500936 return;
937}
938
939static void
James Smart7ee5d432007-10-27 13:37:17 -0400940lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
941 struct lpfc_iocbq *rspiocb)
942{
943 IOCB_t *irsp = &rspiocb->iocb;
944 struct lpfc_vport *vport = cmdiocb->vport;
945
James Smart98c9ea52007-10-27 13:37:33 -0400946 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
947 struct lpfc_dmabuf *outp;
948 struct lpfc_sli_ct_request *CTrsp;
949
950 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
951 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
952 if (CTrsp->CommandResponse.bits.CmdRsp ==
953 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
954 vport->ct_flags |= FC_CT_RFT_ID;
955 }
James Smart7ee5d432007-10-27 13:37:17 -0400956 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
957 return;
958}
959
960static void
James Smart2e0fef82007-06-17 19:56:36 -0500961lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
962 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500963{
James Smart7ee5d432007-10-27 13:37:17 -0400964 IOCB_t *irsp = &rspiocb->iocb;
965 struct lpfc_vport *vport = cmdiocb->vport;
966
James Smart98c9ea52007-10-27 13:37:33 -0400967 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
968 struct lpfc_dmabuf *outp;
969 struct lpfc_sli_ct_request *CTrsp;
970
971 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
972 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
973 if (CTrsp->CommandResponse.bits.CmdRsp ==
974 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
975 vport->ct_flags |= FC_CT_RNN_ID;
976 }
James Smart7ee5d432007-10-27 13:37:17 -0400977 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500978 return;
979}
980
981static void
James Smart92d7f7b2007-06-17 19:56:38 -0500982lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
983 struct lpfc_iocbq *rspiocb)
984{
James Smart7ee5d432007-10-27 13:37:17 -0400985 IOCB_t *irsp = &rspiocb->iocb;
986 struct lpfc_vport *vport = cmdiocb->vport;
987
James Smart98c9ea52007-10-27 13:37:33 -0400988 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
989 struct lpfc_dmabuf *outp;
990 struct lpfc_sli_ct_request *CTrsp;
991
992 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
993 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
994 if (CTrsp->CommandResponse.bits.CmdRsp ==
995 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
996 vport->ct_flags |= FC_CT_RSPN_ID;
997 }
James Smart7ee5d432007-10-27 13:37:17 -0400998 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500999 return;
1000}
1001
1002static void
James Smart2e0fef82007-06-17 19:56:36 -05001003lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1004 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001005{
James Smart7ee5d432007-10-27 13:37:17 -04001006 IOCB_t *irsp = &rspiocb->iocb;
1007 struct lpfc_vport *vport = cmdiocb->vport;
1008
James Smart98c9ea52007-10-27 13:37:33 -04001009 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1010 struct lpfc_dmabuf *outp;
1011 struct lpfc_sli_ct_request *CTrsp;
1012
1013 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1014 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1015 if (CTrsp->CommandResponse.bits.CmdRsp ==
1016 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1017 vport->ct_flags |= FC_CT_RSNN_NN;
1018 }
James Smart7ee5d432007-10-27 13:37:17 -04001019 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1020 return;
1021}
1022
1023static void
1024lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1025 struct lpfc_iocbq *rspiocb)
1026{
1027 struct lpfc_vport *vport = cmdiocb->vport;
1028
1029 /* even if it fails we will act as though it succeeded. */
1030 vport->ct_flags = 0;
1031 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001032 return;
1033}
1034
James Smart2fb9bd82006-12-02 13:33:57 -05001035static void
James Smart92d7f7b2007-06-17 19:56:38 -05001036lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1037 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001038{
James Smart92d7f7b2007-06-17 19:56:38 -05001039 IOCB_t *irsp = &rspiocb->iocb;
1040 struct lpfc_vport *vport = cmdiocb->vport;
1041
James Smart98c9ea52007-10-27 13:37:33 -04001042 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1043 struct lpfc_dmabuf *outp;
1044 struct lpfc_sli_ct_request *CTrsp;
1045
1046 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1047 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1048 if (CTrsp->CommandResponse.bits.CmdRsp ==
1049 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1050 vport->ct_flags |= FC_CT_RFF_ID;
1051 }
James Smart7ee5d432007-10-27 13:37:17 -04001052 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001053 return;
1054}
1055
James Smart495a7142008-06-14 22:52:59 -04001056int
James Smart92d7f7b2007-06-17 19:56:38 -05001057lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1058 size_t size)
1059{
1060 int n;
1061 uint8_t *wwn = vport->phba->wwpn;
1062
1063 n = snprintf(symbol, size,
1064 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1065 wwn[0], wwn[1], wwn[2], wwn[3],
1066 wwn[4], wwn[5], wwn[6], wwn[7]);
1067
1068 if (vport->port_type == LPFC_PHYSICAL_PORT)
1069 return n;
1070
1071 if (n < size)
1072 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1073
James Smarteada2722008-12-04 22:39:13 -05001074 if (n < size &&
1075 strlen(vport->fc_vport->symbolic_name))
1076 n += snprintf(symbol + n, size - n, " VName-%s",
1077 vport->fc_vport->symbolic_name);
James Smart92d7f7b2007-06-17 19:56:38 -05001078 return n;
1079}
1080
1081int
1082lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1083 size_t size)
dea31012005-04-17 16:05:31 -05001084{
James Smart6b5151f2012-01-18 16:24:06 -05001085 char fwrev[FW_REV_STR_SIZE];
James Smart92d7f7b2007-06-17 19:56:38 -05001086 int n;
dea31012005-04-17 16:05:31 -05001087
James Smart92d7f7b2007-06-17 19:56:38 -05001088 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001089
James Smart92d7f7b2007-06-17 19:56:38 -05001090 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1091 vport->phba->ModelName, fwrev, lpfc_release_version);
1092 return n;
dea31012005-04-17 16:05:31 -05001093}
1094
1095/*
1096 * lpfc_ns_cmd
1097 * Description:
1098 * Issue Cmd to NameServer
1099 * SLI_CTNS_GID_FT
1100 * LI_CTNS_RFT_ID
1101 */
1102int
James Smart92d7f7b2007-06-17 19:56:38 -05001103lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1104 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001105{
James Smart92d7f7b2007-06-17 19:56:38 -05001106 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001107 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001108 struct lpfc_dmabuf *mp, *bmp;
1109 struct lpfc_sli_ct_request *CtReq;
1110 struct ulp_bde64 *bpl;
1111 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1112 struct lpfc_iocbq *) = NULL;
1113 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001114 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001115 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001116
1117 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001118 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1119 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001120 rc=1;
1121 goto ns_cmd_exit;
1122 }
dea31012005-04-17 16:05:31 -05001123
1124 /* fill in BDEs for command */
1125 /* Allocate buffer for command payload */
1126 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001127 if (!mp) {
1128 rc=2;
dea31012005-04-17 16:05:31 -05001129 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001130 }
dea31012005-04-17 16:05:31 -05001131
1132 INIT_LIST_HEAD(&mp->list);
1133 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001134 if (!mp->virt) {
1135 rc=3;
dea31012005-04-17 16:05:31 -05001136 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001137 }
dea31012005-04-17 16:05:31 -05001138
1139 /* Allocate buffer for Buffer ptr list */
1140 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001141 if (!bmp) {
1142 rc=4;
dea31012005-04-17 16:05:31 -05001143 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001144 }
dea31012005-04-17 16:05:31 -05001145
1146 INIT_LIST_HEAD(&bmp->list);
1147 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001148 if (!bmp->virt) {
1149 rc=5;
dea31012005-04-17 16:05:31 -05001150 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001151 }
dea31012005-04-17 16:05:31 -05001152
1153 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001154 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1155 "0236 NameServer Req Data: x%x x%x x%x\n",
1156 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001157
1158 bpl = (struct ulp_bde64 *) bmp->virt;
1159 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001160 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1161 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001162 bpl->tus.f.bdeFlags = 0;
1163 if (cmdcode == SLI_CTNS_GID_FT)
1164 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001165 else if (cmdcode == SLI_CTNS_GFF_ID)
1166 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001167 else if (cmdcode == SLI_CTNS_RFT_ID)
1168 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1169 else if (cmdcode == SLI_CTNS_RNN_ID)
1170 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001171 else if (cmdcode == SLI_CTNS_RSPN_ID)
1172 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001173 else if (cmdcode == SLI_CTNS_RSNN_NN)
1174 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001175 else if (cmdcode == SLI_CTNS_DA_ID)
1176 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001177 else if (cmdcode == SLI_CTNS_RFF_ID)
1178 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001179 else
1180 bpl->tus.f.bdeSize = 0;
1181 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1182
1183 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1184 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1185 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1186 CtReq->RevisionId.bits.InId = 0;
1187 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1188 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1189 CtReq->CommandResponse.bits.Size = 0;
1190 switch (cmdcode) {
1191 case SLI_CTNS_GID_FT:
1192 CtReq->CommandResponse.bits.CmdRsp =
1193 be16_to_cpu(SLI_CTNS_GID_FT);
1194 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001195 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001196 vport->port_state = LPFC_NS_QRY;
1197 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001198 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1199 rsp_size = FC_MAX_NS_RSP;
1200 break;
1201
James Smart92d7f7b2007-06-17 19:56:38 -05001202 case SLI_CTNS_GFF_ID:
1203 CtReq->CommandResponse.bits.CmdRsp =
1204 be16_to_cpu(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001205 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001206 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1207 break;
1208
dea31012005-04-17 16:05:31 -05001209 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001210 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001211 CtReq->CommandResponse.bits.CmdRsp =
1212 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001213 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001214 CtReq->un.rft.fcpReg = 1;
1215 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1216 break;
1217
1218 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001219 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001220 CtReq->CommandResponse.bits.CmdRsp =
1221 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001222 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001223 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001224 sizeof (struct lpfc_name));
1225 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1226 break;
1227
James Smart92d7f7b2007-06-17 19:56:38 -05001228 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001229 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001230 CtReq->CommandResponse.bits.CmdRsp =
1231 be16_to_cpu(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001232 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001233 size = sizeof(CtReq->un.rspn.symbname);
1234 CtReq->un.rspn.len =
1235 lpfc_vport_symbolic_port_name(vport,
1236 CtReq->un.rspn.symbname, size);
1237 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1238 break;
dea31012005-04-17 16:05:31 -05001239 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001240 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001241 CtReq->CommandResponse.bits.CmdRsp =
1242 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001243 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001244 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001245 size = sizeof(CtReq->un.rsnn.symbname);
1246 CtReq->un.rsnn.len =
1247 lpfc_vport_symbolic_node_name(vport,
1248 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001249 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1250 break;
James Smart7ee5d432007-10-27 13:37:17 -04001251 case SLI_CTNS_DA_ID:
1252 /* Implement DA_ID Nameserver request */
1253 CtReq->CommandResponse.bits.CmdRsp =
1254 be16_to_cpu(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001255 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001256 cmpl = lpfc_cmpl_ct_cmd_da_id;
1257 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001258 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001259 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001260 CtReq->CommandResponse.bits.CmdRsp =
1261 be16_to_cpu(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001262 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001263 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smart6a9c52c2009-10-02 15:16:51 -04001264 CtReq->un.rff.type_code = FC_TYPE_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001265 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1266 break;
dea31012005-04-17 16:05:31 -05001267 }
James Smarte47c9092008-02-08 18:49:26 -05001268 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1269 * to hold ndlp reference for the corresponding callback function.
1270 */
James Smart858c9f62007-06-17 19:56:39 -05001271 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001272 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001273 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1274 "Issue CT cmd: cmd:x%x did:x%x",
1275 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001276 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001277 }
James Smart858c9f62007-06-17 19:56:39 -05001278 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001279
1280 /* Decrement ndlp reference count to release ndlp reference held
1281 * for the failed command's callback function.
1282 */
James Smart51ef4c22007-08-02 11:10:31 -04001283 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001284
dea31012005-04-17 16:05:31 -05001285 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1286ns_cmd_free_bmp:
1287 kfree(bmp);
1288ns_cmd_free_mpvirt:
1289 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1290ns_cmd_free_mp:
1291 kfree(mp);
1292ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001293 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1294 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1295 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001296 return 1;
1297}
1298
1299static void
James Smart2e0fef82007-06-17 19:56:36 -05001300lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1301 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001302{
dea31012005-04-17 16:05:31 -05001303 struct lpfc_dmabuf *inp = cmdiocb->context1;
1304 struct lpfc_dmabuf *outp = cmdiocb->context2;
1305 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1306 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1307 struct lpfc_nodelist *ndlp;
1308 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1309 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001310 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001311 IOCB_t *irsp = &rspiocb->iocb;
1312 uint32_t latt;
1313
1314 latt = lpfc_els_chk_latt(vport);
1315
1316 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1317 "FDMI cmpl: status:x%x/x%x latt:%d",
1318 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1319
1320 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001321 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1322 "0229 FDMI cmd %04x failed, latt = %d "
1323 "ulpStatus: x%x, rid x%x\n",
1324 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1325 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001326 lpfc_ct_free_iocb(phba, cmdiocb);
1327 return;
1328 }
dea31012005-04-17 16:05:31 -05001329
James Smart2e0fef82007-06-17 19:56:36 -05001330 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001331 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1332 goto fail_out;
1333
dea31012005-04-17 16:05:31 -05001334 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1335 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001336 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1337 "0220 FDMI rsp failed Data: x%x\n",
1338 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001339 }
1340
1341 switch (be16_to_cpu(fdmi_cmd)) {
1342 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001343 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001344 break;
1345
1346 case SLI_MGMT_RPA:
1347 break;
1348
1349 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001350 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001351 break;
1352
1353 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001354 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001355 break;
1356 }
James Smarte47c9092008-02-08 18:49:26 -05001357
1358fail_out:
James Smart858c9f62007-06-17 19:56:39 -05001359 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001360 return;
1361}
James Smart2e0fef82007-06-17 19:56:36 -05001362
dea31012005-04-17 16:05:31 -05001363int
James Smart2e0fef82007-06-17 19:56:36 -05001364lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001365{
James Smart2e0fef82007-06-17 19:56:36 -05001366 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001367 struct lpfc_dmabuf *mp, *bmp;
1368 struct lpfc_sli_ct_request *CtReq;
1369 struct ulp_bde64 *bpl;
1370 uint32_t size;
1371 REG_HBA *rh;
1372 PORT_ENTRY *pe;
1373 REG_PORT_ATTRIBUTE *pab;
1374 ATTRIBUTE_BLOCK *ab;
1375 ATTRIBUTE_ENTRY *ae;
1376 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1377 struct lpfc_iocbq *);
1378
1379
1380 /* fill in BDEs for command */
1381 /* Allocate buffer for command payload */
1382 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1383 if (!mp)
1384 goto fdmi_cmd_exit;
1385
1386 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1387 if (!mp->virt)
1388 goto fdmi_cmd_free_mp;
1389
1390 /* Allocate buffer for Buffer ptr list */
1391 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1392 if (!bmp)
1393 goto fdmi_cmd_free_mpvirt;
1394
1395 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1396 if (!bmp->virt)
1397 goto fdmi_cmd_free_bmp;
1398
1399 INIT_LIST_HEAD(&mp->list);
1400 INIT_LIST_HEAD(&bmp->list);
1401
1402 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001403 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1404 "0218 FDMI Request Data: x%x x%x x%x\n",
1405 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001406 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1407
1408 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1409 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1410 CtReq->RevisionId.bits.InId = 0;
1411
1412 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1413 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1414 size = 0;
1415
1416 switch (cmdcode) {
1417 case SLI_MGMT_RHBA:
1418 {
1419 lpfc_vpd_t *vp = &phba->vpd;
1420 uint32_t i, j, incr;
1421 int len;
1422
1423 CtReq->CommandResponse.bits.CmdRsp =
1424 be16_to_cpu(SLI_MGMT_RHBA);
1425 CtReq->CommandResponse.bits.Size = 0;
1426 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001427 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001428 sizeof (struct lpfc_name));
1429 /* One entry (port) per adapter */
1430 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001431 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001432 sizeof (struct lpfc_name));
1433
1434 /* point to the HBA attribute block */
1435 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1436 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1437 ab->EntryCnt = 0;
1438
1439 /* Point to the beginning of the first HBA attribute
1440 entry */
1441 /* #1 HBA attribute entry */
1442 size += FOURBYTES;
1443 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1444 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1445 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1446 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001447 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001448 sizeof (struct lpfc_name));
1449 ab->EntryCnt++;
1450 size += FOURBYTES + sizeof (struct lpfc_name);
1451
1452 /* #2 HBA attribute entry */
1453 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1454 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1455 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1456 len = strlen(ae->un.Manufacturer);
1457 len += (len & 3) ? (4 - (len & 3)) : 4;
1458 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1459 ab->EntryCnt++;
1460 size += FOURBYTES + len;
1461
1462 /* #3 HBA attribute entry */
1463 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1464 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1465 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1466 len = strlen(ae->un.SerialNumber);
1467 len += (len & 3) ? (4 - (len & 3)) : 4;
1468 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1469 ab->EntryCnt++;
1470 size += FOURBYTES + len;
1471
1472 /* #4 HBA attribute entry */
1473 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1474 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1475 strcpy(ae->un.Model, phba->ModelName);
1476 len = strlen(ae->un.Model);
1477 len += (len & 3) ? (4 - (len & 3)) : 4;
1478 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1479 ab->EntryCnt++;
1480 size += FOURBYTES + len;
1481
1482 /* #5 HBA attribute entry */
1483 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1484 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1485 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1486 len = strlen(ae->un.ModelDescription);
1487 len += (len & 3) ? (4 - (len & 3)) : 4;
1488 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1489 ab->EntryCnt++;
1490 size += FOURBYTES + len;
1491
1492 /* #6 HBA attribute entry */
1493 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1494 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1495 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1496 /* Convert JEDEC ID to ascii for hardware version */
1497 incr = vp->rev.biuRev;
1498 for (i = 0; i < 8; i++) {
1499 j = (incr & 0xf);
1500 if (j <= 9)
1501 ae->un.HardwareVersion[7 - i] =
1502 (char)((uint8_t) 0x30 +
1503 (uint8_t) j);
1504 else
1505 ae->un.HardwareVersion[7 - i] =
1506 (char)((uint8_t) 0x61 +
1507 (uint8_t) (j - 10));
1508 incr = (incr >> 4);
1509 }
1510 ab->EntryCnt++;
1511 size += FOURBYTES + 8;
1512
1513 /* #7 HBA attribute entry */
1514 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1515 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1516 strcpy(ae->un.DriverVersion, lpfc_release_version);
1517 len = strlen(ae->un.DriverVersion);
1518 len += (len & 3) ? (4 - (len & 3)) : 4;
1519 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1520 ab->EntryCnt++;
1521 size += FOURBYTES + len;
1522
1523 /* #8 HBA attribute entry */
1524 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1525 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1526 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1527 len = strlen(ae->un.OptionROMVersion);
1528 len += (len & 3) ? (4 - (len & 3)) : 4;
1529 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1530 ab->EntryCnt++;
1531 size += FOURBYTES + len;
1532
1533 /* #9 HBA attribute entry */
1534 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1535 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1536 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1537 1);
1538 len = strlen(ae->un.FirmwareVersion);
1539 len += (len & 3) ? (4 - (len & 3)) : 4;
1540 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1541 ab->EntryCnt++;
1542 size += FOURBYTES + len;
1543
1544 /* #10 HBA attribute entry */
1545 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1546 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1547 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001548 init_utsname()->sysname,
1549 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001550 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001551 len = strlen(ae->un.OsNameVersion);
1552 len += (len & 3) ? (4 - (len & 3)) : 4;
1553 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1554 ab->EntryCnt++;
1555 size += FOURBYTES + len;
1556
1557 /* #11 HBA attribute entry */
1558 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1559 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1560 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1561 ae->un.MaxCTPayloadLen = (65 * 4096);
1562 ab->EntryCnt++;
1563 size += FOURBYTES + 4;
1564
1565 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1566 /* Total size */
1567 size = GID_REQUEST_SZ - 4 + size;
1568 }
1569 break;
1570
1571 case SLI_MGMT_RPA:
1572 {
1573 lpfc_vpd_t *vp;
1574 struct serv_parm *hsp;
1575 int len;
1576
1577 vp = &phba->vpd;
1578
1579 CtReq->CommandResponse.bits.CmdRsp =
1580 be16_to_cpu(SLI_MGMT_RPA);
1581 CtReq->CommandResponse.bits.Size = 0;
1582 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1583 size = sizeof (struct lpfc_name) + FOURBYTES;
1584 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001585 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001586 sizeof (struct lpfc_name));
1587 pab->ab.EntryCnt = 0;
1588
1589 /* #1 Port attribute entry */
1590 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1591 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1592 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1593 ae->un.SupportFC4Types[2] = 1;
1594 ae->un.SupportFC4Types[7] = 1;
1595 pab->ab.EntryCnt++;
1596 size += FOURBYTES + 32;
1597
1598 /* #2 Port attribute entry */
1599 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1600 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1601 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001602
1603 ae->un.SupportSpeed = 0;
James Smart76a95d72010-11-20 23:11:48 -05001604 if (phba->lmt & LMT_16Gb)
1605 ae->un.SupportSpeed |= HBA_PORTSPEED_16GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001606 if (phba->lmt & LMT_10Gb)
James Smart76a95d72010-11-20 23:11:48 -05001607 ae->un.SupportSpeed |= HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001608 if (phba->lmt & LMT_8Gb)
1609 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1610 if (phba->lmt & LMT_4Gb)
1611 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1612 if (phba->lmt & LMT_2Gb)
1613 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1614 if (phba->lmt & LMT_1Gb)
1615 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1616
dea31012005-04-17 16:05:31 -05001617 pab->ab.EntryCnt++;
1618 size += FOURBYTES + 4;
1619
1620 /* #3 Port attribute entry */
1621 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1622 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1623 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1624 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05001625 case LPFC_LINK_SPEED_1GHZ:
1626 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05001627 break;
James Smart76a95d72010-11-20 23:11:48 -05001628 case LPFC_LINK_SPEED_2GHZ:
1629 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05001630 break;
James Smart76a95d72010-11-20 23:11:48 -05001631 case LPFC_LINK_SPEED_4GHZ:
1632 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05001633 break;
James Smart76a95d72010-11-20 23:11:48 -05001634 case LPFC_LINK_SPEED_8GHZ:
1635 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04001636 break;
James Smart76a95d72010-11-20 23:11:48 -05001637 case LPFC_LINK_SPEED_10GHZ:
1638 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04001639 break;
James Smart76a95d72010-11-20 23:11:48 -05001640 case LPFC_LINK_SPEED_16GHZ:
1641 ae->un.PortSpeed = HBA_PORTSPEED_16GBIT;
1642 break;
1643 default:
1644 ae->un.PortSpeed = HBA_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05001645 break;
1646 }
1647 pab->ab.EntryCnt++;
1648 size += FOURBYTES + 4;
1649
1650 /* #4 Port attribute entry */
1651 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1652 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1653 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001654 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001655 ae->un.MaxFrameSize =
1656 (((uint32_t) hsp->cmn.
1657 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1658 bbRcvSizeLsb;
1659 pab->ab.EntryCnt++;
1660 size += FOURBYTES + 4;
1661
1662 /* #5 Port attribute entry */
1663 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1664 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1665 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1666 len = strlen((char *)ae->un.OsDeviceName);
1667 len += (len & 3) ? (4 - (len & 3)) : 4;
1668 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1669 pab->ab.EntryCnt++;
1670 size += FOURBYTES + len;
1671
James Smart3de2a652007-08-02 11:09:59 -04001672 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001673 /* #6 Port attribute entry */
1674 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1675 size);
1676 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1677 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001678 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001679 len = strlen(ae->un.HostName);
1680 len += (len & 3) ? (4 - (len & 3)) : 4;
1681 ae->ad.bits.AttrLen =
1682 be16_to_cpu(FOURBYTES + len);
1683 pab->ab.EntryCnt++;
1684 size += FOURBYTES + len;
1685 }
1686
1687 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1688 /* Total size */
1689 size = GID_REQUEST_SZ - 4 + size;
1690 }
1691 break;
1692
1693 case SLI_MGMT_DHBA:
1694 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1695 CtReq->CommandResponse.bits.Size = 0;
1696 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1697 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001698 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001699 sizeof (struct lpfc_name));
1700 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1701 break;
1702
1703 case SLI_MGMT_DPRT:
1704 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1705 CtReq->CommandResponse.bits.Size = 0;
1706 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1707 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001708 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001709 sizeof (struct lpfc_name));
1710 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1711 break;
1712 }
1713
1714 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001715 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1716 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001717 bpl->tus.f.bdeFlags = 0;
1718 bpl->tus.f.bdeSize = size;
1719 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1720
1721 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1722
James Smarte47c9092008-02-08 18:49:26 -05001723 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1724 * to hold ndlp reference for the corresponding callback function.
1725 */
James Smart92d7f7b2007-06-17 19:56:38 -05001726 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001727 return 0;
1728
James Smarte47c9092008-02-08 18:49:26 -05001729 /* Decrement ndlp reference count to release ndlp reference held
1730 * for the failed command's callback function.
1731 */
James Smart51ef4c22007-08-02 11:10:31 -04001732 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001733
dea31012005-04-17 16:05:31 -05001734 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1735fdmi_cmd_free_bmp:
1736 kfree(bmp);
1737fdmi_cmd_free_mpvirt:
1738 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1739fdmi_cmd_free_mp:
1740 kfree(mp);
1741fdmi_cmd_exit:
1742 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001743 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1744 "0244 Issue FDMI request failed Data: x%x\n",
1745 cmdcode);
dea31012005-04-17 16:05:31 -05001746 return 1;
1747}
1748
James Smart92494142011-02-16 12:39:44 -05001749/**
1750 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
1751 * @ptr - Context object of the timer.
1752 *
1753 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
1754 * the worker thread.
1755 **/
1756void
1757lpfc_delayed_disc_tmo(unsigned long ptr)
1758{
1759 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1760 struct lpfc_hba *phba = vport->phba;
1761 uint32_t tmo_posted;
1762 unsigned long iflag;
1763
1764 spin_lock_irqsave(&vport->work_port_lock, iflag);
1765 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
1766 if (!tmo_posted)
1767 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
1768 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1769
1770 if (!tmo_posted)
1771 lpfc_worker_wake_up(phba);
1772 return;
1773}
1774
1775/**
1776 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
1777 * handle delayed discovery.
1778 * @vport: pointer to a host virtual N_Port data structure.
1779 *
1780 * This function start nport discovery of the vport.
1781 **/
1782void
1783lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
1784{
1785 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1786
1787 spin_lock_irq(shost->host_lock);
1788 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
1789 spin_unlock_irq(shost->host_lock);
1790 return;
1791 }
1792 vport->fc_flag &= ~FC_DISC_DELAYED;
1793 spin_unlock_irq(shost->host_lock);
1794
1795 lpfc_do_scr_ns_plogi(vport->phba, vport);
1796}
1797
dea31012005-04-17 16:05:31 -05001798void
1799lpfc_fdmi_tmo(unsigned long ptr)
1800{
James Smart2e0fef82007-06-17 19:56:36 -05001801 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1802 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001803 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05001804 unsigned long iflag;
1805
James Smart2e0fef82007-06-17 19:56:36 -05001806 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001807 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1808 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05001809 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04001810 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001811
James Smart5e9d9b82008-06-14 22:52:53 -04001812 if (!tmo_posted)
1813 lpfc_worker_wake_up(phba);
1814 return;
dea31012005-04-17 16:05:31 -05001815}
1816
1817void
James Smart2e0fef82007-06-17 19:56:36 -05001818lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001819{
1820 struct lpfc_nodelist *ndlp;
1821
James Smart2e0fef82007-06-17 19:56:36 -05001822 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001823 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001824 if (init_utsname()->nodename[0] != '\0')
1825 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1826 else
1827 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001828 }
dea31012005-04-17 16:05:31 -05001829 return;
1830}
1831
dea31012005-04-17 16:05:31 -05001832void
James Smart2e0fef82007-06-17 19:56:36 -05001833lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001834{
1835 struct lpfc_sli *psli = &phba->sli;
1836 lpfc_vpd_t *vp = &phba->vpd;
1837 uint32_t b1, b2, b3, b4, i, rev;
1838 char c;
1839 uint32_t *ptr, str[4];
1840 uint8_t *fwname;
1841
James Smartf1126682009-06-10 17:22:44 -04001842 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart6b5151f2012-01-18 16:24:06 -05001843 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
James Smartf1126682009-06-10 17:22:44 -04001844 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04001845 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001846 rev = vp->rev.sli2FwRev;
1847 else
1848 rev = vp->rev.sli1FwRev;
1849
1850 b1 = (rev & 0x0000f000) >> 12;
1851 b2 = (rev & 0x00000f00) >> 8;
1852 b3 = (rev & 0x000000c0) >> 6;
1853 b4 = (rev & 0x00000030) >> 4;
1854
1855 switch (b4) {
1856 case 0:
1857 c = 'N';
1858 break;
1859 case 1:
1860 c = 'A';
1861 break;
1862 case 2:
1863 c = 'B';
1864 break;
James Smart73d91e52011-10-10 21:32:10 -04001865 case 3:
1866 c = 'X';
1867 break;
dea31012005-04-17 16:05:31 -05001868 default:
1869 c = 0;
1870 break;
1871 }
1872 b4 = (rev & 0x0000000f);
1873
James Smartf4b4c682009-05-22 14:53:12 -04001874 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001875 fwname = vp->rev.sli2FwName;
1876 else
1877 fwname = vp->rev.sli1FwName;
1878
1879 for (i = 0; i < 16; i++)
1880 if (fwname[i] == 0x20)
1881 fwname[i] = 0;
1882
1883 ptr = (uint32_t*)fwname;
1884
1885 for (i = 0; i < 3; i++)
1886 str[i] = be32_to_cpu(*ptr++);
1887
1888 if (c == 0) {
1889 if (flag)
1890 sprintf(fwrevision, "%d.%d%d (%s)",
1891 b1, b2, b3, (char *)str);
1892 else
1893 sprintf(fwrevision, "%d.%d%d", b1,
1894 b2, b3);
1895 } else {
1896 if (flag)
1897 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1898 b1, b2, b3, c,
1899 b4, (char *)str);
1900 else
1901 sprintf(fwrevision, "%d.%d%d%c%d",
1902 b1, b2, b3, c, b4);
1903 }
1904 } else {
1905 rev = vp->rev.smFwRev;
1906
1907 b1 = (rev & 0xff000000) >> 24;
1908 b2 = (rev & 0x00f00000) >> 20;
1909 b3 = (rev & 0x000f0000) >> 16;
1910 c = (rev & 0x0000ff00) >> 8;
1911 b4 = (rev & 0x000000ff);
1912
Roel Kluind44a6d22010-01-17 16:15:57 +01001913 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05001914 }
1915 return;
1916}