blob: bf7bf62e81ebf5267e1f241e78398a3e69d1067f [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
dea31012005-04-17 16:05:31 -050019 *******************************************************************/
20
21/*
James Smart09372822008-01-11 01:52:54 -050022 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea31012005-04-17 16:05:31 -050023 */
24
25#include <linux/blkdev.h>
26#include <linux/pci.h>
27#include <linux/interrupt.h>
28#include <linux/utsname.h>
29
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040033#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040034#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050035
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_logmsg.h"
45#include "lpfc_crtn.h"
46#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050047#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050048#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050049
50#define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
51 * incapable of reporting */
52#define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
53#define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
54#define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
55#define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
56#define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
57#define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
58
59#define FOURBYTES 4
60
61
62static char *lpfc_release_version = LPFC_DRIVER_VERSION;
63
James Smarted957682007-06-17 19:56:37 -050064static void
65lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050066 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050067{
James Smarted957682007-06-17 19:56:37 -050068 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050069 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040070 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050071 "status = x%x\n",
72 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050073 }
James Smart9c2face2008-01-11 01:53:18 -050074 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
75 "0145 Ignoring unsolicted CT HBQ Size:%d "
76 "status = x%x\n",
77 size, piocbq->iocb.ulpStatus);
78}
79
80static void
81lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
83{
84 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -050085}
86
dea31012005-04-17 16:05:31 -050087void
James Smart2e0fef82007-06-17 19:56:36 -050088lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
89 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -050090{
James Smarted957682007-06-17 19:56:37 -050091 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -050092 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -050093 int i;
94 struct lpfc_iocbq *iocbq;
95 dma_addr_t paddr;
96 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -050097 struct list_head head;
98 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -050099
James Smartf1c3b0f2009-07-19 10:01:32 -0400100 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
101
James Smart92d7f7b2007-06-17 19:56:38 -0500102 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
103 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
104 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
105 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500106 /* Not enough posted buffers; Try posting more buffers */
107 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500108 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400109 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500110 return;
111 }
112
113 /* If there are no BDEs associated with this IOCB,
114 * there is nothing to do.
115 */
116 if (icmd->ulpBdeCount == 0)
117 return;
118
James Smarted957682007-06-17 19:56:37 -0500119 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500120 INIT_LIST_HEAD(&head);
121 list_add_tail(&head, &piocbq->list);
122 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500123 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500124 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500125 continue;
James Smart9c2face2008-01-11 01:53:18 -0500126 bdeBuf = iocbq->context2;
127 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500128 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500129 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
130 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500131 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500132 bdeBuf = iocbq->context3;
133 iocbq->context3 = NULL;
134 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
135 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
136 size);
137 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500138 }
dea31012005-04-17 16:05:31 -0500139 }
James Smart9c2face2008-01-11 01:53:18 -0500140 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500141 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400142 INIT_LIST_HEAD(&head);
143 list_add_tail(&head, &piocbq->list);
144 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500145 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500146 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400147 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500148 for (i = 0; i < icmd->ulpBdeCount; i++) {
149 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
150 icmd->un.cont64[i].addrLow);
151 mp = lpfc_sli_ringpostbuf_get(phba, pring,
152 paddr);
153 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400154 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500155 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500156 }
James Smart495a7142008-06-14 22:52:59 -0400157 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500158 }
James Smartd7c255b2008-08-24 21:50:00 -0400159 list_del(&head);
dea31012005-04-17 16:05:31 -0500160 }
dea31012005-04-17 16:05:31 -0500161}
162
James Smart6669f9b2009-10-02 15:16:45 -0400163/**
164 * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort
165 * @phba: Pointer to HBA context object.
166 * @pring: Pointer to the driver internal I/O ring.
167 * @piocbq: Pointer to the IOCBQ.
168 *
169 * This function serves as the default handler for the sli4 unsolicited
170 * abort event. It shall be invoked when there is no application interface
171 * registered unsolicited abort handler. This handler does nothing but
172 * just simply releases the dma buffer used by the unsol abort event.
173 **/
174void
175lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
176 struct lpfc_sli_ring *pring,
177 struct lpfc_iocbq *piocbq)
178{
179 IOCB_t *icmd = &piocbq->iocb;
180 struct lpfc_dmabuf *bdeBuf;
181 uint32_t size;
182
183 /* Forward abort event to any process registered to receive ct event */
184 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
185
186 /* If there is no BDE associated with IOCB, there is nothing to do */
187 if (icmd->ulpBdeCount == 0)
188 return;
189 bdeBuf = piocbq->context2;
190 piocbq->context2 = NULL;
191 size = icmd->un.cont64[0].tus.f.bdeSize;
192 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
193 lpfc_in_buf_free(phba, bdeBuf);
194}
195
dea31012005-04-17 16:05:31 -0500196static void
James Smart2e0fef82007-06-17 19:56:36 -0500197lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500198{
199 struct lpfc_dmabuf *mlast, *next_mlast;
200
201 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
202 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
203 list_del(&mlast->list);
204 kfree(mlast);
205 }
206 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
207 kfree(mlist);
208 return;
209}
210
211static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500212lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500213 uint32_t size, int *entries)
214{
215 struct lpfc_dmabuf *mlist = NULL;
216 struct lpfc_dmabuf *mp;
217 int cnt, i = 0;
218
James Smart09372822008-01-11 01:52:54 -0500219 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500220 cnt = size > FCELSSIZE ? FCELSSIZE: size;
221
222 while (size) {
223 /* Allocate buffer for rsp payload */
224 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
225 if (!mp) {
226 if (mlist)
227 lpfc_free_ct_rsp(phba, mlist);
228 return NULL;
229 }
230
231 INIT_LIST_HEAD(&mp->list);
232
James Smart92d7f7b2007-06-17 19:56:38 -0500233 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
234 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500235 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
236 else
237 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
238
239 if (!mp->virt) {
240 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700241 if (mlist)
242 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500243 return NULL;
244 }
245
246 /* Queue it to a linked list */
247 if (!mlist)
248 mlist = mp;
249 else
250 list_add_tail(&mp->list, &mlist->list);
251
James Smart34b02dc2008-08-24 21:49:55 -0400252 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500253 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500254 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
255 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500256 bpl->tus.f.bdeSize = (uint16_t) cnt;
257 bpl->tus.w = le32_to_cpu(bpl->tus.w);
258 bpl++;
259
260 i++;
261 size -= cnt;
262 }
263
264 *entries = i;
265 return mlist;
266}
267
James Smart858c9f62007-06-17 19:56:39 -0500268int
269lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
270{
271 struct lpfc_dmabuf *buf_ptr;
272
James Smart51ef4c22007-08-02 11:10:31 -0400273 if (ctiocb->context_un.ndlp) {
274 lpfc_nlp_put(ctiocb->context_un.ndlp);
275 ctiocb->context_un.ndlp = NULL;
276 }
James Smart858c9f62007-06-17 19:56:39 -0500277 if (ctiocb->context1) {
278 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
279 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
280 kfree(buf_ptr);
281 ctiocb->context1 = NULL;
282 }
283 if (ctiocb->context2) {
284 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
285 ctiocb->context2 = NULL;
286 }
287
288 if (ctiocb->context3) {
289 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
290 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
291 kfree(buf_ptr);
292 ctiocb->context1 = NULL;
293 }
294 lpfc_sli_release_iocbq(phba, ctiocb);
295 return 0;
296}
297
dea31012005-04-17 16:05:31 -0500298static int
James Smart2e0fef82007-06-17 19:56:36 -0500299lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500300 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
301 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
302 struct lpfc_iocbq *),
303 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500304 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500305{
James Smart2e0fef82007-06-17 19:56:36 -0500306 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500307 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400308 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500309 int rc;
dea31012005-04-17 16:05:31 -0500310
311 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400312 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500313
314 if (geniocb == NULL)
315 return 1;
dea31012005-04-17 16:05:31 -0500316
317 icmd = &geniocb->iocb;
318 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
319 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
320 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400321 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea31012005-04-17 16:05:31 -0500322 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
323
324 if (usr_flg)
325 geniocb->context3 = NULL;
326 else
327 geniocb->context3 = (uint8_t *) bmp;
328
329 /* Save for completion so we can release these resources */
330 geniocb->context1 = (uint8_t *) inp;
331 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500332 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500333
334 /* Fill in payload, bp points to frame payload */
335 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
336
337 /* Fill in rest of iocb */
338 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
339 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
James Smart6a9c52c2009-10-02 15:16:51 -0400340 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
341 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -0500342
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500343 if (!tmo) {
344 /* FC spec states we need 3 * ratov for CT requests */
345 tmo = (3 * phba->fc_ratov);
346 }
dea31012005-04-17 16:05:31 -0500347 icmd->ulpTimeout = tmo;
348 icmd->ulpBdeCount = 1;
349 icmd->ulpLe = 1;
350 icmd->ulpClass = CLASS3;
351 icmd->ulpContext = ndlp->nlp_rpi;
352
James Smart92d7f7b2007-06-17 19:56:38 -0500353 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
354 /* For GEN_REQUEST64_CR, use the RPI */
355 icmd->ulpCt_h = 0;
356 icmd->ulpCt_l = 0;
357 }
358
dea31012005-04-17 16:05:31 -0500359 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400360 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
361 "0119 Issue GEN REQ IOCB to NPORT x%x "
362 "Data: x%x x%x\n",
363 ndlp->nlp_DID, icmd->ulpIoTag,
364 vport->port_state);
dea31012005-04-17 16:05:31 -0500365 geniocb->iocb_cmpl = cmpl;
366 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500367 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500368 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400369 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500370
371 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500372 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500373 return 1;
374 }
dea31012005-04-17 16:05:31 -0500375
376 return 0;
377}
378
379static int
James Smart2e0fef82007-06-17 19:56:36 -0500380lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500381 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
382 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
383 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500384 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500385{
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500387 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
388 struct lpfc_dmabuf *outmp;
389 int cnt = 0, status;
390 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
391 CommandResponse.bits.CmdRsp;
392
393 bpl++; /* Skip past ct request */
394
395 /* Put buffer(s) for ct rsp in bpl */
396 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
397 if (!outmp)
398 return -ENOMEM;
James Smart6a9c52c2009-10-02 15:16:51 -0400399 /*
400 * Form the CT IOCB. The total number of BDEs in this IOCB
401 * is the single command plus response count from
402 * lpfc_alloc_ct_rsp.
403 */
404 cnt += 1;
James Smart2e0fef82007-06-17 19:56:36 -0500405 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart6a9c52c2009-10-02 15:16:51 -0400406 cnt, 0, retry);
dea31012005-04-17 16:05:31 -0500407 if (status) {
408 lpfc_free_ct_rsp(phba, outmp);
409 return -ENOMEM;
410 }
411 return 0;
412}
413
James Smart549e55c2007-08-02 11:09:51 -0400414struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500415lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500416 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400417 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500418
James Smart549e55c2007-08-02 11:09:51 -0400419 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500420 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400421 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
422 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500423 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400424 }
James Smart92d7f7b2007-06-17 19:56:38 -0500425 }
James Smart549e55c2007-08-02 11:09:51 -0400426 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500427 return NULL;
428}
429
dea31012005-04-17 16:05:31 -0500430static int
James Smart2e0fef82007-06-17 19:56:36 -0500431lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500432{
James Smart2e0fef82007-06-17 19:56:36 -0500433 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500434 struct lpfc_sli_ct_request *Response =
435 (struct lpfc_sli_ct_request *) mp->virt;
436 struct lpfc_nodelist *ndlp = NULL;
437 struct lpfc_dmabuf *mlast, *next_mp;
438 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500439 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500440 int Cnt;
441 struct list_head head;
442
James Smart2e0fef82007-06-17 19:56:36 -0500443 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500444 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500445 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500446
dea31012005-04-17 16:05:31 -0500447
448 list_add_tail(&head, &mp->list);
449 list_for_each_entry_safe(mp, next_mp, &head, list) {
450 mlast = mp;
451
James Smart7054a602007-04-25 09:52:34 -0400452 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
453
dea31012005-04-17 16:05:31 -0500454 Size -= Cnt;
455
James Smart1dcb58e2007-04-25 09:51:30 -0400456 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500457 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400458 } else
dea31012005-04-17 16:05:31 -0500459 Cnt -= 16; /* subtract length of CT header */
460
461 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400462 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500463 /* Get next DID from NameServer List */
464 CTentry = *ctptr++;
465 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500466
dea31012005-04-17 16:05:31 -0500467 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500468
469 /*
470 * Check for rscn processing or not
471 * To conserve rpi's, filter out addresses for other
472 * vports on the same physical HBAs.
473 */
474 if ((Did != vport->fc_myDID) &&
475 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400476 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500477 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart98c9ea52007-10-27 13:37:33 -0400478 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
James Smart3de2a652007-08-02 11:09:59 -0400479 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500480 ndlp = lpfc_setup_disc_node(vport, Did);
James Smart58da1ff2008-04-07 10:15:56 -0400481 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500482 lpfc_debugfs_disc_trc(vport,
483 LPFC_DISC_TRC_CT,
484 "Parse GID_FTrsp: "
485 "did:x%x flg:x%x x%x",
486 Did, ndlp->nlp_flag,
487 vport->fc_flag);
488
James Smarte8b62012007-08-02 11:10:09 -0400489 lpfc_printf_vlog(vport,
490 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500491 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400492 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500493 "x%x NameServer Rsp"
494 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400495 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500496 vport->fc_flag,
497 vport->fc_rscn_id_cnt);
498 } else {
James Smart858c9f62007-06-17 19:56:39 -0500499 lpfc_debugfs_disc_trc(vport,
500 LPFC_DISC_TRC_CT,
501 "Skip1 GID_FTrsp: "
502 "did:x%x flg:x%x cnt:%d",
503 Did, vport->fc_flag,
504 vport->fc_rscn_id_cnt);
505
James Smarte8b62012007-08-02 11:10:09 -0400506 lpfc_printf_vlog(vport,
507 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500508 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400509 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500510 "NameServer Rsp Data: "
511 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400512 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500513 vport->fc_rscn_id_cnt);
514 }
515
516 } else {
517 if (!(vport->fc_flag & FC_RSCN_MODE) ||
518 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500519 lpfc_debugfs_disc_trc(vport,
520 LPFC_DISC_TRC_CT,
521 "Query GID_FTrsp: "
522 "did:x%x flg:x%x cnt:%d",
523 Did, vport->fc_flag,
524 vport->fc_rscn_id_cnt);
525
James Smart0ff10d42008-01-11 01:52:36 -0500526 /* This NPortID was previously
527 * a FCP target, * Don't even
528 * bother to send GFF_ID.
529 */
530 ndlp = lpfc_findnode_did(vport,
531 Did);
James Smarte47c9092008-02-08 18:49:26 -0500532 if (ndlp &&
533 NLP_CHK_NODE_ACT(ndlp)
534 && (ndlp->nlp_type &
535 NLP_FCP_TARGET))
James Smart0ff10d42008-01-11 01:52:36 -0500536 lpfc_setup_disc_node
537 (vport, Did);
538 else if (lpfc_ns_cmd(vport,
James Smart92d7f7b2007-06-17 19:56:38 -0500539 SLI_CTNS_GFF_ID,
540 0, Did) == 0)
541 vport->num_disc_nodes++;
James Smart6a9c52c2009-10-02 15:16:51 -0400542 else
543 lpfc_setup_disc_node
544 (vport, Did);
James Smart92d7f7b2007-06-17 19:56:38 -0500545 }
546 else {
James Smart858c9f62007-06-17 19:56:39 -0500547 lpfc_debugfs_disc_trc(vport,
548 LPFC_DISC_TRC_CT,
549 "Skip2 GID_FTrsp: "
550 "did:x%x flg:x%x cnt:%d",
551 Did, vport->fc_flag,
552 vport->fc_rscn_id_cnt);
553
James Smarte8b62012007-08-02 11:10:09 -0400554 lpfc_printf_vlog(vport,
555 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500556 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400557 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500558 "NameServer Rsp Data: "
559 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400560 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500561 vport->fc_rscn_id_cnt);
562 }
563 }
dea31012005-04-17 16:05:31 -0500564 }
dea31012005-04-17 16:05:31 -0500565 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
566 goto nsout1;
567 Cnt -= sizeof (uint32_t);
568 }
569 ctptr = NULL;
570
571 }
572
573nsout1:
574 list_del(&head);
dea31012005-04-17 16:05:31 -0500575 return 0;
576}
577
dea31012005-04-17 16:05:31 -0500578static void
James Smart2e0fef82007-06-17 19:56:36 -0500579lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
580 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500581{
James Smart2e0fef82007-06-17 19:56:36 -0500582 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500584 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500585 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500586 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500587 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400588 struct lpfc_nodelist *ndlp;
James Smart58da1ff2008-04-07 10:15:56 -0400589 int rc;
dea31012005-04-17 16:05:31 -0500590
James Smart51ef4c22007-08-02 11:10:31 -0400591 /* First save ndlp, before we overwrite it */
592 ndlp = cmdiocb->context_un.ndlp;
593
dea31012005-04-17 16:05:31 -0500594 /* we pass cmdiocb to state machine which needs rspiocb as well */
595 cmdiocb->context_un.rsp_iocb = rspiocb;
596
dea31012005-04-17 16:05:31 -0500597 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
598 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500599 irsp = &rspiocb->iocb;
600
601 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
602 "GID_FT cmpl: status:x%x/x%x rtry:%d",
603 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500604
James Smart92d7f7b2007-06-17 19:56:38 -0500605 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500606 if (vport->load_flag & FC_UNLOADING) {
607 if (vport->fc_flag & FC_RSCN_MODE)
608 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500609 goto out;
James Smarteada2722008-12-04 22:39:13 -0500610 }
James Smart92d7f7b2007-06-17 19:56:38 -0500611
James Smart58da1ff2008-04-07 10:15:56 -0400612 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400613 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
614 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500615 if (vport->fc_flag & FC_RSCN_MODE)
616 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500617 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
618 goto out;
619 }
James Smart58da1ff2008-04-07 10:15:56 -0400620 if (lpfc_error_lost_link(irsp)) {
621 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
622 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500623 if (vport->fc_flag & FC_RSCN_MODE)
624 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400625 goto out;
626 }
James Smart858c9f62007-06-17 19:56:39 -0500627 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500628 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500629 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400630 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
631 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500632 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500633
James Smart58da1ff2008-04-07 10:15:56 -0400634 /* CT command is being retried */
635 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smart92d7f7b2007-06-17 19:56:38 -0500636 vport->fc_ns_retry, 0);
James Smart58da1ff2008-04-07 10:15:56 -0400637 if (rc == 0)
638 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500639 }
James Smarteada2722008-12-04 22:39:13 -0500640 if (vport->fc_flag & FC_RSCN_MODE)
641 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500642 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400643 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
644 "0257 GID_FT Query error: 0x%x 0x%x\n",
645 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500646 } else {
647 /* Good status, continue checking */
648 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
649 if (CTrsp->CommandResponse.bits.CmdRsp ==
650 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400651 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
652 "0208 NameServer Rsp Data: x%x\n",
653 vport->fc_flag);
James Smart2e0fef82007-06-17 19:56:36 -0500654 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500655 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
656 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
657 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
658 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400659 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
660 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400661 lpfc_printf_vlog(vport, KERN_INFO,
662 LOG_DISCOVERY,
663 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400664 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400665 CTrsp->CommandResponse.bits.CmdRsp,
666 (uint32_t) CTrsp->ReasonCode,
667 (uint32_t) CTrsp->Explanation,
668 vport->fc_flag);
669
670 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
671 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
672 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
673 (uint32_t) CTrsp->ReasonCode,
674 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400675 } else {
676 lpfc_printf_vlog(vport, KERN_INFO,
677 LOG_DISCOVERY,
678 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500679 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500680 CTrsp->CommandResponse.bits.CmdRsp,
681 (uint32_t) CTrsp->ReasonCode,
682 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500683 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500684
James Smarta58cbd52007-08-02 11:09:43 -0400685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500686 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
687 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
688 (uint32_t) CTrsp->ReasonCode,
689 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400690 }
691
James Smart858c9f62007-06-17 19:56:39 -0500692
dea31012005-04-17 16:05:31 -0500693 } else {
694 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400695 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
696 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500697 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500698 CTrsp->CommandResponse.bits.CmdRsp,
699 (uint32_t) CTrsp->ReasonCode,
700 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500701 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500702
703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
704 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
705 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
706 (uint32_t) CTrsp->ReasonCode,
707 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500708 }
709 }
710 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500711 if (vport->num_disc_nodes == 0) {
712 /*
713 * The driver has cycled through all Nports in the RSCN payload.
714 * Complete the handling by cleaning up and marking the
715 * current driver state.
716 */
717 if (vport->port_state >= LPFC_DISC_AUTH) {
718 if (vport->fc_flag & FC_RSCN_MODE) {
719 lpfc_els_flush_rscn(vport);
720 spin_lock_irq(shost->host_lock);
721 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
722 spin_unlock_irq(shost->host_lock);
723 }
724 else
725 lpfc_els_flush_rscn(vport);
726 }
727
728 lpfc_disc_start(vport);
729 }
dea31012005-04-17 16:05:31 -0500730out:
James Smart51ef4c22007-08-02 11:10:31 -0400731 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500732 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500733 return;
734}
735
James Smart311464e2007-08-02 11:10:37 -0400736static void
James Smart92d7f7b2007-06-17 19:56:38 -0500737lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
738 struct lpfc_iocbq *rspiocb)
739{
740 struct lpfc_vport *vport = cmdiocb->vport;
741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
742 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500743 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
744 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
745 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500746 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500747 uint8_t fbits;
748 struct lpfc_nodelist *ndlp;
749
750 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
751 did = be32_to_cpu(did);
752
James Smart858c9f62007-06-17 19:56:39 -0500753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
754 "GFF_ID cmpl: status:x%x/x%x did:x%x",
755 irsp->ulpStatus, irsp->un.ulpWord[4], did);
756
James Smart92d7f7b2007-06-17 19:56:38 -0500757 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
758 /* Good status, continue checking */
759 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
760 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
761
762 if (CTrsp->CommandResponse.bits.CmdRsp ==
763 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
764 if ((fbits & FC4_FEATURE_INIT) &&
765 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400766 lpfc_printf_vlog(vport, KERN_INFO,
767 LOG_DISCOVERY,
768 "0270 Skip x%x GFF "
769 "NameServer Rsp Data: (init) "
770 "x%x x%x\n", did, fbits,
771 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500772 goto out;
773 }
774 }
775 }
James Smart858c9f62007-06-17 19:56:39 -0500776 else {
James Smart0ff10d42008-01-11 01:52:36 -0500777 /* Check for retry */
778 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
779 retry = 1;
780 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
781 switch (irsp->un.ulpWord[4]) {
782 case IOERR_NO_RESOURCES:
783 /* We don't increment the retry
784 * count for this case.
785 */
786 break;
787 case IOERR_LINK_DOWN:
788 case IOERR_SLI_ABORTED:
789 case IOERR_SLI_DOWN:
790 retry = 0;
791 break;
792 default:
793 cmdiocb->retry++;
794 }
795 }
796 else
797 cmdiocb->retry++;
798
799 if (retry) {
800 /* CT command is being retried */
801 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
802 cmdiocb->retry, did);
803 if (rc == 0) {
804 /* success */
805 lpfc_ct_free_iocb(phba, cmdiocb);
806 return;
807 }
808 }
809 }
James Smarte8b62012007-08-02 11:10:09 -0400810 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
811 "0267 NameServer GFF Rsp "
812 "x%x Error (%d %d) Data: x%x x%x\n",
813 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500814 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500815 }
816
James Smart92d7f7b2007-06-17 19:56:38 -0500817 /* This is a target port, unregistered port, or the GFF_ID failed */
818 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400819 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400820 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
821 "0242 Process x%x GFF "
822 "NameServer Rsp Data: x%x x%x x%x\n",
823 did, ndlp->nlp_flag, vport->fc_flag,
824 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500825 } else {
James Smarte8b62012007-08-02 11:10:09 -0400826 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
827 "0243 Skip x%x GFF "
828 "NameServer Rsp Data: x%x x%x\n", did,
829 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500830 }
831out:
832 /* Link up / RSCN discovery */
833 if (vport->num_disc_nodes)
834 vport->num_disc_nodes--;
835 if (vport->num_disc_nodes == 0) {
836 /*
837 * The driver has cycled through all Nports in the RSCN payload.
838 * Complete the handling by cleaning up and marking the
839 * current driver state.
840 */
841 if (vport->port_state >= LPFC_DISC_AUTH) {
842 if (vport->fc_flag & FC_RSCN_MODE) {
843 lpfc_els_flush_rscn(vport);
844 spin_lock_irq(shost->host_lock);
845 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
846 spin_unlock_irq(shost->host_lock);
847 }
848 else
849 lpfc_els_flush_rscn(vport);
850 }
851 lpfc_disc_start(vport);
852 }
James Smart858c9f62007-06-17 19:56:39 -0500853 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500854 return;
855}
856
857
dea31012005-04-17 16:05:31 -0500858static void
James Smart7ee5d432007-10-27 13:37:17 -0400859lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
860 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500861{
James Smart92d7f7b2007-06-17 19:56:38 -0500862 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500863 struct lpfc_dmabuf *inp;
864 struct lpfc_dmabuf *outp;
865 IOCB_t *irsp;
866 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400867 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500868 int cmdcode, rc;
869 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500870 uint32_t latt;
dea31012005-04-17 16:05:31 -0500871
James Smart51ef4c22007-08-02 11:10:31 -0400872 /* First save ndlp, before we overwrite it */
873 ndlp = cmdiocb->context_un.ndlp;
874
dea31012005-04-17 16:05:31 -0500875 /* we pass cmdiocb to state machine which needs rspiocb as well */
876 cmdiocb->context_un.rsp_iocb = rspiocb;
877
878 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
879 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500880 irsp = &rspiocb->iocb;
881
James Smart92d7f7b2007-06-17 19:56:38 -0500882 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
883 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500884 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
885
James Smart858c9f62007-06-17 19:56:39 -0500886 latt = lpfc_els_chk_latt(vport);
887
888 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400889 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400890 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400891 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
892 latt, irsp->ulpStatus,
893 CTrsp->CommandResponse.bits.CmdRsp,
894 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500895
James Smart858c9f62007-06-17 19:56:39 -0500896 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
897 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
898 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
899
James Smart92d7f7b2007-06-17 19:56:38 -0500900 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400901 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
902 "0268 NS cmd %x Error (%d %d)\n",
903 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500904
James Smart92d7f7b2007-06-17 19:56:38 -0500905 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
906 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
907 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
908 goto out;
909
910 retry = cmdiocb->retry;
911 if (retry >= LPFC_MAX_NS_RETRY)
912 goto out;
913
914 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400915 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -0400916 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500917 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
918 if (rc == 0)
919 goto out;
920 }
921
922out:
James Smart51ef4c22007-08-02 11:10:31 -0400923 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500924 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500925 return;
926}
927
928static void
James Smart7ee5d432007-10-27 13:37:17 -0400929lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
930 struct lpfc_iocbq *rspiocb)
931{
932 IOCB_t *irsp = &rspiocb->iocb;
933 struct lpfc_vport *vport = cmdiocb->vport;
934
James Smart98c9ea52007-10-27 13:37:33 -0400935 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
936 struct lpfc_dmabuf *outp;
937 struct lpfc_sli_ct_request *CTrsp;
938
939 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
940 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
941 if (CTrsp->CommandResponse.bits.CmdRsp ==
942 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
943 vport->ct_flags |= FC_CT_RFT_ID;
944 }
James Smart7ee5d432007-10-27 13:37:17 -0400945 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
946 return;
947}
948
949static void
James Smart2e0fef82007-06-17 19:56:36 -0500950lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
951 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500952{
James Smart7ee5d432007-10-27 13:37:17 -0400953 IOCB_t *irsp = &rspiocb->iocb;
954 struct lpfc_vport *vport = cmdiocb->vport;
955
James Smart98c9ea52007-10-27 13:37:33 -0400956 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
957 struct lpfc_dmabuf *outp;
958 struct lpfc_sli_ct_request *CTrsp;
959
960 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
961 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
962 if (CTrsp->CommandResponse.bits.CmdRsp ==
963 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
964 vport->ct_flags |= FC_CT_RNN_ID;
965 }
James Smart7ee5d432007-10-27 13:37:17 -0400966 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500967 return;
968}
969
970static void
James Smart92d7f7b2007-06-17 19:56:38 -0500971lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
972 struct lpfc_iocbq *rspiocb)
973{
James Smart7ee5d432007-10-27 13:37:17 -0400974 IOCB_t *irsp = &rspiocb->iocb;
975 struct lpfc_vport *vport = cmdiocb->vport;
976
James Smart98c9ea52007-10-27 13:37:33 -0400977 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
978 struct lpfc_dmabuf *outp;
979 struct lpfc_sli_ct_request *CTrsp;
980
981 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
982 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
983 if (CTrsp->CommandResponse.bits.CmdRsp ==
984 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
985 vport->ct_flags |= FC_CT_RSPN_ID;
986 }
James Smart7ee5d432007-10-27 13:37:17 -0400987 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500988 return;
989}
990
991static void
James Smart2e0fef82007-06-17 19:56:36 -0500992lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
993 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500994{
James Smart7ee5d432007-10-27 13:37:17 -0400995 IOCB_t *irsp = &rspiocb->iocb;
996 struct lpfc_vport *vport = cmdiocb->vport;
997
James Smart98c9ea52007-10-27 13:37:33 -0400998 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
999 struct lpfc_dmabuf *outp;
1000 struct lpfc_sli_ct_request *CTrsp;
1001
1002 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1003 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1004 if (CTrsp->CommandResponse.bits.CmdRsp ==
1005 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1006 vport->ct_flags |= FC_CT_RSNN_NN;
1007 }
James Smart7ee5d432007-10-27 13:37:17 -04001008 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1009 return;
1010}
1011
1012static void
1013lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1014 struct lpfc_iocbq *rspiocb)
1015{
1016 struct lpfc_vport *vport = cmdiocb->vport;
1017
1018 /* even if it fails we will act as though it succeeded. */
1019 vport->ct_flags = 0;
1020 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001021 return;
1022}
1023
James Smart2fb9bd82006-12-02 13:33:57 -05001024static void
James Smart92d7f7b2007-06-17 19:56:38 -05001025lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1026 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001027{
James Smart92d7f7b2007-06-17 19:56:38 -05001028 IOCB_t *irsp = &rspiocb->iocb;
1029 struct lpfc_vport *vport = cmdiocb->vport;
1030
James Smart98c9ea52007-10-27 13:37:33 -04001031 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1032 struct lpfc_dmabuf *outp;
1033 struct lpfc_sli_ct_request *CTrsp;
1034
1035 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1036 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1037 if (CTrsp->CommandResponse.bits.CmdRsp ==
1038 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1039 vport->ct_flags |= FC_CT_RFF_ID;
1040 }
James Smart7ee5d432007-10-27 13:37:17 -04001041 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001042 return;
1043}
1044
James Smart495a7142008-06-14 22:52:59 -04001045int
James Smart92d7f7b2007-06-17 19:56:38 -05001046lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1047 size_t size)
1048{
1049 int n;
1050 uint8_t *wwn = vport->phba->wwpn;
1051
1052 n = snprintf(symbol, size,
1053 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1054 wwn[0], wwn[1], wwn[2], wwn[3],
1055 wwn[4], wwn[5], wwn[6], wwn[7]);
1056
1057 if (vport->port_type == LPFC_PHYSICAL_PORT)
1058 return n;
1059
1060 if (n < size)
1061 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1062
James Smarteada2722008-12-04 22:39:13 -05001063 if (n < size &&
1064 strlen(vport->fc_vport->symbolic_name))
1065 n += snprintf(symbol + n, size - n, " VName-%s",
1066 vport->fc_vport->symbolic_name);
James Smart92d7f7b2007-06-17 19:56:38 -05001067 return n;
1068}
1069
1070int
1071lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1072 size_t size)
dea31012005-04-17 16:05:31 -05001073{
1074 char fwrev[16];
James Smart92d7f7b2007-06-17 19:56:38 -05001075 int n;
dea31012005-04-17 16:05:31 -05001076
James Smart92d7f7b2007-06-17 19:56:38 -05001077 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001078
James Smart92d7f7b2007-06-17 19:56:38 -05001079 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1080 vport->phba->ModelName, fwrev, lpfc_release_version);
1081 return n;
dea31012005-04-17 16:05:31 -05001082}
1083
1084/*
1085 * lpfc_ns_cmd
1086 * Description:
1087 * Issue Cmd to NameServer
1088 * SLI_CTNS_GID_FT
1089 * LI_CTNS_RFT_ID
1090 */
1091int
James Smart92d7f7b2007-06-17 19:56:38 -05001092lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1093 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001094{
James Smart92d7f7b2007-06-17 19:56:38 -05001095 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001096 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001097 struct lpfc_dmabuf *mp, *bmp;
1098 struct lpfc_sli_ct_request *CtReq;
1099 struct ulp_bde64 *bpl;
1100 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1101 struct lpfc_iocbq *) = NULL;
1102 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001103 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001104 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001105
1106 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001107 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1108 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001109 rc=1;
1110 goto ns_cmd_exit;
1111 }
dea31012005-04-17 16:05:31 -05001112
1113 /* fill in BDEs for command */
1114 /* Allocate buffer for command payload */
1115 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001116 if (!mp) {
1117 rc=2;
dea31012005-04-17 16:05:31 -05001118 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001119 }
dea31012005-04-17 16:05:31 -05001120
1121 INIT_LIST_HEAD(&mp->list);
1122 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001123 if (!mp->virt) {
1124 rc=3;
dea31012005-04-17 16:05:31 -05001125 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001126 }
dea31012005-04-17 16:05:31 -05001127
1128 /* Allocate buffer for Buffer ptr list */
1129 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001130 if (!bmp) {
1131 rc=4;
dea31012005-04-17 16:05:31 -05001132 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001133 }
dea31012005-04-17 16:05:31 -05001134
1135 INIT_LIST_HEAD(&bmp->list);
1136 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001137 if (!bmp->virt) {
1138 rc=5;
dea31012005-04-17 16:05:31 -05001139 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001140 }
dea31012005-04-17 16:05:31 -05001141
1142 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001143 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1144 "0236 NameServer Req Data: x%x x%x x%x\n",
1145 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001146
1147 bpl = (struct ulp_bde64 *) bmp->virt;
1148 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001149 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1150 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001151 bpl->tus.f.bdeFlags = 0;
1152 if (cmdcode == SLI_CTNS_GID_FT)
1153 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001154 else if (cmdcode == SLI_CTNS_GFF_ID)
1155 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001156 else if (cmdcode == SLI_CTNS_RFT_ID)
1157 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1158 else if (cmdcode == SLI_CTNS_RNN_ID)
1159 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001160 else if (cmdcode == SLI_CTNS_RSPN_ID)
1161 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001162 else if (cmdcode == SLI_CTNS_RSNN_NN)
1163 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001164 else if (cmdcode == SLI_CTNS_DA_ID)
1165 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001166 else if (cmdcode == SLI_CTNS_RFF_ID)
1167 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001168 else
1169 bpl->tus.f.bdeSize = 0;
1170 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1171
1172 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1173 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1174 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1175 CtReq->RevisionId.bits.InId = 0;
1176 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1177 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1178 CtReq->CommandResponse.bits.Size = 0;
1179 switch (cmdcode) {
1180 case SLI_CTNS_GID_FT:
1181 CtReq->CommandResponse.bits.CmdRsp =
1182 be16_to_cpu(SLI_CTNS_GID_FT);
1183 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001184 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001185 vport->port_state = LPFC_NS_QRY;
1186 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001187 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1188 rsp_size = FC_MAX_NS_RSP;
1189 break;
1190
James Smart92d7f7b2007-06-17 19:56:38 -05001191 case SLI_CTNS_GFF_ID:
1192 CtReq->CommandResponse.bits.CmdRsp =
1193 be16_to_cpu(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001194 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001195 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1196 break;
1197
dea31012005-04-17 16:05:31 -05001198 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001199 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001200 CtReq->CommandResponse.bits.CmdRsp =
1201 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001202 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001203 CtReq->un.rft.fcpReg = 1;
1204 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1205 break;
1206
1207 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001208 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001209 CtReq->CommandResponse.bits.CmdRsp =
1210 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001211 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001212 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001213 sizeof (struct lpfc_name));
1214 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1215 break;
1216
James Smart92d7f7b2007-06-17 19:56:38 -05001217 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001218 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001219 CtReq->CommandResponse.bits.CmdRsp =
1220 be16_to_cpu(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001221 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001222 size = sizeof(CtReq->un.rspn.symbname);
1223 CtReq->un.rspn.len =
1224 lpfc_vport_symbolic_port_name(vport,
1225 CtReq->un.rspn.symbname, size);
1226 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1227 break;
dea31012005-04-17 16:05:31 -05001228 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001229 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001230 CtReq->CommandResponse.bits.CmdRsp =
1231 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001232 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001233 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001234 size = sizeof(CtReq->un.rsnn.symbname);
1235 CtReq->un.rsnn.len =
1236 lpfc_vport_symbolic_node_name(vport,
1237 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001238 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1239 break;
James Smart7ee5d432007-10-27 13:37:17 -04001240 case SLI_CTNS_DA_ID:
1241 /* Implement DA_ID Nameserver request */
1242 CtReq->CommandResponse.bits.CmdRsp =
1243 be16_to_cpu(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001244 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001245 cmpl = lpfc_cmpl_ct_cmd_da_id;
1246 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001247 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001248 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001249 CtReq->CommandResponse.bits.CmdRsp =
1250 be16_to_cpu(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001251 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001252 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smart6a9c52c2009-10-02 15:16:51 -04001253 CtReq->un.rff.type_code = FC_TYPE_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001254 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1255 break;
dea31012005-04-17 16:05:31 -05001256 }
James Smarte47c9092008-02-08 18:49:26 -05001257 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1258 * to hold ndlp reference for the corresponding callback function.
1259 */
James Smart858c9f62007-06-17 19:56:39 -05001260 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001261 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001262 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1263 "Issue CT cmd: cmd:x%x did:x%x",
1264 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001265 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001266 }
James Smart858c9f62007-06-17 19:56:39 -05001267 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001268
1269 /* Decrement ndlp reference count to release ndlp reference held
1270 * for the failed command's callback function.
1271 */
James Smart51ef4c22007-08-02 11:10:31 -04001272 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001273
dea31012005-04-17 16:05:31 -05001274 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1275ns_cmd_free_bmp:
1276 kfree(bmp);
1277ns_cmd_free_mpvirt:
1278 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1279ns_cmd_free_mp:
1280 kfree(mp);
1281ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001282 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1283 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1284 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001285 return 1;
1286}
1287
1288static void
James Smart2e0fef82007-06-17 19:56:36 -05001289lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1290 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001291{
dea31012005-04-17 16:05:31 -05001292 struct lpfc_dmabuf *inp = cmdiocb->context1;
1293 struct lpfc_dmabuf *outp = cmdiocb->context2;
1294 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1295 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1296 struct lpfc_nodelist *ndlp;
1297 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1298 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001299 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001300 IOCB_t *irsp = &rspiocb->iocb;
1301 uint32_t latt;
1302
1303 latt = lpfc_els_chk_latt(vport);
1304
1305 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1306 "FDMI cmpl: status:x%x/x%x latt:%d",
1307 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1308
1309 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001310 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1311 "0229 FDMI cmd %04x failed, latt = %d "
1312 "ulpStatus: x%x, rid x%x\n",
1313 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1314 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001315 lpfc_ct_free_iocb(phba, cmdiocb);
1316 return;
1317 }
dea31012005-04-17 16:05:31 -05001318
James Smart2e0fef82007-06-17 19:56:36 -05001319 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001320 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1321 goto fail_out;
1322
dea31012005-04-17 16:05:31 -05001323 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1324 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001325 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1326 "0220 FDMI rsp failed Data: x%x\n",
1327 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001328 }
1329
1330 switch (be16_to_cpu(fdmi_cmd)) {
1331 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001332 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001333 break;
1334
1335 case SLI_MGMT_RPA:
1336 break;
1337
1338 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001339 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001340 break;
1341
1342 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001343 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001344 break;
1345 }
James Smarte47c9092008-02-08 18:49:26 -05001346
1347fail_out:
James Smart858c9f62007-06-17 19:56:39 -05001348 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001349 return;
1350}
James Smart2e0fef82007-06-17 19:56:36 -05001351
dea31012005-04-17 16:05:31 -05001352int
James Smart2e0fef82007-06-17 19:56:36 -05001353lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001354{
James Smart2e0fef82007-06-17 19:56:36 -05001355 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001356 struct lpfc_dmabuf *mp, *bmp;
1357 struct lpfc_sli_ct_request *CtReq;
1358 struct ulp_bde64 *bpl;
1359 uint32_t size;
1360 REG_HBA *rh;
1361 PORT_ENTRY *pe;
1362 REG_PORT_ATTRIBUTE *pab;
1363 ATTRIBUTE_BLOCK *ab;
1364 ATTRIBUTE_ENTRY *ae;
1365 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1366 struct lpfc_iocbq *);
1367
1368
1369 /* fill in BDEs for command */
1370 /* Allocate buffer for command payload */
1371 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1372 if (!mp)
1373 goto fdmi_cmd_exit;
1374
1375 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1376 if (!mp->virt)
1377 goto fdmi_cmd_free_mp;
1378
1379 /* Allocate buffer for Buffer ptr list */
1380 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1381 if (!bmp)
1382 goto fdmi_cmd_free_mpvirt;
1383
1384 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1385 if (!bmp->virt)
1386 goto fdmi_cmd_free_bmp;
1387
1388 INIT_LIST_HEAD(&mp->list);
1389 INIT_LIST_HEAD(&bmp->list);
1390
1391 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001392 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1393 "0218 FDMI Request Data: x%x x%x x%x\n",
1394 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001395 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1396
1397 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1398 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1399 CtReq->RevisionId.bits.InId = 0;
1400
1401 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1402 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1403 size = 0;
1404
1405 switch (cmdcode) {
1406 case SLI_MGMT_RHBA:
1407 {
1408 lpfc_vpd_t *vp = &phba->vpd;
1409 uint32_t i, j, incr;
1410 int len;
1411
1412 CtReq->CommandResponse.bits.CmdRsp =
1413 be16_to_cpu(SLI_MGMT_RHBA);
1414 CtReq->CommandResponse.bits.Size = 0;
1415 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001416 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001417 sizeof (struct lpfc_name));
1418 /* One entry (port) per adapter */
1419 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001420 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001421 sizeof (struct lpfc_name));
1422
1423 /* point to the HBA attribute block */
1424 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1425 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1426 ab->EntryCnt = 0;
1427
1428 /* Point to the beginning of the first HBA attribute
1429 entry */
1430 /* #1 HBA attribute entry */
1431 size += FOURBYTES;
1432 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1433 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1434 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1435 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001436 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001437 sizeof (struct lpfc_name));
1438 ab->EntryCnt++;
1439 size += FOURBYTES + sizeof (struct lpfc_name);
1440
1441 /* #2 HBA attribute entry */
1442 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1443 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1444 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1445 len = strlen(ae->un.Manufacturer);
1446 len += (len & 3) ? (4 - (len & 3)) : 4;
1447 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1448 ab->EntryCnt++;
1449 size += FOURBYTES + len;
1450
1451 /* #3 HBA attribute entry */
1452 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1453 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1454 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1455 len = strlen(ae->un.SerialNumber);
1456 len += (len & 3) ? (4 - (len & 3)) : 4;
1457 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1458 ab->EntryCnt++;
1459 size += FOURBYTES + len;
1460
1461 /* #4 HBA attribute entry */
1462 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1463 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1464 strcpy(ae->un.Model, phba->ModelName);
1465 len = strlen(ae->un.Model);
1466 len += (len & 3) ? (4 - (len & 3)) : 4;
1467 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1468 ab->EntryCnt++;
1469 size += FOURBYTES + len;
1470
1471 /* #5 HBA attribute entry */
1472 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1473 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1474 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1475 len = strlen(ae->un.ModelDescription);
1476 len += (len & 3) ? (4 - (len & 3)) : 4;
1477 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1478 ab->EntryCnt++;
1479 size += FOURBYTES + len;
1480
1481 /* #6 HBA attribute entry */
1482 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1483 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1484 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1485 /* Convert JEDEC ID to ascii for hardware version */
1486 incr = vp->rev.biuRev;
1487 for (i = 0; i < 8; i++) {
1488 j = (incr & 0xf);
1489 if (j <= 9)
1490 ae->un.HardwareVersion[7 - i] =
1491 (char)((uint8_t) 0x30 +
1492 (uint8_t) j);
1493 else
1494 ae->un.HardwareVersion[7 - i] =
1495 (char)((uint8_t) 0x61 +
1496 (uint8_t) (j - 10));
1497 incr = (incr >> 4);
1498 }
1499 ab->EntryCnt++;
1500 size += FOURBYTES + 8;
1501
1502 /* #7 HBA attribute entry */
1503 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1504 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1505 strcpy(ae->un.DriverVersion, lpfc_release_version);
1506 len = strlen(ae->un.DriverVersion);
1507 len += (len & 3) ? (4 - (len & 3)) : 4;
1508 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1509 ab->EntryCnt++;
1510 size += FOURBYTES + len;
1511
1512 /* #8 HBA attribute entry */
1513 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1514 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1515 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1516 len = strlen(ae->un.OptionROMVersion);
1517 len += (len & 3) ? (4 - (len & 3)) : 4;
1518 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1519 ab->EntryCnt++;
1520 size += FOURBYTES + len;
1521
1522 /* #9 HBA attribute entry */
1523 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1524 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1525 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1526 1);
1527 len = strlen(ae->un.FirmwareVersion);
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 /* #10 HBA attribute entry */
1534 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1535 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1536 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001537 init_utsname()->sysname,
1538 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001539 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001540 len = strlen(ae->un.OsNameVersion);
1541 len += (len & 3) ? (4 - (len & 3)) : 4;
1542 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1543 ab->EntryCnt++;
1544 size += FOURBYTES + len;
1545
1546 /* #11 HBA attribute entry */
1547 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1548 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1549 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1550 ae->un.MaxCTPayloadLen = (65 * 4096);
1551 ab->EntryCnt++;
1552 size += FOURBYTES + 4;
1553
1554 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1555 /* Total size */
1556 size = GID_REQUEST_SZ - 4 + size;
1557 }
1558 break;
1559
1560 case SLI_MGMT_RPA:
1561 {
1562 lpfc_vpd_t *vp;
1563 struct serv_parm *hsp;
1564 int len;
1565
1566 vp = &phba->vpd;
1567
1568 CtReq->CommandResponse.bits.CmdRsp =
1569 be16_to_cpu(SLI_MGMT_RPA);
1570 CtReq->CommandResponse.bits.Size = 0;
1571 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1572 size = sizeof (struct lpfc_name) + FOURBYTES;
1573 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001574 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001575 sizeof (struct lpfc_name));
1576 pab->ab.EntryCnt = 0;
1577
1578 /* #1 Port attribute entry */
1579 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1580 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1581 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1582 ae->un.SupportFC4Types[2] = 1;
1583 ae->un.SupportFC4Types[7] = 1;
1584 pab->ab.EntryCnt++;
1585 size += FOURBYTES + 32;
1586
1587 /* #2 Port attribute entry */
1588 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1589 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1590 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001591
1592 ae->un.SupportSpeed = 0;
1593 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001594 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001595 if (phba->lmt & LMT_8Gb)
1596 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1597 if (phba->lmt & LMT_4Gb)
1598 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1599 if (phba->lmt & LMT_2Gb)
1600 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1601 if (phba->lmt & LMT_1Gb)
1602 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1603
dea31012005-04-17 16:05:31 -05001604 pab->ab.EntryCnt++;
1605 size += FOURBYTES + 4;
1606
1607 /* #3 Port attribute entry */
1608 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1609 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1610 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1611 switch(phba->fc_linkspeed) {
1612 case LA_1GHZ_LINK:
1613 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1614 break;
1615 case LA_2GHZ_LINK:
1616 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1617 break;
1618 case LA_4GHZ_LINK:
1619 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1620 break;
James Smartb87eab32007-04-25 09:53:28 -04001621 case LA_8GHZ_LINK:
1622 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1623 break;
James Smartf4b4c682009-05-22 14:53:12 -04001624 case LA_10GHZ_LINK:
1625 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
1626 break;
dea31012005-04-17 16:05:31 -05001627 default:
1628 ae->un.PortSpeed =
1629 HBA_PORTSPEED_UNKNOWN;
1630 break;
1631 }
1632 pab->ab.EntryCnt++;
1633 size += FOURBYTES + 4;
1634
1635 /* #4 Port attribute entry */
1636 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1637 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1638 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001639 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001640 ae->un.MaxFrameSize =
1641 (((uint32_t) hsp->cmn.
1642 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1643 bbRcvSizeLsb;
1644 pab->ab.EntryCnt++;
1645 size += FOURBYTES + 4;
1646
1647 /* #5 Port attribute entry */
1648 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1649 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1650 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1651 len = strlen((char *)ae->un.OsDeviceName);
1652 len += (len & 3) ? (4 - (len & 3)) : 4;
1653 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1654 pab->ab.EntryCnt++;
1655 size += FOURBYTES + len;
1656
James Smart3de2a652007-08-02 11:09:59 -04001657 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001658 /* #6 Port attribute entry */
1659 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1660 size);
1661 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1662 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001663 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001664 len = strlen(ae->un.HostName);
1665 len += (len & 3) ? (4 - (len & 3)) : 4;
1666 ae->ad.bits.AttrLen =
1667 be16_to_cpu(FOURBYTES + len);
1668 pab->ab.EntryCnt++;
1669 size += FOURBYTES + len;
1670 }
1671
1672 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1673 /* Total size */
1674 size = GID_REQUEST_SZ - 4 + size;
1675 }
1676 break;
1677
1678 case SLI_MGMT_DHBA:
1679 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1680 CtReq->CommandResponse.bits.Size = 0;
1681 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1682 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001683 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001684 sizeof (struct lpfc_name));
1685 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1686 break;
1687
1688 case SLI_MGMT_DPRT:
1689 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1690 CtReq->CommandResponse.bits.Size = 0;
1691 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1692 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001693 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001694 sizeof (struct lpfc_name));
1695 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1696 break;
1697 }
1698
1699 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001700 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1701 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001702 bpl->tus.f.bdeFlags = 0;
1703 bpl->tus.f.bdeSize = size;
1704 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1705
1706 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1707
James Smarte47c9092008-02-08 18:49:26 -05001708 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1709 * to hold ndlp reference for the corresponding callback function.
1710 */
James Smart92d7f7b2007-06-17 19:56:38 -05001711 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001712 return 0;
1713
James Smarte47c9092008-02-08 18:49:26 -05001714 /* Decrement ndlp reference count to release ndlp reference held
1715 * for the failed command's callback function.
1716 */
James Smart51ef4c22007-08-02 11:10:31 -04001717 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001718
dea31012005-04-17 16:05:31 -05001719 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1720fdmi_cmd_free_bmp:
1721 kfree(bmp);
1722fdmi_cmd_free_mpvirt:
1723 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1724fdmi_cmd_free_mp:
1725 kfree(mp);
1726fdmi_cmd_exit:
1727 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001728 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1729 "0244 Issue FDMI request failed Data: x%x\n",
1730 cmdcode);
dea31012005-04-17 16:05:31 -05001731 return 1;
1732}
1733
1734void
1735lpfc_fdmi_tmo(unsigned long ptr)
1736{
James Smart2e0fef82007-06-17 19:56:36 -05001737 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1738 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001739 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05001740 unsigned long iflag;
1741
James Smart2e0fef82007-06-17 19:56:36 -05001742 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001743 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1744 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05001745 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04001746 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001747
James Smart5e9d9b82008-06-14 22:52:53 -04001748 if (!tmo_posted)
1749 lpfc_worker_wake_up(phba);
1750 return;
dea31012005-04-17 16:05:31 -05001751}
1752
1753void
James Smart2e0fef82007-06-17 19:56:36 -05001754lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001755{
1756 struct lpfc_nodelist *ndlp;
1757
James Smart2e0fef82007-06-17 19:56:36 -05001758 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001759 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001760 if (init_utsname()->nodename[0] != '\0')
1761 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1762 else
1763 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001764 }
dea31012005-04-17 16:05:31 -05001765 return;
1766}
1767
dea31012005-04-17 16:05:31 -05001768void
James Smart2e0fef82007-06-17 19:56:36 -05001769lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001770{
1771 struct lpfc_sli *psli = &phba->sli;
1772 lpfc_vpd_t *vp = &phba->vpd;
1773 uint32_t b1, b2, b3, b4, i, rev;
1774 char c;
1775 uint32_t *ptr, str[4];
1776 uint8_t *fwname;
1777
James Smartf1126682009-06-10 17:22:44 -04001778 if (phba->sli_rev == LPFC_SLI_REV4)
1779 sprintf(fwrevision, "%s", vp->rev.opFwName);
1780 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04001781 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001782 rev = vp->rev.sli2FwRev;
1783 else
1784 rev = vp->rev.sli1FwRev;
1785
1786 b1 = (rev & 0x0000f000) >> 12;
1787 b2 = (rev & 0x00000f00) >> 8;
1788 b3 = (rev & 0x000000c0) >> 6;
1789 b4 = (rev & 0x00000030) >> 4;
1790
1791 switch (b4) {
1792 case 0:
1793 c = 'N';
1794 break;
1795 case 1:
1796 c = 'A';
1797 break;
1798 case 2:
1799 c = 'B';
1800 break;
1801 default:
1802 c = 0;
1803 break;
1804 }
1805 b4 = (rev & 0x0000000f);
1806
James Smartf4b4c682009-05-22 14:53:12 -04001807 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001808 fwname = vp->rev.sli2FwName;
1809 else
1810 fwname = vp->rev.sli1FwName;
1811
1812 for (i = 0; i < 16; i++)
1813 if (fwname[i] == 0x20)
1814 fwname[i] = 0;
1815
1816 ptr = (uint32_t*)fwname;
1817
1818 for (i = 0; i < 3; i++)
1819 str[i] = be32_to_cpu(*ptr++);
1820
1821 if (c == 0) {
1822 if (flag)
1823 sprintf(fwrevision, "%d.%d%d (%s)",
1824 b1, b2, b3, (char *)str);
1825 else
1826 sprintf(fwrevision, "%d.%d%d", b1,
1827 b2, b3);
1828 } else {
1829 if (flag)
1830 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1831 b1, b2, b3, c,
1832 b4, (char *)str);
1833 else
1834 sprintf(fwrevision, "%d.%d%d%c%d",
1835 b1, b2, b3, c, b4);
1836 }
1837 } else {
1838 rev = vp->rev.smFwRev;
1839
1840 b1 = (rev & 0xff000000) >> 24;
1841 b2 = (rev & 0x00f00000) >> 20;
1842 b3 = (rev & 0x000f0000) >> 16;
1843 c = (rev & 0x0000ff00) >> 8;
1844 b4 = (rev & 0x000000ff);
1845
Roel Kluind44a6d22010-01-17 16:15:57 +01001846 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05001847 }
1848 return;
1849}