blob: 707081d0a2265ad88e7d4b18c25ca0d51d2a9998 [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) &&
107 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500108 /* Not enough posted buffers; Try posting more buffers */
109 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500110 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400111 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500112 return;
113 }
114
115 /* If there are no BDEs associated with this IOCB,
116 * there is nothing to do.
117 */
118 if (icmd->ulpBdeCount == 0)
119 return;
120
James Smarted957682007-06-17 19:56:37 -0500121 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500122 INIT_LIST_HEAD(&head);
123 list_add_tail(&head, &piocbq->list);
124 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500125 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500126 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500127 continue;
James Smart9c2face2008-01-11 01:53:18 -0500128 bdeBuf = iocbq->context2;
129 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500130 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500131 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
132 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500133 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500134 bdeBuf = iocbq->context3;
135 iocbq->context3 = NULL;
136 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
137 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
138 size);
139 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500140 }
dea31012005-04-17 16:05:31 -0500141 }
James Smart9c2face2008-01-11 01:53:18 -0500142 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500143 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400144 INIT_LIST_HEAD(&head);
145 list_add_tail(&head, &piocbq->list);
146 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500147 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500148 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400149 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500150 for (i = 0; i < icmd->ulpBdeCount; i++) {
151 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
152 icmd->un.cont64[i].addrLow);
153 mp = lpfc_sli_ringpostbuf_get(phba, pring,
154 paddr);
155 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400156 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500157 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500158 }
James Smart495a7142008-06-14 22:52:59 -0400159 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500160 }
James Smartd7c255b2008-08-24 21:50:00 -0400161 list_del(&head);
dea31012005-04-17 16:05:31 -0500162 }
dea31012005-04-17 16:05:31 -0500163}
164
James Smart6669f9b2009-10-02 15:16:45 -0400165/**
166 * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort
167 * @phba: Pointer to HBA context object.
168 * @pring: Pointer to the driver internal I/O ring.
169 * @piocbq: Pointer to the IOCBQ.
170 *
171 * This function serves as the default handler for the sli4 unsolicited
172 * abort event. It shall be invoked when there is no application interface
173 * registered unsolicited abort handler. This handler does nothing but
174 * just simply releases the dma buffer used by the unsol abort event.
175 **/
176void
177lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
178 struct lpfc_sli_ring *pring,
179 struct lpfc_iocbq *piocbq)
180{
181 IOCB_t *icmd = &piocbq->iocb;
182 struct lpfc_dmabuf *bdeBuf;
183 uint32_t size;
184
185 /* Forward abort event to any process registered to receive ct event */
James Smart4fede782010-01-26 23:08:55 -0500186 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
187 return;
James Smart6669f9b2009-10-02 15:16:45 -0400188
189 /* If there is no BDE associated with IOCB, there is nothing to do */
190 if (icmd->ulpBdeCount == 0)
191 return;
192 bdeBuf = piocbq->context2;
193 piocbq->context2 = NULL;
194 size = icmd->un.cont64[0].tus.f.bdeSize;
195 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
196 lpfc_in_buf_free(phba, bdeBuf);
197}
198
dea31012005-04-17 16:05:31 -0500199static void
James Smart2e0fef82007-06-17 19:56:36 -0500200lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500201{
202 struct lpfc_dmabuf *mlast, *next_mlast;
203
204 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
205 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
206 list_del(&mlast->list);
207 kfree(mlast);
208 }
209 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
210 kfree(mlist);
211 return;
212}
213
214static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500215lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500216 uint32_t size, int *entries)
217{
218 struct lpfc_dmabuf *mlist = NULL;
219 struct lpfc_dmabuf *mp;
220 int cnt, i = 0;
221
James Smart09372822008-01-11 01:52:54 -0500222 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500223 cnt = size > FCELSSIZE ? FCELSSIZE: size;
224
225 while (size) {
226 /* Allocate buffer for rsp payload */
227 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
228 if (!mp) {
229 if (mlist)
230 lpfc_free_ct_rsp(phba, mlist);
231 return NULL;
232 }
233
234 INIT_LIST_HEAD(&mp->list);
235
James Smart92d7f7b2007-06-17 19:56:38 -0500236 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
237 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500238 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
239 else
240 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
241
242 if (!mp->virt) {
243 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700244 if (mlist)
245 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500246 return NULL;
247 }
248
249 /* Queue it to a linked list */
250 if (!mlist)
251 mlist = mp;
252 else
253 list_add_tail(&mp->list, &mlist->list);
254
James Smart34b02dc2008-08-24 21:49:55 -0400255 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500256 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500257 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
258 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500259 bpl->tus.f.bdeSize = (uint16_t) cnt;
260 bpl->tus.w = le32_to_cpu(bpl->tus.w);
261 bpl++;
262
263 i++;
264 size -= cnt;
265 }
266
267 *entries = i;
268 return mlist;
269}
270
James Smart858c9f62007-06-17 19:56:39 -0500271int
272lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
273{
274 struct lpfc_dmabuf *buf_ptr;
275
James Smart51ef4c22007-08-02 11:10:31 -0400276 if (ctiocb->context_un.ndlp) {
277 lpfc_nlp_put(ctiocb->context_un.ndlp);
278 ctiocb->context_un.ndlp = NULL;
279 }
James Smart858c9f62007-06-17 19:56:39 -0500280 if (ctiocb->context1) {
281 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
282 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
283 kfree(buf_ptr);
284 ctiocb->context1 = NULL;
285 }
286 if (ctiocb->context2) {
287 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
288 ctiocb->context2 = NULL;
289 }
290
291 if (ctiocb->context3) {
292 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
293 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
294 kfree(buf_ptr);
295 ctiocb->context1 = NULL;
296 }
297 lpfc_sli_release_iocbq(phba, ctiocb);
298 return 0;
299}
300
dea31012005-04-17 16:05:31 -0500301static int
James Smart2e0fef82007-06-17 19:56:36 -0500302lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500303 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
304 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
305 struct lpfc_iocbq *),
306 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500307 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500308{
James Smart2e0fef82007-06-17 19:56:36 -0500309 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500310 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400311 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500312 int rc;
dea31012005-04-17 16:05:31 -0500313
314 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400315 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500316
317 if (geniocb == NULL)
318 return 1;
dea31012005-04-17 16:05:31 -0500319
320 icmd = &geniocb->iocb;
321 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
322 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
323 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400324 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea31012005-04-17 16:05:31 -0500325 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
326
327 if (usr_flg)
328 geniocb->context3 = NULL;
329 else
330 geniocb->context3 = (uint8_t *) bmp;
331
332 /* Save for completion so we can release these resources */
333 geniocb->context1 = (uint8_t *) inp;
334 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500335 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500336
337 /* Fill in payload, bp points to frame payload */
338 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
339
340 /* Fill in rest of iocb */
341 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
342 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
James Smart6a9c52c2009-10-02 15:16:51 -0400343 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
344 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -0500345
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500346 if (!tmo) {
347 /* FC spec states we need 3 * ratov for CT requests */
348 tmo = (3 * phba->fc_ratov);
349 }
dea31012005-04-17 16:05:31 -0500350 icmd->ulpTimeout = tmo;
351 icmd->ulpBdeCount = 1;
352 icmd->ulpLe = 1;
353 icmd->ulpClass = CLASS3;
354 icmd->ulpContext = ndlp->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -0400355 if (phba->sli_rev == LPFC_SLI_REV4)
356 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea31012005-04-17 16:05:31 -0500357
James Smart92d7f7b2007-06-17 19:56:38 -0500358 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
359 /* For GEN_REQUEST64_CR, use the RPI */
360 icmd->ulpCt_h = 0;
361 icmd->ulpCt_l = 0;
362 }
363
dea31012005-04-17 16:05:31 -0500364 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400365 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
366 "0119 Issue GEN REQ IOCB to NPORT x%x "
367 "Data: x%x x%x\n",
368 ndlp->nlp_DID, icmd->ulpIoTag,
369 vport->port_state);
dea31012005-04-17 16:05:31 -0500370 geniocb->iocb_cmpl = cmpl;
371 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500372 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400374 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500375
376 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500377 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500378 return 1;
379 }
dea31012005-04-17 16:05:31 -0500380
381 return 0;
382}
383
384static int
James Smart2e0fef82007-06-17 19:56:36 -0500385lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500386 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
387 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
388 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500389 uint32_t rsp_size, uint8_t retry)
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 ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
393 struct lpfc_dmabuf *outmp;
394 int cnt = 0, status;
395 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
396 CommandResponse.bits.CmdRsp;
397
398 bpl++; /* Skip past ct request */
399
400 /* Put buffer(s) for ct rsp in bpl */
401 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
402 if (!outmp)
403 return -ENOMEM;
James Smart6a9c52c2009-10-02 15:16:51 -0400404 /*
405 * Form the CT IOCB. The total number of BDEs in this IOCB
406 * is the single command plus response count from
407 * lpfc_alloc_ct_rsp.
408 */
409 cnt += 1;
James Smart2e0fef82007-06-17 19:56:36 -0500410 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart6a9c52c2009-10-02 15:16:51 -0400411 cnt, 0, retry);
dea31012005-04-17 16:05:31 -0500412 if (status) {
413 lpfc_free_ct_rsp(phba, outmp);
414 return -ENOMEM;
415 }
416 return 0;
417}
418
James Smart549e55c2007-08-02 11:09:51 -0400419struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500420lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500421 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400422 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500423
James Smart549e55c2007-08-02 11:09:51 -0400424 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500425 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400426 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
427 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500428 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400429 }
James Smart92d7f7b2007-06-17 19:56:38 -0500430 }
James Smart549e55c2007-08-02 11:09:51 -0400431 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500432 return NULL;
433}
434
dea31012005-04-17 16:05:31 -0500435static int
James Smart2e0fef82007-06-17 19:56:36 -0500436lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500437{
James Smart2e0fef82007-06-17 19:56:36 -0500438 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500439 struct lpfc_sli_ct_request *Response =
440 (struct lpfc_sli_ct_request *) mp->virt;
441 struct lpfc_nodelist *ndlp = NULL;
442 struct lpfc_dmabuf *mlast, *next_mp;
443 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500444 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500445 int Cnt;
446 struct list_head head;
447
James Smart2e0fef82007-06-17 19:56:36 -0500448 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500449 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500450 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500451
dea31012005-04-17 16:05:31 -0500452
453 list_add_tail(&head, &mp->list);
454 list_for_each_entry_safe(mp, next_mp, &head, list) {
455 mlast = mp;
456
James Smart7054a602007-04-25 09:52:34 -0400457 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
458
dea31012005-04-17 16:05:31 -0500459 Size -= Cnt;
460
James Smart1dcb58e2007-04-25 09:51:30 -0400461 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500462 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400463 } else
dea31012005-04-17 16:05:31 -0500464 Cnt -= 16; /* subtract length of CT header */
465
466 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400467 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500468 /* Get next DID from NameServer List */
469 CTentry = *ctptr++;
470 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500471
dea31012005-04-17 16:05:31 -0500472 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500473
474 /*
475 * Check for rscn processing or not
476 * To conserve rpi's, filter out addresses for other
477 * vports on the same physical HBAs.
478 */
479 if ((Did != vport->fc_myDID) &&
480 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400481 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500482 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart98c9ea52007-10-27 13:37:33 -0400483 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
James Smart3de2a652007-08-02 11:09:59 -0400484 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500485 ndlp = lpfc_setup_disc_node(vport, Did);
James Smart58da1ff2008-04-07 10:15:56 -0400486 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500487 lpfc_debugfs_disc_trc(vport,
488 LPFC_DISC_TRC_CT,
489 "Parse GID_FTrsp: "
490 "did:x%x flg:x%x x%x",
491 Did, ndlp->nlp_flag,
492 vport->fc_flag);
493
James Smarte8b62012007-08-02 11:10:09 -0400494 lpfc_printf_vlog(vport,
495 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500496 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400497 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500498 "x%x NameServer Rsp"
499 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400500 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500501 vport->fc_flag,
502 vport->fc_rscn_id_cnt);
503 } else {
James Smart858c9f62007-06-17 19:56:39 -0500504 lpfc_debugfs_disc_trc(vport,
505 LPFC_DISC_TRC_CT,
506 "Skip1 GID_FTrsp: "
507 "did:x%x flg:x%x cnt:%d",
508 Did, vport->fc_flag,
509 vport->fc_rscn_id_cnt);
510
James Smarte8b62012007-08-02 11:10:09 -0400511 lpfc_printf_vlog(vport,
512 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500513 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400514 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500515 "NameServer Rsp Data: "
516 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400517 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500518 vport->fc_rscn_id_cnt);
519 }
520
521 } else {
522 if (!(vport->fc_flag & FC_RSCN_MODE) ||
523 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500524 lpfc_debugfs_disc_trc(vport,
525 LPFC_DISC_TRC_CT,
526 "Query GID_FTrsp: "
527 "did:x%x flg:x%x cnt:%d",
528 Did, vport->fc_flag,
529 vport->fc_rscn_id_cnt);
530
James Smart0ff10d42008-01-11 01:52:36 -0500531 /* This NPortID was previously
532 * a FCP target, * Don't even
533 * bother to send GFF_ID.
534 */
535 ndlp = lpfc_findnode_did(vport,
536 Did);
James Smarte47c9092008-02-08 18:49:26 -0500537 if (ndlp &&
538 NLP_CHK_NODE_ACT(ndlp)
539 && (ndlp->nlp_type &
540 NLP_FCP_TARGET))
James Smart0ff10d42008-01-11 01:52:36 -0500541 lpfc_setup_disc_node
542 (vport, Did);
543 else if (lpfc_ns_cmd(vport,
James Smart92d7f7b2007-06-17 19:56:38 -0500544 SLI_CTNS_GFF_ID,
545 0, Did) == 0)
546 vport->num_disc_nodes++;
James Smart6a9c52c2009-10-02 15:16:51 -0400547 else
548 lpfc_setup_disc_node
549 (vport, Did);
James Smart92d7f7b2007-06-17 19:56:38 -0500550 }
551 else {
James Smart858c9f62007-06-17 19:56:39 -0500552 lpfc_debugfs_disc_trc(vport,
553 LPFC_DISC_TRC_CT,
554 "Skip2 GID_FTrsp: "
555 "did:x%x flg:x%x cnt:%d",
556 Did, vport->fc_flag,
557 vport->fc_rscn_id_cnt);
558
James Smarte8b62012007-08-02 11:10:09 -0400559 lpfc_printf_vlog(vport,
560 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500561 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400562 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500563 "NameServer Rsp Data: "
564 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400565 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500566 vport->fc_rscn_id_cnt);
567 }
568 }
dea31012005-04-17 16:05:31 -0500569 }
dea31012005-04-17 16:05:31 -0500570 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
571 goto nsout1;
572 Cnt -= sizeof (uint32_t);
573 }
574 ctptr = NULL;
575
576 }
577
578nsout1:
579 list_del(&head);
dea31012005-04-17 16:05:31 -0500580 return 0;
581}
582
dea31012005-04-17 16:05:31 -0500583static void
James Smart2e0fef82007-06-17 19:56:36 -0500584lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
585 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500586{
James Smart2e0fef82007-06-17 19:56:36 -0500587 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500588 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500589 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500590 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500591 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500592 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400593 struct lpfc_nodelist *ndlp;
James Smart58da1ff2008-04-07 10:15:56 -0400594 int rc;
dea31012005-04-17 16:05:31 -0500595
James Smart51ef4c22007-08-02 11:10:31 -0400596 /* First save ndlp, before we overwrite it */
597 ndlp = cmdiocb->context_un.ndlp;
598
dea31012005-04-17 16:05:31 -0500599 /* we pass cmdiocb to state machine which needs rspiocb as well */
600 cmdiocb->context_un.rsp_iocb = rspiocb;
601
dea31012005-04-17 16:05:31 -0500602 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
603 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500604 irsp = &rspiocb->iocb;
605
606 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
607 "GID_FT cmpl: status:x%x/x%x rtry:%d",
608 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500609
James Smart92d7f7b2007-06-17 19:56:38 -0500610 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500611 if (vport->load_flag & FC_UNLOADING) {
612 if (vport->fc_flag & FC_RSCN_MODE)
613 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500614 goto out;
James Smarteada2722008-12-04 22:39:13 -0500615 }
James Smart92d7f7b2007-06-17 19:56:38 -0500616
James Smart58da1ff2008-04-07 10:15:56 -0400617 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400618 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
619 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500620 if (vport->fc_flag & FC_RSCN_MODE)
621 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500622 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
623 goto out;
624 }
James Smart58da1ff2008-04-07 10:15:56 -0400625 if (lpfc_error_lost_link(irsp)) {
626 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
627 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500628 if (vport->fc_flag & FC_RSCN_MODE)
629 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400630 goto out;
631 }
James Smart858c9f62007-06-17 19:56:39 -0500632 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500633 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500634 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400635 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
636 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500637 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500638
James Smart58da1ff2008-04-07 10:15:56 -0400639 /* CT command is being retried */
640 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smart92d7f7b2007-06-17 19:56:38 -0500641 vport->fc_ns_retry, 0);
James Smart58da1ff2008-04-07 10:15:56 -0400642 if (rc == 0)
643 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500644 }
James Smarteada2722008-12-04 22:39:13 -0500645 if (vport->fc_flag & FC_RSCN_MODE)
646 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500647 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400648 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
649 "0257 GID_FT Query error: 0x%x 0x%x\n",
650 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500651 } else {
652 /* Good status, continue checking */
653 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
654 if (CTrsp->CommandResponse.bits.CmdRsp ==
655 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400656 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
657 "0208 NameServer Rsp Data: x%x\n",
658 vport->fc_flag);
James Smart2e0fef82007-06-17 19:56:36 -0500659 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500660 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
661 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
662 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
663 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400664 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
665 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400666 lpfc_printf_vlog(vport, KERN_INFO,
667 LOG_DISCOVERY,
668 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400669 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400670 CTrsp->CommandResponse.bits.CmdRsp,
671 (uint32_t) CTrsp->ReasonCode,
672 (uint32_t) CTrsp->Explanation,
673 vport->fc_flag);
674
675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
676 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
677 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
678 (uint32_t) CTrsp->ReasonCode,
679 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400680 } else {
681 lpfc_printf_vlog(vport, KERN_INFO,
682 LOG_DISCOVERY,
683 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500684 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500685 CTrsp->CommandResponse.bits.CmdRsp,
686 (uint32_t) CTrsp->ReasonCode,
687 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500688 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500689
James Smarta58cbd52007-08-02 11:09:43 -0400690 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500691 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
692 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
693 (uint32_t) CTrsp->ReasonCode,
694 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400695 }
696
James Smart858c9f62007-06-17 19:56:39 -0500697
dea31012005-04-17 16:05:31 -0500698 } else {
699 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400700 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
701 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500702 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500703 CTrsp->CommandResponse.bits.CmdRsp,
704 (uint32_t) CTrsp->ReasonCode,
705 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500706 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500707
708 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
709 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
710 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
711 (uint32_t) CTrsp->ReasonCode,
712 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500713 }
714 }
715 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500716 if (vport->num_disc_nodes == 0) {
717 /*
718 * The driver has cycled through all Nports in the RSCN payload.
719 * Complete the handling by cleaning up and marking the
720 * current driver state.
721 */
722 if (vport->port_state >= LPFC_DISC_AUTH) {
723 if (vport->fc_flag & FC_RSCN_MODE) {
724 lpfc_els_flush_rscn(vport);
725 spin_lock_irq(shost->host_lock);
726 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
727 spin_unlock_irq(shost->host_lock);
728 }
729 else
730 lpfc_els_flush_rscn(vport);
731 }
732
733 lpfc_disc_start(vport);
734 }
dea31012005-04-17 16:05:31 -0500735out:
James Smart51ef4c22007-08-02 11:10:31 -0400736 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500737 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500738 return;
739}
740
James Smart311464e2007-08-02 11:10:37 -0400741static void
James Smart92d7f7b2007-06-17 19:56:38 -0500742lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
743 struct lpfc_iocbq *rspiocb)
744{
745 struct lpfc_vport *vport = cmdiocb->vport;
746 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
747 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500748 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
749 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
750 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500751 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500752 uint8_t fbits;
753 struct lpfc_nodelist *ndlp;
754
755 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
756 did = be32_to_cpu(did);
757
James Smart858c9f62007-06-17 19:56:39 -0500758 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
759 "GFF_ID cmpl: status:x%x/x%x did:x%x",
760 irsp->ulpStatus, irsp->un.ulpWord[4], did);
761
James Smart92d7f7b2007-06-17 19:56:38 -0500762 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
763 /* Good status, continue checking */
764 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
765 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
766
767 if (CTrsp->CommandResponse.bits.CmdRsp ==
768 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
769 if ((fbits & FC4_FEATURE_INIT) &&
770 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400771 lpfc_printf_vlog(vport, KERN_INFO,
772 LOG_DISCOVERY,
773 "0270 Skip x%x GFF "
774 "NameServer Rsp Data: (init) "
775 "x%x x%x\n", did, fbits,
776 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500777 goto out;
778 }
779 }
780 }
James Smart858c9f62007-06-17 19:56:39 -0500781 else {
James Smart0ff10d42008-01-11 01:52:36 -0500782 /* Check for retry */
783 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
784 retry = 1;
785 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
786 switch (irsp->un.ulpWord[4]) {
787 case IOERR_NO_RESOURCES:
788 /* We don't increment the retry
789 * count for this case.
790 */
791 break;
792 case IOERR_LINK_DOWN:
793 case IOERR_SLI_ABORTED:
794 case IOERR_SLI_DOWN:
795 retry = 0;
796 break;
797 default:
798 cmdiocb->retry++;
799 }
800 }
801 else
802 cmdiocb->retry++;
803
804 if (retry) {
805 /* CT command is being retried */
806 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
807 cmdiocb->retry, did);
808 if (rc == 0) {
809 /* success */
810 lpfc_ct_free_iocb(phba, cmdiocb);
811 return;
812 }
813 }
814 }
James Smarte8b62012007-08-02 11:10:09 -0400815 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
816 "0267 NameServer GFF Rsp "
817 "x%x Error (%d %d) Data: x%x x%x\n",
818 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500819 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500820 }
821
James Smart92d7f7b2007-06-17 19:56:38 -0500822 /* This is a target port, unregistered port, or the GFF_ID failed */
823 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400824 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400825 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
826 "0242 Process x%x GFF "
827 "NameServer Rsp Data: x%x x%x x%x\n",
828 did, ndlp->nlp_flag, vport->fc_flag,
829 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500830 } else {
James Smarte8b62012007-08-02 11:10:09 -0400831 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
832 "0243 Skip x%x GFF "
833 "NameServer Rsp Data: x%x x%x\n", did,
834 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500835 }
836out:
837 /* Link up / RSCN discovery */
838 if (vport->num_disc_nodes)
839 vport->num_disc_nodes--;
840 if (vport->num_disc_nodes == 0) {
841 /*
842 * The driver has cycled through all Nports in the RSCN payload.
843 * Complete the handling by cleaning up and marking the
844 * current driver state.
845 */
846 if (vport->port_state >= LPFC_DISC_AUTH) {
847 if (vport->fc_flag & FC_RSCN_MODE) {
848 lpfc_els_flush_rscn(vport);
849 spin_lock_irq(shost->host_lock);
850 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
851 spin_unlock_irq(shost->host_lock);
852 }
853 else
854 lpfc_els_flush_rscn(vport);
855 }
856 lpfc_disc_start(vport);
857 }
James Smart858c9f62007-06-17 19:56:39 -0500858 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500859 return;
860}
861
862
dea31012005-04-17 16:05:31 -0500863static void
James Smart7ee5d432007-10-27 13:37:17 -0400864lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
865 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500866{
James Smart92d7f7b2007-06-17 19:56:38 -0500867 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500868 struct lpfc_dmabuf *inp;
869 struct lpfc_dmabuf *outp;
870 IOCB_t *irsp;
871 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400872 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500873 int cmdcode, rc;
874 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500875 uint32_t latt;
dea31012005-04-17 16:05:31 -0500876
James Smart51ef4c22007-08-02 11:10:31 -0400877 /* First save ndlp, before we overwrite it */
878 ndlp = cmdiocb->context_un.ndlp;
879
dea31012005-04-17 16:05:31 -0500880 /* we pass cmdiocb to state machine which needs rspiocb as well */
881 cmdiocb->context_un.rsp_iocb = rspiocb;
882
883 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
884 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500885 irsp = &rspiocb->iocb;
886
James Smart92d7f7b2007-06-17 19:56:38 -0500887 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
888 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500889 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
890
James Smart858c9f62007-06-17 19:56:39 -0500891 latt = lpfc_els_chk_latt(vport);
892
893 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400894 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400895 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400896 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
897 latt, irsp->ulpStatus,
898 CTrsp->CommandResponse.bits.CmdRsp,
899 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500900
James Smart858c9f62007-06-17 19:56:39 -0500901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
902 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
903 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
904
James Smart92d7f7b2007-06-17 19:56:38 -0500905 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400906 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
907 "0268 NS cmd %x Error (%d %d)\n",
908 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500909
James Smart92d7f7b2007-06-17 19:56:38 -0500910 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
911 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
912 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
913 goto out;
914
915 retry = cmdiocb->retry;
916 if (retry >= LPFC_MAX_NS_RETRY)
917 goto out;
918
919 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400920 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -0400921 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500922 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
923 if (rc == 0)
924 goto out;
925 }
926
927out:
James Smart51ef4c22007-08-02 11:10:31 -0400928 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500929 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500930 return;
931}
932
933static void
James Smart7ee5d432007-10-27 13:37:17 -0400934lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
935 struct lpfc_iocbq *rspiocb)
936{
937 IOCB_t *irsp = &rspiocb->iocb;
938 struct lpfc_vport *vport = cmdiocb->vport;
939
James Smart98c9ea52007-10-27 13:37:33 -0400940 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
941 struct lpfc_dmabuf *outp;
942 struct lpfc_sli_ct_request *CTrsp;
943
944 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
945 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
946 if (CTrsp->CommandResponse.bits.CmdRsp ==
947 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
948 vport->ct_flags |= FC_CT_RFT_ID;
949 }
James Smart7ee5d432007-10-27 13:37:17 -0400950 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
951 return;
952}
953
954static void
James Smart2e0fef82007-06-17 19:56:36 -0500955lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
956 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500957{
James Smart7ee5d432007-10-27 13:37:17 -0400958 IOCB_t *irsp = &rspiocb->iocb;
959 struct lpfc_vport *vport = cmdiocb->vport;
960
James Smart98c9ea52007-10-27 13:37:33 -0400961 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
962 struct lpfc_dmabuf *outp;
963 struct lpfc_sli_ct_request *CTrsp;
964
965 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
966 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
967 if (CTrsp->CommandResponse.bits.CmdRsp ==
968 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
969 vport->ct_flags |= FC_CT_RNN_ID;
970 }
James Smart7ee5d432007-10-27 13:37:17 -0400971 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500972 return;
973}
974
975static void
James Smart92d7f7b2007-06-17 19:56:38 -0500976lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
977 struct lpfc_iocbq *rspiocb)
978{
James Smart7ee5d432007-10-27 13:37:17 -0400979 IOCB_t *irsp = &rspiocb->iocb;
980 struct lpfc_vport *vport = cmdiocb->vport;
981
James Smart98c9ea52007-10-27 13:37:33 -0400982 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
983 struct lpfc_dmabuf *outp;
984 struct lpfc_sli_ct_request *CTrsp;
985
986 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
987 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
988 if (CTrsp->CommandResponse.bits.CmdRsp ==
989 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
990 vport->ct_flags |= FC_CT_RSPN_ID;
991 }
James Smart7ee5d432007-10-27 13:37:17 -0400992 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500993 return;
994}
995
996static void
James Smart2e0fef82007-06-17 19:56:36 -0500997lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
998 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500999{
James Smart7ee5d432007-10-27 13:37:17 -04001000 IOCB_t *irsp = &rspiocb->iocb;
1001 struct lpfc_vport *vport = cmdiocb->vport;
1002
James Smart98c9ea52007-10-27 13:37:33 -04001003 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1004 struct lpfc_dmabuf *outp;
1005 struct lpfc_sli_ct_request *CTrsp;
1006
1007 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1008 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1009 if (CTrsp->CommandResponse.bits.CmdRsp ==
1010 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1011 vport->ct_flags |= FC_CT_RSNN_NN;
1012 }
James Smart7ee5d432007-10-27 13:37:17 -04001013 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1014 return;
1015}
1016
1017static void
1018lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1019 struct lpfc_iocbq *rspiocb)
1020{
1021 struct lpfc_vport *vport = cmdiocb->vport;
1022
1023 /* even if it fails we will act as though it succeeded. */
1024 vport->ct_flags = 0;
1025 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001026 return;
1027}
1028
James Smart2fb9bd82006-12-02 13:33:57 -05001029static void
James Smart92d7f7b2007-06-17 19:56:38 -05001030lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1031 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001032{
James Smart92d7f7b2007-06-17 19:56:38 -05001033 IOCB_t *irsp = &rspiocb->iocb;
1034 struct lpfc_vport *vport = cmdiocb->vport;
1035
James Smart98c9ea52007-10-27 13:37:33 -04001036 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1037 struct lpfc_dmabuf *outp;
1038 struct lpfc_sli_ct_request *CTrsp;
1039
1040 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1041 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1042 if (CTrsp->CommandResponse.bits.CmdRsp ==
1043 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1044 vport->ct_flags |= FC_CT_RFF_ID;
1045 }
James Smart7ee5d432007-10-27 13:37:17 -04001046 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001047 return;
1048}
1049
James Smart495a7142008-06-14 22:52:59 -04001050int
James Smart92d7f7b2007-06-17 19:56:38 -05001051lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1052 size_t size)
1053{
1054 int n;
1055 uint8_t *wwn = vport->phba->wwpn;
1056
1057 n = snprintf(symbol, size,
1058 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1059 wwn[0], wwn[1], wwn[2], wwn[3],
1060 wwn[4], wwn[5], wwn[6], wwn[7]);
1061
1062 if (vport->port_type == LPFC_PHYSICAL_PORT)
1063 return n;
1064
1065 if (n < size)
1066 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1067
James Smarteada2722008-12-04 22:39:13 -05001068 if (n < size &&
1069 strlen(vport->fc_vport->symbolic_name))
1070 n += snprintf(symbol + n, size - n, " VName-%s",
1071 vport->fc_vport->symbolic_name);
James Smart92d7f7b2007-06-17 19:56:38 -05001072 return n;
1073}
1074
1075int
1076lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1077 size_t size)
dea31012005-04-17 16:05:31 -05001078{
1079 char fwrev[16];
James Smart92d7f7b2007-06-17 19:56:38 -05001080 int n;
dea31012005-04-17 16:05:31 -05001081
James Smart92d7f7b2007-06-17 19:56:38 -05001082 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001083
James Smart92d7f7b2007-06-17 19:56:38 -05001084 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1085 vport->phba->ModelName, fwrev, lpfc_release_version);
1086 return n;
dea31012005-04-17 16:05:31 -05001087}
1088
1089/*
1090 * lpfc_ns_cmd
1091 * Description:
1092 * Issue Cmd to NameServer
1093 * SLI_CTNS_GID_FT
1094 * LI_CTNS_RFT_ID
1095 */
1096int
James Smart92d7f7b2007-06-17 19:56:38 -05001097lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1098 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001099{
James Smart92d7f7b2007-06-17 19:56:38 -05001100 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001101 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001102 struct lpfc_dmabuf *mp, *bmp;
1103 struct lpfc_sli_ct_request *CtReq;
1104 struct ulp_bde64 *bpl;
1105 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1106 struct lpfc_iocbq *) = NULL;
1107 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001108 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001109 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001110
1111 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001112 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1113 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001114 rc=1;
1115 goto ns_cmd_exit;
1116 }
dea31012005-04-17 16:05:31 -05001117
1118 /* fill in BDEs for command */
1119 /* Allocate buffer for command payload */
1120 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001121 if (!mp) {
1122 rc=2;
dea31012005-04-17 16:05:31 -05001123 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001124 }
dea31012005-04-17 16:05:31 -05001125
1126 INIT_LIST_HEAD(&mp->list);
1127 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001128 if (!mp->virt) {
1129 rc=3;
dea31012005-04-17 16:05:31 -05001130 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001131 }
dea31012005-04-17 16:05:31 -05001132
1133 /* Allocate buffer for Buffer ptr list */
1134 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001135 if (!bmp) {
1136 rc=4;
dea31012005-04-17 16:05:31 -05001137 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001138 }
dea31012005-04-17 16:05:31 -05001139
1140 INIT_LIST_HEAD(&bmp->list);
1141 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001142 if (!bmp->virt) {
1143 rc=5;
dea31012005-04-17 16:05:31 -05001144 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001145 }
dea31012005-04-17 16:05:31 -05001146
1147 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001148 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1149 "0236 NameServer Req Data: x%x x%x x%x\n",
1150 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001151
1152 bpl = (struct ulp_bde64 *) bmp->virt;
1153 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001154 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1155 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001156 bpl->tus.f.bdeFlags = 0;
1157 if (cmdcode == SLI_CTNS_GID_FT)
1158 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001159 else if (cmdcode == SLI_CTNS_GFF_ID)
1160 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001161 else if (cmdcode == SLI_CTNS_RFT_ID)
1162 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1163 else if (cmdcode == SLI_CTNS_RNN_ID)
1164 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001165 else if (cmdcode == SLI_CTNS_RSPN_ID)
1166 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001167 else if (cmdcode == SLI_CTNS_RSNN_NN)
1168 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001169 else if (cmdcode == SLI_CTNS_DA_ID)
1170 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001171 else if (cmdcode == SLI_CTNS_RFF_ID)
1172 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001173 else
1174 bpl->tus.f.bdeSize = 0;
1175 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1176
1177 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1178 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1179 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1180 CtReq->RevisionId.bits.InId = 0;
1181 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1182 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1183 CtReq->CommandResponse.bits.Size = 0;
1184 switch (cmdcode) {
1185 case SLI_CTNS_GID_FT:
1186 CtReq->CommandResponse.bits.CmdRsp =
1187 be16_to_cpu(SLI_CTNS_GID_FT);
1188 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001189 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001190 vport->port_state = LPFC_NS_QRY;
1191 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001192 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1193 rsp_size = FC_MAX_NS_RSP;
1194 break;
1195
James Smart92d7f7b2007-06-17 19:56:38 -05001196 case SLI_CTNS_GFF_ID:
1197 CtReq->CommandResponse.bits.CmdRsp =
1198 be16_to_cpu(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001199 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001200 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1201 break;
1202
dea31012005-04-17 16:05:31 -05001203 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001204 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001205 CtReq->CommandResponse.bits.CmdRsp =
1206 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001207 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001208 CtReq->un.rft.fcpReg = 1;
1209 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1210 break;
1211
1212 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001213 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001214 CtReq->CommandResponse.bits.CmdRsp =
1215 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001216 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001217 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001218 sizeof (struct lpfc_name));
1219 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1220 break;
1221
James Smart92d7f7b2007-06-17 19:56:38 -05001222 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001223 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001224 CtReq->CommandResponse.bits.CmdRsp =
1225 be16_to_cpu(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001226 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001227 size = sizeof(CtReq->un.rspn.symbname);
1228 CtReq->un.rspn.len =
1229 lpfc_vport_symbolic_port_name(vport,
1230 CtReq->un.rspn.symbname, size);
1231 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1232 break;
dea31012005-04-17 16:05:31 -05001233 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001234 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001235 CtReq->CommandResponse.bits.CmdRsp =
1236 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001237 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001238 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001239 size = sizeof(CtReq->un.rsnn.symbname);
1240 CtReq->un.rsnn.len =
1241 lpfc_vport_symbolic_node_name(vport,
1242 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001243 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1244 break;
James Smart7ee5d432007-10-27 13:37:17 -04001245 case SLI_CTNS_DA_ID:
1246 /* Implement DA_ID Nameserver request */
1247 CtReq->CommandResponse.bits.CmdRsp =
1248 be16_to_cpu(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001249 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001250 cmpl = lpfc_cmpl_ct_cmd_da_id;
1251 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001252 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001253 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001254 CtReq->CommandResponse.bits.CmdRsp =
1255 be16_to_cpu(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001256 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001257 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smart6a9c52c2009-10-02 15:16:51 -04001258 CtReq->un.rff.type_code = FC_TYPE_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001259 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1260 break;
dea31012005-04-17 16:05:31 -05001261 }
James Smarte47c9092008-02-08 18:49:26 -05001262 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1263 * to hold ndlp reference for the corresponding callback function.
1264 */
James Smart858c9f62007-06-17 19:56:39 -05001265 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001266 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1268 "Issue CT cmd: cmd:x%x did:x%x",
1269 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001270 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001271 }
James Smart858c9f62007-06-17 19:56:39 -05001272 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001273
1274 /* Decrement ndlp reference count to release ndlp reference held
1275 * for the failed command's callback function.
1276 */
James Smart51ef4c22007-08-02 11:10:31 -04001277 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001278
dea31012005-04-17 16:05:31 -05001279 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1280ns_cmd_free_bmp:
1281 kfree(bmp);
1282ns_cmd_free_mpvirt:
1283 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1284ns_cmd_free_mp:
1285 kfree(mp);
1286ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001287 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1288 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1289 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001290 return 1;
1291}
1292
1293static void
James Smart2e0fef82007-06-17 19:56:36 -05001294lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1295 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001296{
dea31012005-04-17 16:05:31 -05001297 struct lpfc_dmabuf *inp = cmdiocb->context1;
1298 struct lpfc_dmabuf *outp = cmdiocb->context2;
1299 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1300 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1301 struct lpfc_nodelist *ndlp;
1302 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1303 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001304 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001305 IOCB_t *irsp = &rspiocb->iocb;
1306 uint32_t latt;
1307
1308 latt = lpfc_els_chk_latt(vport);
1309
1310 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1311 "FDMI cmpl: status:x%x/x%x latt:%d",
1312 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1313
1314 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001315 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1316 "0229 FDMI cmd %04x failed, latt = %d "
1317 "ulpStatus: x%x, rid x%x\n",
1318 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1319 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001320 lpfc_ct_free_iocb(phba, cmdiocb);
1321 return;
1322 }
dea31012005-04-17 16:05:31 -05001323
James Smart2e0fef82007-06-17 19:56:36 -05001324 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001325 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1326 goto fail_out;
1327
dea31012005-04-17 16:05:31 -05001328 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1329 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001330 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1331 "0220 FDMI rsp failed Data: x%x\n",
1332 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001333 }
1334
1335 switch (be16_to_cpu(fdmi_cmd)) {
1336 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001337 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001338 break;
1339
1340 case SLI_MGMT_RPA:
1341 break;
1342
1343 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001344 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001345 break;
1346
1347 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001348 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001349 break;
1350 }
James Smarte47c9092008-02-08 18:49:26 -05001351
1352fail_out:
James Smart858c9f62007-06-17 19:56:39 -05001353 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001354 return;
1355}
James Smart2e0fef82007-06-17 19:56:36 -05001356
dea31012005-04-17 16:05:31 -05001357int
James Smart2e0fef82007-06-17 19:56:36 -05001358lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001359{
James Smart2e0fef82007-06-17 19:56:36 -05001360 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001361 struct lpfc_dmabuf *mp, *bmp;
1362 struct lpfc_sli_ct_request *CtReq;
1363 struct ulp_bde64 *bpl;
1364 uint32_t size;
1365 REG_HBA *rh;
1366 PORT_ENTRY *pe;
1367 REG_PORT_ATTRIBUTE *pab;
1368 ATTRIBUTE_BLOCK *ab;
1369 ATTRIBUTE_ENTRY *ae;
1370 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1371 struct lpfc_iocbq *);
1372
1373
1374 /* fill in BDEs for command */
1375 /* Allocate buffer for command payload */
1376 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1377 if (!mp)
1378 goto fdmi_cmd_exit;
1379
1380 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1381 if (!mp->virt)
1382 goto fdmi_cmd_free_mp;
1383
1384 /* Allocate buffer for Buffer ptr list */
1385 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1386 if (!bmp)
1387 goto fdmi_cmd_free_mpvirt;
1388
1389 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1390 if (!bmp->virt)
1391 goto fdmi_cmd_free_bmp;
1392
1393 INIT_LIST_HEAD(&mp->list);
1394 INIT_LIST_HEAD(&bmp->list);
1395
1396 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001397 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1398 "0218 FDMI Request Data: x%x x%x x%x\n",
1399 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001400 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1401
1402 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1403 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1404 CtReq->RevisionId.bits.InId = 0;
1405
1406 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1407 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1408 size = 0;
1409
1410 switch (cmdcode) {
1411 case SLI_MGMT_RHBA:
1412 {
1413 lpfc_vpd_t *vp = &phba->vpd;
1414 uint32_t i, j, incr;
1415 int len;
1416
1417 CtReq->CommandResponse.bits.CmdRsp =
1418 be16_to_cpu(SLI_MGMT_RHBA);
1419 CtReq->CommandResponse.bits.Size = 0;
1420 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001421 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001422 sizeof (struct lpfc_name));
1423 /* One entry (port) per adapter */
1424 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001425 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001426 sizeof (struct lpfc_name));
1427
1428 /* point to the HBA attribute block */
1429 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1430 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1431 ab->EntryCnt = 0;
1432
1433 /* Point to the beginning of the first HBA attribute
1434 entry */
1435 /* #1 HBA attribute entry */
1436 size += FOURBYTES;
1437 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1438 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1439 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1440 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001441 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001442 sizeof (struct lpfc_name));
1443 ab->EntryCnt++;
1444 size += FOURBYTES + sizeof (struct lpfc_name);
1445
1446 /* #2 HBA attribute entry */
1447 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1448 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1449 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1450 len = strlen(ae->un.Manufacturer);
1451 len += (len & 3) ? (4 - (len & 3)) : 4;
1452 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1453 ab->EntryCnt++;
1454 size += FOURBYTES + len;
1455
1456 /* #3 HBA attribute entry */
1457 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1458 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1459 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1460 len = strlen(ae->un.SerialNumber);
1461 len += (len & 3) ? (4 - (len & 3)) : 4;
1462 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1463 ab->EntryCnt++;
1464 size += FOURBYTES + len;
1465
1466 /* #4 HBA attribute entry */
1467 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1468 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1469 strcpy(ae->un.Model, phba->ModelName);
1470 len = strlen(ae->un.Model);
1471 len += (len & 3) ? (4 - (len & 3)) : 4;
1472 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1473 ab->EntryCnt++;
1474 size += FOURBYTES + len;
1475
1476 /* #5 HBA attribute entry */
1477 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1478 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1479 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1480 len = strlen(ae->un.ModelDescription);
1481 len += (len & 3) ? (4 - (len & 3)) : 4;
1482 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1483 ab->EntryCnt++;
1484 size += FOURBYTES + len;
1485
1486 /* #6 HBA attribute entry */
1487 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1488 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1489 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1490 /* Convert JEDEC ID to ascii for hardware version */
1491 incr = vp->rev.biuRev;
1492 for (i = 0; i < 8; i++) {
1493 j = (incr & 0xf);
1494 if (j <= 9)
1495 ae->un.HardwareVersion[7 - i] =
1496 (char)((uint8_t) 0x30 +
1497 (uint8_t) j);
1498 else
1499 ae->un.HardwareVersion[7 - i] =
1500 (char)((uint8_t) 0x61 +
1501 (uint8_t) (j - 10));
1502 incr = (incr >> 4);
1503 }
1504 ab->EntryCnt++;
1505 size += FOURBYTES + 8;
1506
1507 /* #7 HBA attribute entry */
1508 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1509 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1510 strcpy(ae->un.DriverVersion, lpfc_release_version);
1511 len = strlen(ae->un.DriverVersion);
1512 len += (len & 3) ? (4 - (len & 3)) : 4;
1513 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1514 ab->EntryCnt++;
1515 size += FOURBYTES + len;
1516
1517 /* #8 HBA attribute entry */
1518 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1519 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1520 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1521 len = strlen(ae->un.OptionROMVersion);
1522 len += (len & 3) ? (4 - (len & 3)) : 4;
1523 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1524 ab->EntryCnt++;
1525 size += FOURBYTES + len;
1526
1527 /* #9 HBA attribute entry */
1528 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1529 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1530 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1531 1);
1532 len = strlen(ae->un.FirmwareVersion);
1533 len += (len & 3) ? (4 - (len & 3)) : 4;
1534 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1535 ab->EntryCnt++;
1536 size += FOURBYTES + len;
1537
1538 /* #10 HBA attribute entry */
1539 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1540 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1541 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001542 init_utsname()->sysname,
1543 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001544 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001545 len = strlen(ae->un.OsNameVersion);
1546 len += (len & 3) ? (4 - (len & 3)) : 4;
1547 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1548 ab->EntryCnt++;
1549 size += FOURBYTES + len;
1550
1551 /* #11 HBA attribute entry */
1552 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1553 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1554 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1555 ae->un.MaxCTPayloadLen = (65 * 4096);
1556 ab->EntryCnt++;
1557 size += FOURBYTES + 4;
1558
1559 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1560 /* Total size */
1561 size = GID_REQUEST_SZ - 4 + size;
1562 }
1563 break;
1564
1565 case SLI_MGMT_RPA:
1566 {
1567 lpfc_vpd_t *vp;
1568 struct serv_parm *hsp;
1569 int len;
1570
1571 vp = &phba->vpd;
1572
1573 CtReq->CommandResponse.bits.CmdRsp =
1574 be16_to_cpu(SLI_MGMT_RPA);
1575 CtReq->CommandResponse.bits.Size = 0;
1576 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1577 size = sizeof (struct lpfc_name) + FOURBYTES;
1578 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001579 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001580 sizeof (struct lpfc_name));
1581 pab->ab.EntryCnt = 0;
1582
1583 /* #1 Port attribute entry */
1584 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1585 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1586 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1587 ae->un.SupportFC4Types[2] = 1;
1588 ae->un.SupportFC4Types[7] = 1;
1589 pab->ab.EntryCnt++;
1590 size += FOURBYTES + 32;
1591
1592 /* #2 Port attribute entry */
1593 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1594 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1595 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001596
1597 ae->un.SupportSpeed = 0;
James Smart76a95d72010-11-20 23:11:48 -05001598 if (phba->lmt & LMT_16Gb)
1599 ae->un.SupportSpeed |= HBA_PORTSPEED_16GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001600 if (phba->lmt & LMT_10Gb)
James Smart76a95d72010-11-20 23:11:48 -05001601 ae->un.SupportSpeed |= HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001602 if (phba->lmt & LMT_8Gb)
1603 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1604 if (phba->lmt & LMT_4Gb)
1605 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1606 if (phba->lmt & LMT_2Gb)
1607 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1608 if (phba->lmt & LMT_1Gb)
1609 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1610
dea31012005-04-17 16:05:31 -05001611 pab->ab.EntryCnt++;
1612 size += FOURBYTES + 4;
1613
1614 /* #3 Port attribute entry */
1615 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1616 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1617 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1618 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05001619 case LPFC_LINK_SPEED_1GHZ:
1620 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05001621 break;
James Smart76a95d72010-11-20 23:11:48 -05001622 case LPFC_LINK_SPEED_2GHZ:
1623 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05001624 break;
James Smart76a95d72010-11-20 23:11:48 -05001625 case LPFC_LINK_SPEED_4GHZ:
1626 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05001627 break;
James Smart76a95d72010-11-20 23:11:48 -05001628 case LPFC_LINK_SPEED_8GHZ:
1629 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04001630 break;
James Smart76a95d72010-11-20 23:11:48 -05001631 case LPFC_LINK_SPEED_10GHZ:
1632 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04001633 break;
James Smart76a95d72010-11-20 23:11:48 -05001634 case LPFC_LINK_SPEED_16GHZ:
1635 ae->un.PortSpeed = HBA_PORTSPEED_16GBIT;
1636 break;
1637 default:
1638 ae->un.PortSpeed = HBA_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05001639 break;
1640 }
1641 pab->ab.EntryCnt++;
1642 size += FOURBYTES + 4;
1643
1644 /* #4 Port attribute entry */
1645 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1646 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1647 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001648 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001649 ae->un.MaxFrameSize =
1650 (((uint32_t) hsp->cmn.
1651 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1652 bbRcvSizeLsb;
1653 pab->ab.EntryCnt++;
1654 size += FOURBYTES + 4;
1655
1656 /* #5 Port attribute entry */
1657 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1658 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1659 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1660 len = strlen((char *)ae->un.OsDeviceName);
1661 len += (len & 3) ? (4 - (len & 3)) : 4;
1662 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1663 pab->ab.EntryCnt++;
1664 size += FOURBYTES + len;
1665
James Smart3de2a652007-08-02 11:09:59 -04001666 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001667 /* #6 Port attribute entry */
1668 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1669 size);
1670 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1671 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001672 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001673 len = strlen(ae->un.HostName);
1674 len += (len & 3) ? (4 - (len & 3)) : 4;
1675 ae->ad.bits.AttrLen =
1676 be16_to_cpu(FOURBYTES + len);
1677 pab->ab.EntryCnt++;
1678 size += FOURBYTES + len;
1679 }
1680
1681 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1682 /* Total size */
1683 size = GID_REQUEST_SZ - 4 + size;
1684 }
1685 break;
1686
1687 case SLI_MGMT_DHBA:
1688 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1689 CtReq->CommandResponse.bits.Size = 0;
1690 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1691 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001692 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001693 sizeof (struct lpfc_name));
1694 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1695 break;
1696
1697 case SLI_MGMT_DPRT:
1698 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1699 CtReq->CommandResponse.bits.Size = 0;
1700 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1701 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001702 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001703 sizeof (struct lpfc_name));
1704 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1705 break;
1706 }
1707
1708 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001709 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1710 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001711 bpl->tus.f.bdeFlags = 0;
1712 bpl->tus.f.bdeSize = size;
1713 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1714
1715 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1716
James Smarte47c9092008-02-08 18:49:26 -05001717 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1718 * to hold ndlp reference for the corresponding callback function.
1719 */
James Smart92d7f7b2007-06-17 19:56:38 -05001720 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001721 return 0;
1722
James Smarte47c9092008-02-08 18:49:26 -05001723 /* Decrement ndlp reference count to release ndlp reference held
1724 * for the failed command's callback function.
1725 */
James Smart51ef4c22007-08-02 11:10:31 -04001726 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001727
dea31012005-04-17 16:05:31 -05001728 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1729fdmi_cmd_free_bmp:
1730 kfree(bmp);
1731fdmi_cmd_free_mpvirt:
1732 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1733fdmi_cmd_free_mp:
1734 kfree(mp);
1735fdmi_cmd_exit:
1736 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001737 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1738 "0244 Issue FDMI request failed Data: x%x\n",
1739 cmdcode);
dea31012005-04-17 16:05:31 -05001740 return 1;
1741}
1742
James Smart92494142011-02-16 12:39:44 -05001743/**
1744 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
1745 * @ptr - Context object of the timer.
1746 *
1747 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
1748 * the worker thread.
1749 **/
1750void
1751lpfc_delayed_disc_tmo(unsigned long ptr)
1752{
1753 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1754 struct lpfc_hba *phba = vport->phba;
1755 uint32_t tmo_posted;
1756 unsigned long iflag;
1757
1758 spin_lock_irqsave(&vport->work_port_lock, iflag);
1759 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
1760 if (!tmo_posted)
1761 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
1762 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1763
1764 if (!tmo_posted)
1765 lpfc_worker_wake_up(phba);
1766 return;
1767}
1768
1769/**
1770 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
1771 * handle delayed discovery.
1772 * @vport: pointer to a host virtual N_Port data structure.
1773 *
1774 * This function start nport discovery of the vport.
1775 **/
1776void
1777lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
1778{
1779 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1780
1781 spin_lock_irq(shost->host_lock);
1782 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
1783 spin_unlock_irq(shost->host_lock);
1784 return;
1785 }
1786 vport->fc_flag &= ~FC_DISC_DELAYED;
1787 spin_unlock_irq(shost->host_lock);
1788
1789 lpfc_do_scr_ns_plogi(vport->phba, vport);
1790}
1791
dea31012005-04-17 16:05:31 -05001792void
1793lpfc_fdmi_tmo(unsigned long ptr)
1794{
James Smart2e0fef82007-06-17 19:56:36 -05001795 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1796 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001797 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05001798 unsigned long iflag;
1799
James Smart2e0fef82007-06-17 19:56:36 -05001800 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001801 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1802 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05001803 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04001804 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001805
James Smart5e9d9b82008-06-14 22:52:53 -04001806 if (!tmo_posted)
1807 lpfc_worker_wake_up(phba);
1808 return;
dea31012005-04-17 16:05:31 -05001809}
1810
1811void
James Smart2e0fef82007-06-17 19:56:36 -05001812lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001813{
1814 struct lpfc_nodelist *ndlp;
1815
James Smart2e0fef82007-06-17 19:56:36 -05001816 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001817 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001818 if (init_utsname()->nodename[0] != '\0')
1819 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1820 else
1821 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001822 }
dea31012005-04-17 16:05:31 -05001823 return;
1824}
1825
dea31012005-04-17 16:05:31 -05001826void
James Smart2e0fef82007-06-17 19:56:36 -05001827lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001828{
1829 struct lpfc_sli *psli = &phba->sli;
1830 lpfc_vpd_t *vp = &phba->vpd;
1831 uint32_t b1, b2, b3, b4, i, rev;
1832 char c;
1833 uint32_t *ptr, str[4];
1834 uint8_t *fwname;
1835
James Smartf1126682009-06-10 17:22:44 -04001836 if (phba->sli_rev == LPFC_SLI_REV4)
1837 sprintf(fwrevision, "%s", vp->rev.opFwName);
1838 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04001839 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001840 rev = vp->rev.sli2FwRev;
1841 else
1842 rev = vp->rev.sli1FwRev;
1843
1844 b1 = (rev & 0x0000f000) >> 12;
1845 b2 = (rev & 0x00000f00) >> 8;
1846 b3 = (rev & 0x000000c0) >> 6;
1847 b4 = (rev & 0x00000030) >> 4;
1848
1849 switch (b4) {
1850 case 0:
1851 c = 'N';
1852 break;
1853 case 1:
1854 c = 'A';
1855 break;
1856 case 2:
1857 c = 'B';
1858 break;
James Smart73d91e52011-10-10 21:32:10 -04001859 case 3:
1860 c = 'X';
1861 break;
dea31012005-04-17 16:05:31 -05001862 default:
1863 c = 0;
1864 break;
1865 }
1866 b4 = (rev & 0x0000000f);
1867
James Smartf4b4c682009-05-22 14:53:12 -04001868 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001869 fwname = vp->rev.sli2FwName;
1870 else
1871 fwname = vp->rev.sli1FwName;
1872
1873 for (i = 0; i < 16; i++)
1874 if (fwname[i] == 0x20)
1875 fwname[i] = 0;
1876
1877 ptr = (uint32_t*)fwname;
1878
1879 for (i = 0; i < 3; i++)
1880 str[i] = be32_to_cpu(*ptr++);
1881
1882 if (c == 0) {
1883 if (flag)
1884 sprintf(fwrevision, "%d.%d%d (%s)",
1885 b1, b2, b3, (char *)str);
1886 else
1887 sprintf(fwrevision, "%d.%d%d", b1,
1888 b2, b3);
1889 } else {
1890 if (flag)
1891 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1892 b1, b2, b3, c,
1893 b4, (char *)str);
1894 else
1895 sprintf(fwrevision, "%d.%d%d%c%d",
1896 b1, b2, b3, c, b4);
1897 }
1898 } else {
1899 rev = vp->rev.smFwRev;
1900
1901 b1 = (rev & 0xff000000) >> 24;
1902 b2 = (rev & 0x00f00000) >> 20;
1903 b3 = (rev & 0x000f0000) >> 16;
1904 c = (rev & 0x0000ff00) >> 8;
1905 b4 = (rev & 0x000000ff);
1906
Roel Kluind44a6d22010-01-17 16:15:57 +01001907 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05001908 }
1909 return;
1910}