blob: e724048bf3902b8aec501492024c05ffeebb2472 [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>
dea31012005-04-17 16:05:31 -050034
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_hw.h"
37#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040039#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_disc.h"
41#include "lpfc_scsi.h"
42#include "lpfc.h"
43#include "lpfc_logmsg.h"
44#include "lpfc_crtn.h"
45#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050046#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050047#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050048
49#define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
50 * incapable of reporting */
51#define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
52#define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
53#define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
54#define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
55#define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
56#define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
57
58#define FOURBYTES 4
59
60
61static char *lpfc_release_version = LPFC_DRIVER_VERSION;
62
James Smarted957682007-06-17 19:56:37 -050063static void
64lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050065 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050066{
James Smarted957682007-06-17 19:56:37 -050067 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050068 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040069 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050070 "status = x%x\n",
71 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050072 }
James Smart9c2face2008-01-11 01:53:18 -050073 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
74 "0145 Ignoring unsolicted CT HBQ Size:%d "
75 "status = x%x\n",
76 size, piocbq->iocb.ulpStatus);
77}
78
79static void
80lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct lpfc_dmabuf *mp, uint32_t size)
82{
83 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -050084}
85
dea31012005-04-17 16:05:31 -050086void
James Smart2e0fef82007-06-17 19:56:36 -050087lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
88 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -050089{
James Smarted957682007-06-17 19:56:37 -050090 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -050091 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -050092 int i;
93 struct lpfc_iocbq *iocbq;
94 dma_addr_t paddr;
95 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -050096 struct list_head head;
97 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -050098
James Smartf1c3b0f2009-07-19 10:01:32 -040099 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
100
James Smart92d7f7b2007-06-17 19:56:38 -0500101 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
102 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
103 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
104 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500105 /* Not enough posted buffers; Try posting more buffers */
106 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500107 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400108 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500109 return;
110 }
111
112 /* If there are no BDEs associated with this IOCB,
113 * there is nothing to do.
114 */
115 if (icmd->ulpBdeCount == 0)
116 return;
117
James Smarted957682007-06-17 19:56:37 -0500118 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500119 INIT_LIST_HEAD(&head);
120 list_add_tail(&head, &piocbq->list);
121 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500122 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500123 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500124 continue;
James Smart9c2face2008-01-11 01:53:18 -0500125 bdeBuf = iocbq->context2;
126 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500127 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500128 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
129 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500130 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500131 bdeBuf = iocbq->context3;
132 iocbq->context3 = NULL;
133 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
134 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
135 size);
136 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500137 }
dea31012005-04-17 16:05:31 -0500138 }
James Smart9c2face2008-01-11 01:53:18 -0500139 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500140 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400141 INIT_LIST_HEAD(&head);
142 list_add_tail(&head, &piocbq->list);
143 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500144 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500145 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400146 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500147 for (i = 0; i < icmd->ulpBdeCount; i++) {
148 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
149 icmd->un.cont64[i].addrLow);
150 mp = lpfc_sli_ringpostbuf_get(phba, pring,
151 paddr);
152 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400153 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500154 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500155 }
James Smart495a7142008-06-14 22:52:59 -0400156 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500157 }
James Smartd7c255b2008-08-24 21:50:00 -0400158 list_del(&head);
dea31012005-04-17 16:05:31 -0500159 }
dea31012005-04-17 16:05:31 -0500160}
161
James Smart6669f9b2009-10-02 15:16:45 -0400162/**
163 * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort
164 * @phba: Pointer to HBA context object.
165 * @pring: Pointer to the driver internal I/O ring.
166 * @piocbq: Pointer to the IOCBQ.
167 *
168 * This function serves as the default handler for the sli4 unsolicited
169 * abort event. It shall be invoked when there is no application interface
170 * registered unsolicited abort handler. This handler does nothing but
171 * just simply releases the dma buffer used by the unsol abort event.
172 **/
173void
174lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
175 struct lpfc_sli_ring *pring,
176 struct lpfc_iocbq *piocbq)
177{
178 IOCB_t *icmd = &piocbq->iocb;
179 struct lpfc_dmabuf *bdeBuf;
180 uint32_t size;
181
182 /* Forward abort event to any process registered to receive ct event */
183 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
184
185 /* If there is no BDE associated with IOCB, there is nothing to do */
186 if (icmd->ulpBdeCount == 0)
187 return;
188 bdeBuf = piocbq->context2;
189 piocbq->context2 = NULL;
190 size = icmd->un.cont64[0].tus.f.bdeSize;
191 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
192 lpfc_in_buf_free(phba, bdeBuf);
193}
194
dea31012005-04-17 16:05:31 -0500195static void
James Smart2e0fef82007-06-17 19:56:36 -0500196lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500197{
198 struct lpfc_dmabuf *mlast, *next_mlast;
199
200 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
201 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
202 list_del(&mlast->list);
203 kfree(mlast);
204 }
205 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
206 kfree(mlist);
207 return;
208}
209
210static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500211lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500212 uint32_t size, int *entries)
213{
214 struct lpfc_dmabuf *mlist = NULL;
215 struct lpfc_dmabuf *mp;
216 int cnt, i = 0;
217
James Smart09372822008-01-11 01:52:54 -0500218 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500219 cnt = size > FCELSSIZE ? FCELSSIZE: size;
220
221 while (size) {
222 /* Allocate buffer for rsp payload */
223 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
224 if (!mp) {
225 if (mlist)
226 lpfc_free_ct_rsp(phba, mlist);
227 return NULL;
228 }
229
230 INIT_LIST_HEAD(&mp->list);
231
James Smart92d7f7b2007-06-17 19:56:38 -0500232 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
233 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500234 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
235 else
236 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
237
238 if (!mp->virt) {
239 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700240 if (mlist)
241 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500242 return NULL;
243 }
244
245 /* Queue it to a linked list */
246 if (!mlist)
247 mlist = mp;
248 else
249 list_add_tail(&mp->list, &mlist->list);
250
James Smart34b02dc2008-08-24 21:49:55 -0400251 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500252 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500253 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
254 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500255 bpl->tus.f.bdeSize = (uint16_t) cnt;
256 bpl->tus.w = le32_to_cpu(bpl->tus.w);
257 bpl++;
258
259 i++;
260 size -= cnt;
261 }
262
263 *entries = i;
264 return mlist;
265}
266
James Smart858c9f62007-06-17 19:56:39 -0500267int
268lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
269{
270 struct lpfc_dmabuf *buf_ptr;
271
James Smart51ef4c22007-08-02 11:10:31 -0400272 if (ctiocb->context_un.ndlp) {
273 lpfc_nlp_put(ctiocb->context_un.ndlp);
274 ctiocb->context_un.ndlp = NULL;
275 }
James Smart858c9f62007-06-17 19:56:39 -0500276 if (ctiocb->context1) {
277 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
278 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
279 kfree(buf_ptr);
280 ctiocb->context1 = NULL;
281 }
282 if (ctiocb->context2) {
283 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
284 ctiocb->context2 = NULL;
285 }
286
287 if (ctiocb->context3) {
288 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
289 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
290 kfree(buf_ptr);
291 ctiocb->context1 = NULL;
292 }
293 lpfc_sli_release_iocbq(phba, ctiocb);
294 return 0;
295}
296
dea31012005-04-17 16:05:31 -0500297static int
James Smart2e0fef82007-06-17 19:56:36 -0500298lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500299 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
300 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
301 struct lpfc_iocbq *),
302 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500303 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500304{
James Smart2e0fef82007-06-17 19:56:36 -0500305 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500306 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400307 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500308 int rc;
dea31012005-04-17 16:05:31 -0500309
310 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400311 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500312
313 if (geniocb == NULL)
314 return 1;
dea31012005-04-17 16:05:31 -0500315
316 icmd = &geniocb->iocb;
317 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
318 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
319 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400320 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea31012005-04-17 16:05:31 -0500321 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
322
323 if (usr_flg)
324 geniocb->context3 = NULL;
325 else
326 geniocb->context3 = (uint8_t *) bmp;
327
328 /* Save for completion so we can release these resources */
329 geniocb->context1 = (uint8_t *) inp;
330 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500331 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500332
333 /* Fill in payload, bp points to frame payload */
334 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
335
336 /* Fill in rest of iocb */
337 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
338 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
339 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
340 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
341
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500342 if (!tmo) {
343 /* FC spec states we need 3 * ratov for CT requests */
344 tmo = (3 * phba->fc_ratov);
345 }
dea31012005-04-17 16:05:31 -0500346 icmd->ulpTimeout = tmo;
347 icmd->ulpBdeCount = 1;
348 icmd->ulpLe = 1;
349 icmd->ulpClass = CLASS3;
350 icmd->ulpContext = ndlp->nlp_rpi;
351
James Smart92d7f7b2007-06-17 19:56:38 -0500352 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
353 /* For GEN_REQUEST64_CR, use the RPI */
354 icmd->ulpCt_h = 0;
355 icmd->ulpCt_l = 0;
356 }
357
dea31012005-04-17 16:05:31 -0500358 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400359 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
360 "0119 Issue GEN REQ IOCB to NPORT x%x "
361 "Data: x%x x%x\n",
362 ndlp->nlp_DID, icmd->ulpIoTag,
363 vport->port_state);
dea31012005-04-17 16:05:31 -0500364 geniocb->iocb_cmpl = cmpl;
365 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500366 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400368 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500371 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500372 return 1;
373 }
dea31012005-04-17 16:05:31 -0500374
375 return 0;
376}
377
378static int
James Smart2e0fef82007-06-17 19:56:36 -0500379lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500380 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
381 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
382 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500383 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500384{
James Smart2e0fef82007-06-17 19:56:36 -0500385 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500386 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
387 struct lpfc_dmabuf *outmp;
388 int cnt = 0, status;
389 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
390 CommandResponse.bits.CmdRsp;
391
392 bpl++; /* Skip past ct request */
393
394 /* Put buffer(s) for ct rsp in bpl */
395 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
396 if (!outmp)
397 return -ENOMEM;
398
James Smart2e0fef82007-06-17 19:56:36 -0500399 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart92d7f7b2007-06-17 19:56:38 -0500400 cnt+1, 0, retry);
dea31012005-04-17 16:05:31 -0500401 if (status) {
402 lpfc_free_ct_rsp(phba, outmp);
403 return -ENOMEM;
404 }
405 return 0;
406}
407
James Smart549e55c2007-08-02 11:09:51 -0400408struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500409lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500410 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400411 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500412
James Smart549e55c2007-08-02 11:09:51 -0400413 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500414 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400415 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
416 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500417 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400418 }
James Smart92d7f7b2007-06-17 19:56:38 -0500419 }
James Smart549e55c2007-08-02 11:09:51 -0400420 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500421 return NULL;
422}
423
dea31012005-04-17 16:05:31 -0500424static int
James Smart2e0fef82007-06-17 19:56:36 -0500425lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500426{
James Smart2e0fef82007-06-17 19:56:36 -0500427 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500428 struct lpfc_sli_ct_request *Response =
429 (struct lpfc_sli_ct_request *) mp->virt;
430 struct lpfc_nodelist *ndlp = NULL;
431 struct lpfc_dmabuf *mlast, *next_mp;
432 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500433 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500434 int Cnt;
435 struct list_head head;
436
James Smart2e0fef82007-06-17 19:56:36 -0500437 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500438 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500439 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500440
dea31012005-04-17 16:05:31 -0500441
442 list_add_tail(&head, &mp->list);
443 list_for_each_entry_safe(mp, next_mp, &head, list) {
444 mlast = mp;
445
James Smart7054a602007-04-25 09:52:34 -0400446 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
447
dea31012005-04-17 16:05:31 -0500448 Size -= Cnt;
449
James Smart1dcb58e2007-04-25 09:51:30 -0400450 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500451 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400452 } else
dea31012005-04-17 16:05:31 -0500453 Cnt -= 16; /* subtract length of CT header */
454
455 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400456 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500457 /* Get next DID from NameServer List */
458 CTentry = *ctptr++;
459 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500460
dea31012005-04-17 16:05:31 -0500461 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500462
463 /*
464 * Check for rscn processing or not
465 * To conserve rpi's, filter out addresses for other
466 * vports on the same physical HBAs.
467 */
468 if ((Did != vport->fc_myDID) &&
469 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400470 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500471 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart98c9ea52007-10-27 13:37:33 -0400472 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
James Smart3de2a652007-08-02 11:09:59 -0400473 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500474 ndlp = lpfc_setup_disc_node(vport, Did);
James Smart58da1ff2008-04-07 10:15:56 -0400475 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500476 lpfc_debugfs_disc_trc(vport,
477 LPFC_DISC_TRC_CT,
478 "Parse GID_FTrsp: "
479 "did:x%x flg:x%x x%x",
480 Did, ndlp->nlp_flag,
481 vport->fc_flag);
482
James Smarte8b62012007-08-02 11:10:09 -0400483 lpfc_printf_vlog(vport,
484 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500485 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400486 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500487 "x%x NameServer Rsp"
488 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400489 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500490 vport->fc_flag,
491 vport->fc_rscn_id_cnt);
492 } else {
James Smart858c9f62007-06-17 19:56:39 -0500493 lpfc_debugfs_disc_trc(vport,
494 LPFC_DISC_TRC_CT,
495 "Skip1 GID_FTrsp: "
496 "did:x%x flg:x%x cnt:%d",
497 Did, vport->fc_flag,
498 vport->fc_rscn_id_cnt);
499
James Smarte8b62012007-08-02 11:10:09 -0400500 lpfc_printf_vlog(vport,
501 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500502 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400503 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500504 "NameServer Rsp Data: "
505 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400506 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500507 vport->fc_rscn_id_cnt);
508 }
509
510 } else {
511 if (!(vport->fc_flag & FC_RSCN_MODE) ||
512 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500513 lpfc_debugfs_disc_trc(vport,
514 LPFC_DISC_TRC_CT,
515 "Query GID_FTrsp: "
516 "did:x%x flg:x%x cnt:%d",
517 Did, vport->fc_flag,
518 vport->fc_rscn_id_cnt);
519
James Smart0ff10d42008-01-11 01:52:36 -0500520 /* This NPortID was previously
521 * a FCP target, * Don't even
522 * bother to send GFF_ID.
523 */
524 ndlp = lpfc_findnode_did(vport,
525 Did);
James Smarte47c9092008-02-08 18:49:26 -0500526 if (ndlp &&
527 NLP_CHK_NODE_ACT(ndlp)
528 && (ndlp->nlp_type &
529 NLP_FCP_TARGET))
James Smart0ff10d42008-01-11 01:52:36 -0500530 lpfc_setup_disc_node
531 (vport, Did);
532 else if (lpfc_ns_cmd(vport,
James Smart92d7f7b2007-06-17 19:56:38 -0500533 SLI_CTNS_GFF_ID,
534 0, Did) == 0)
535 vport->num_disc_nodes++;
536 }
537 else {
James Smart858c9f62007-06-17 19:56:39 -0500538 lpfc_debugfs_disc_trc(vport,
539 LPFC_DISC_TRC_CT,
540 "Skip2 GID_FTrsp: "
541 "did:x%x flg:x%x cnt:%d",
542 Did, vport->fc_flag,
543 vport->fc_rscn_id_cnt);
544
James Smarte8b62012007-08-02 11:10:09 -0400545 lpfc_printf_vlog(vport,
546 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500547 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400548 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500549 "NameServer Rsp Data: "
550 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400551 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500552 vport->fc_rscn_id_cnt);
553 }
554 }
dea31012005-04-17 16:05:31 -0500555 }
dea31012005-04-17 16:05:31 -0500556 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
557 goto nsout1;
558 Cnt -= sizeof (uint32_t);
559 }
560 ctptr = NULL;
561
562 }
563
564nsout1:
565 list_del(&head);
dea31012005-04-17 16:05:31 -0500566 return 0;
567}
568
dea31012005-04-17 16:05:31 -0500569static void
James Smart2e0fef82007-06-17 19:56:36 -0500570lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
571 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500572{
James Smart2e0fef82007-06-17 19:56:36 -0500573 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500574 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500575 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500576 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500577 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500578 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400579 struct lpfc_nodelist *ndlp;
James Smart58da1ff2008-04-07 10:15:56 -0400580 int rc;
dea31012005-04-17 16:05:31 -0500581
James Smart51ef4c22007-08-02 11:10:31 -0400582 /* First save ndlp, before we overwrite it */
583 ndlp = cmdiocb->context_un.ndlp;
584
dea31012005-04-17 16:05:31 -0500585 /* we pass cmdiocb to state machine which needs rspiocb as well */
586 cmdiocb->context_un.rsp_iocb = rspiocb;
587
dea31012005-04-17 16:05:31 -0500588 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
589 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500590 irsp = &rspiocb->iocb;
591
592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
593 "GID_FT cmpl: status:x%x/x%x rtry:%d",
594 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500595
James Smart92d7f7b2007-06-17 19:56:38 -0500596 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500597 if (vport->load_flag & FC_UNLOADING) {
598 if (vport->fc_flag & FC_RSCN_MODE)
599 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500600 goto out;
James Smarteada2722008-12-04 22:39:13 -0500601 }
James Smart92d7f7b2007-06-17 19:56:38 -0500602
James Smart58da1ff2008-04-07 10:15:56 -0400603 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400604 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
605 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500606 if (vport->fc_flag & FC_RSCN_MODE)
607 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500608 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
609 goto out;
610 }
James Smart58da1ff2008-04-07 10:15:56 -0400611 if (lpfc_error_lost_link(irsp)) {
612 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
613 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500614 if (vport->fc_flag & FC_RSCN_MODE)
615 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400616 goto out;
617 }
James Smart858c9f62007-06-17 19:56:39 -0500618 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500619 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500620 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400621 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
622 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500623 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500624
James Smart58da1ff2008-04-07 10:15:56 -0400625 /* CT command is being retried */
626 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smart92d7f7b2007-06-17 19:56:38 -0500627 vport->fc_ns_retry, 0);
James Smart58da1ff2008-04-07 10:15:56 -0400628 if (rc == 0)
629 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500630 }
James Smarteada2722008-12-04 22:39:13 -0500631 if (vport->fc_flag & FC_RSCN_MODE)
632 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500633 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400634 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
635 "0257 GID_FT Query error: 0x%x 0x%x\n",
636 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500637 } else {
638 /* Good status, continue checking */
639 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
640 if (CTrsp->CommandResponse.bits.CmdRsp ==
641 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400642 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
643 "0208 NameServer Rsp Data: x%x\n",
644 vport->fc_flag);
James Smart2e0fef82007-06-17 19:56:36 -0500645 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500646 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
647 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
648 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
649 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400650 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
651 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400652 lpfc_printf_vlog(vport, KERN_INFO,
653 LOG_DISCOVERY,
654 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400655 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400656 CTrsp->CommandResponse.bits.CmdRsp,
657 (uint32_t) CTrsp->ReasonCode,
658 (uint32_t) CTrsp->Explanation,
659 vport->fc_flag);
660
661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
662 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
663 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
664 (uint32_t) CTrsp->ReasonCode,
665 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400666 } else {
667 lpfc_printf_vlog(vport, KERN_INFO,
668 LOG_DISCOVERY,
669 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500670 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500671 CTrsp->CommandResponse.bits.CmdRsp,
672 (uint32_t) CTrsp->ReasonCode,
673 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500674 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500675
James Smarta58cbd52007-08-02 11:09:43 -0400676 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500677 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
678 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
679 (uint32_t) CTrsp->ReasonCode,
680 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400681 }
682
James Smart858c9f62007-06-17 19:56:39 -0500683
dea31012005-04-17 16:05:31 -0500684 } else {
685 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400686 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
687 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500688 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500689 CTrsp->CommandResponse.bits.CmdRsp,
690 (uint32_t) CTrsp->ReasonCode,
691 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500692 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500693
694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
695 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
696 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
697 (uint32_t) CTrsp->ReasonCode,
698 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500699 }
700 }
701 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500702 if (vport->num_disc_nodes == 0) {
703 /*
704 * The driver has cycled through all Nports in the RSCN payload.
705 * Complete the handling by cleaning up and marking the
706 * current driver state.
707 */
708 if (vport->port_state >= LPFC_DISC_AUTH) {
709 if (vport->fc_flag & FC_RSCN_MODE) {
710 lpfc_els_flush_rscn(vport);
711 spin_lock_irq(shost->host_lock);
712 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
713 spin_unlock_irq(shost->host_lock);
714 }
715 else
716 lpfc_els_flush_rscn(vport);
717 }
718
719 lpfc_disc_start(vport);
720 }
dea31012005-04-17 16:05:31 -0500721out:
James Smart51ef4c22007-08-02 11:10:31 -0400722 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500723 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500724 return;
725}
726
James Smart311464e2007-08-02 11:10:37 -0400727static void
James Smart92d7f7b2007-06-17 19:56:38 -0500728lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
729 struct lpfc_iocbq *rspiocb)
730{
731 struct lpfc_vport *vport = cmdiocb->vport;
732 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
733 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500734 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
735 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
736 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500737 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500738 uint8_t fbits;
739 struct lpfc_nodelist *ndlp;
740
741 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
742 did = be32_to_cpu(did);
743
James Smart858c9f62007-06-17 19:56:39 -0500744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
745 "GFF_ID cmpl: status:x%x/x%x did:x%x",
746 irsp->ulpStatus, irsp->un.ulpWord[4], did);
747
James Smart92d7f7b2007-06-17 19:56:38 -0500748 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
749 /* Good status, continue checking */
750 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
751 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
752
753 if (CTrsp->CommandResponse.bits.CmdRsp ==
754 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
755 if ((fbits & FC4_FEATURE_INIT) &&
756 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400757 lpfc_printf_vlog(vport, KERN_INFO,
758 LOG_DISCOVERY,
759 "0270 Skip x%x GFF "
760 "NameServer Rsp Data: (init) "
761 "x%x x%x\n", did, fbits,
762 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500763 goto out;
764 }
765 }
766 }
James Smart858c9f62007-06-17 19:56:39 -0500767 else {
James Smart0ff10d42008-01-11 01:52:36 -0500768 /* Check for retry */
769 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
770 retry = 1;
771 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
772 switch (irsp->un.ulpWord[4]) {
773 case IOERR_NO_RESOURCES:
774 /* We don't increment the retry
775 * count for this case.
776 */
777 break;
778 case IOERR_LINK_DOWN:
779 case IOERR_SLI_ABORTED:
780 case IOERR_SLI_DOWN:
781 retry = 0;
782 break;
783 default:
784 cmdiocb->retry++;
785 }
786 }
787 else
788 cmdiocb->retry++;
789
790 if (retry) {
791 /* CT command is being retried */
792 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
793 cmdiocb->retry, did);
794 if (rc == 0) {
795 /* success */
796 lpfc_ct_free_iocb(phba, cmdiocb);
797 return;
798 }
799 }
800 }
James Smarte8b62012007-08-02 11:10:09 -0400801 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
802 "0267 NameServer GFF Rsp "
803 "x%x Error (%d %d) Data: x%x x%x\n",
804 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500805 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500806 }
807
James Smart92d7f7b2007-06-17 19:56:38 -0500808 /* This is a target port, unregistered port, or the GFF_ID failed */
809 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400810 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
812 "0242 Process x%x GFF "
813 "NameServer Rsp Data: x%x x%x x%x\n",
814 did, ndlp->nlp_flag, vport->fc_flag,
815 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500816 } else {
James Smarte8b62012007-08-02 11:10:09 -0400817 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
818 "0243 Skip x%x GFF "
819 "NameServer Rsp Data: x%x x%x\n", did,
820 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500821 }
822out:
823 /* Link up / RSCN discovery */
824 if (vport->num_disc_nodes)
825 vport->num_disc_nodes--;
826 if (vport->num_disc_nodes == 0) {
827 /*
828 * The driver has cycled through all Nports in the RSCN payload.
829 * Complete the handling by cleaning up and marking the
830 * current driver state.
831 */
832 if (vport->port_state >= LPFC_DISC_AUTH) {
833 if (vport->fc_flag & FC_RSCN_MODE) {
834 lpfc_els_flush_rscn(vport);
835 spin_lock_irq(shost->host_lock);
836 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
837 spin_unlock_irq(shost->host_lock);
838 }
839 else
840 lpfc_els_flush_rscn(vport);
841 }
842 lpfc_disc_start(vport);
843 }
James Smart858c9f62007-06-17 19:56:39 -0500844 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500845 return;
846}
847
848
dea31012005-04-17 16:05:31 -0500849static void
James Smart7ee5d432007-10-27 13:37:17 -0400850lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
851 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500852{
James Smart92d7f7b2007-06-17 19:56:38 -0500853 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500854 struct lpfc_dmabuf *inp;
855 struct lpfc_dmabuf *outp;
856 IOCB_t *irsp;
857 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400858 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500859 int cmdcode, rc;
860 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500861 uint32_t latt;
dea31012005-04-17 16:05:31 -0500862
James Smart51ef4c22007-08-02 11:10:31 -0400863 /* First save ndlp, before we overwrite it */
864 ndlp = cmdiocb->context_un.ndlp;
865
dea31012005-04-17 16:05:31 -0500866 /* we pass cmdiocb to state machine which needs rspiocb as well */
867 cmdiocb->context_un.rsp_iocb = rspiocb;
868
869 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
870 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500871 irsp = &rspiocb->iocb;
872
James Smart92d7f7b2007-06-17 19:56:38 -0500873 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
874 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500875 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
876
James Smart858c9f62007-06-17 19:56:39 -0500877 latt = lpfc_els_chk_latt(vport);
878
879 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400880 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400881 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400882 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
883 latt, irsp->ulpStatus,
884 CTrsp->CommandResponse.bits.CmdRsp,
885 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500886
James Smart858c9f62007-06-17 19:56:39 -0500887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
888 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
889 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
890
James Smart92d7f7b2007-06-17 19:56:38 -0500891 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400892 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
893 "0268 NS cmd %x Error (%d %d)\n",
894 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500895
James Smart92d7f7b2007-06-17 19:56:38 -0500896 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
897 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
898 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
899 goto out;
900
901 retry = cmdiocb->retry;
902 if (retry >= LPFC_MAX_NS_RETRY)
903 goto out;
904
905 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400906 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -0400907 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500908 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
909 if (rc == 0)
910 goto out;
911 }
912
913out:
James Smart51ef4c22007-08-02 11:10:31 -0400914 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500915 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500916 return;
917}
918
919static void
James Smart7ee5d432007-10-27 13:37:17 -0400920lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
921 struct lpfc_iocbq *rspiocb)
922{
923 IOCB_t *irsp = &rspiocb->iocb;
924 struct lpfc_vport *vport = cmdiocb->vport;
925
James Smart98c9ea52007-10-27 13:37:33 -0400926 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
927 struct lpfc_dmabuf *outp;
928 struct lpfc_sli_ct_request *CTrsp;
929
930 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
931 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
932 if (CTrsp->CommandResponse.bits.CmdRsp ==
933 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
934 vport->ct_flags |= FC_CT_RFT_ID;
935 }
James Smart7ee5d432007-10-27 13:37:17 -0400936 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
937 return;
938}
939
940static void
James Smart2e0fef82007-06-17 19:56:36 -0500941lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
942 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500943{
James Smart7ee5d432007-10-27 13:37:17 -0400944 IOCB_t *irsp = &rspiocb->iocb;
945 struct lpfc_vport *vport = cmdiocb->vport;
946
James Smart98c9ea52007-10-27 13:37:33 -0400947 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
948 struct lpfc_dmabuf *outp;
949 struct lpfc_sli_ct_request *CTrsp;
950
951 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
952 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
953 if (CTrsp->CommandResponse.bits.CmdRsp ==
954 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
955 vport->ct_flags |= FC_CT_RNN_ID;
956 }
James Smart7ee5d432007-10-27 13:37:17 -0400957 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500958 return;
959}
960
961static void
James Smart92d7f7b2007-06-17 19:56:38 -0500962lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
963 struct lpfc_iocbq *rspiocb)
964{
James Smart7ee5d432007-10-27 13:37:17 -0400965 IOCB_t *irsp = &rspiocb->iocb;
966 struct lpfc_vport *vport = cmdiocb->vport;
967
James Smart98c9ea52007-10-27 13:37:33 -0400968 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
969 struct lpfc_dmabuf *outp;
970 struct lpfc_sli_ct_request *CTrsp;
971
972 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
973 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
974 if (CTrsp->CommandResponse.bits.CmdRsp ==
975 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
976 vport->ct_flags |= FC_CT_RSPN_ID;
977 }
James Smart7ee5d432007-10-27 13:37:17 -0400978 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500979 return;
980}
981
982static void
James Smart2e0fef82007-06-17 19:56:36 -0500983lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
984 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500985{
James Smart7ee5d432007-10-27 13:37:17 -0400986 IOCB_t *irsp = &rspiocb->iocb;
987 struct lpfc_vport *vport = cmdiocb->vport;
988
James Smart98c9ea52007-10-27 13:37:33 -0400989 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
990 struct lpfc_dmabuf *outp;
991 struct lpfc_sli_ct_request *CTrsp;
992
993 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
994 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
995 if (CTrsp->CommandResponse.bits.CmdRsp ==
996 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
997 vport->ct_flags |= FC_CT_RSNN_NN;
998 }
James Smart7ee5d432007-10-27 13:37:17 -0400999 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1000 return;
1001}
1002
1003static void
1004lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1005 struct lpfc_iocbq *rspiocb)
1006{
1007 struct lpfc_vport *vport = cmdiocb->vport;
1008
1009 /* even if it fails we will act as though it succeeded. */
1010 vport->ct_flags = 0;
1011 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001012 return;
1013}
1014
James Smart2fb9bd82006-12-02 13:33:57 -05001015static void
James Smart92d7f7b2007-06-17 19:56:38 -05001016lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1017 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001018{
James Smart92d7f7b2007-06-17 19:56:38 -05001019 IOCB_t *irsp = &rspiocb->iocb;
1020 struct lpfc_vport *vport = cmdiocb->vport;
1021
James Smart98c9ea52007-10-27 13:37:33 -04001022 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1023 struct lpfc_dmabuf *outp;
1024 struct lpfc_sli_ct_request *CTrsp;
1025
1026 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1027 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1028 if (CTrsp->CommandResponse.bits.CmdRsp ==
1029 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1030 vport->ct_flags |= FC_CT_RFF_ID;
1031 }
James Smart7ee5d432007-10-27 13:37:17 -04001032 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001033 return;
1034}
1035
James Smart495a7142008-06-14 22:52:59 -04001036int
James Smart92d7f7b2007-06-17 19:56:38 -05001037lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1038 size_t size)
1039{
1040 int n;
1041 uint8_t *wwn = vport->phba->wwpn;
1042
1043 n = snprintf(symbol, size,
1044 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1045 wwn[0], wwn[1], wwn[2], wwn[3],
1046 wwn[4], wwn[5], wwn[6], wwn[7]);
1047
1048 if (vport->port_type == LPFC_PHYSICAL_PORT)
1049 return n;
1050
1051 if (n < size)
1052 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1053
James Smarteada2722008-12-04 22:39:13 -05001054 if (n < size &&
1055 strlen(vport->fc_vport->symbolic_name))
1056 n += snprintf(symbol + n, size - n, " VName-%s",
1057 vport->fc_vport->symbolic_name);
James Smart92d7f7b2007-06-17 19:56:38 -05001058 return n;
1059}
1060
1061int
1062lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1063 size_t size)
dea31012005-04-17 16:05:31 -05001064{
1065 char fwrev[16];
James Smart92d7f7b2007-06-17 19:56:38 -05001066 int n;
dea31012005-04-17 16:05:31 -05001067
James Smart92d7f7b2007-06-17 19:56:38 -05001068 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001069
James Smart92d7f7b2007-06-17 19:56:38 -05001070 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1071 vport->phba->ModelName, fwrev, lpfc_release_version);
1072 return n;
dea31012005-04-17 16:05:31 -05001073}
1074
1075/*
1076 * lpfc_ns_cmd
1077 * Description:
1078 * Issue Cmd to NameServer
1079 * SLI_CTNS_GID_FT
1080 * LI_CTNS_RFT_ID
1081 */
1082int
James Smart92d7f7b2007-06-17 19:56:38 -05001083lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1084 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001085{
James Smart92d7f7b2007-06-17 19:56:38 -05001086 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001087 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001088 struct lpfc_dmabuf *mp, *bmp;
1089 struct lpfc_sli_ct_request *CtReq;
1090 struct ulp_bde64 *bpl;
1091 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1092 struct lpfc_iocbq *) = NULL;
1093 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001094 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001095 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001096
1097 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001098 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1099 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001100 rc=1;
1101 goto ns_cmd_exit;
1102 }
dea31012005-04-17 16:05:31 -05001103
1104 /* fill in BDEs for command */
1105 /* Allocate buffer for command payload */
1106 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001107 if (!mp) {
1108 rc=2;
dea31012005-04-17 16:05:31 -05001109 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001110 }
dea31012005-04-17 16:05:31 -05001111
1112 INIT_LIST_HEAD(&mp->list);
1113 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001114 if (!mp->virt) {
1115 rc=3;
dea31012005-04-17 16:05:31 -05001116 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001117 }
dea31012005-04-17 16:05:31 -05001118
1119 /* Allocate buffer for Buffer ptr list */
1120 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001121 if (!bmp) {
1122 rc=4;
dea31012005-04-17 16:05:31 -05001123 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001124 }
dea31012005-04-17 16:05:31 -05001125
1126 INIT_LIST_HEAD(&bmp->list);
1127 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001128 if (!bmp->virt) {
1129 rc=5;
dea31012005-04-17 16:05:31 -05001130 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001131 }
dea31012005-04-17 16:05:31 -05001132
1133 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001134 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1135 "0236 NameServer Req Data: x%x x%x x%x\n",
1136 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001137
1138 bpl = (struct ulp_bde64 *) bmp->virt;
1139 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001140 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1141 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001142 bpl->tus.f.bdeFlags = 0;
1143 if (cmdcode == SLI_CTNS_GID_FT)
1144 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001145 else if (cmdcode == SLI_CTNS_GFF_ID)
1146 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001147 else if (cmdcode == SLI_CTNS_RFT_ID)
1148 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1149 else if (cmdcode == SLI_CTNS_RNN_ID)
1150 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001151 else if (cmdcode == SLI_CTNS_RSPN_ID)
1152 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001153 else if (cmdcode == SLI_CTNS_RSNN_NN)
1154 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001155 else if (cmdcode == SLI_CTNS_DA_ID)
1156 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001157 else if (cmdcode == SLI_CTNS_RFF_ID)
1158 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001159 else
1160 bpl->tus.f.bdeSize = 0;
1161 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1162
1163 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1164 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1165 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1166 CtReq->RevisionId.bits.InId = 0;
1167 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1168 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1169 CtReq->CommandResponse.bits.Size = 0;
1170 switch (cmdcode) {
1171 case SLI_CTNS_GID_FT:
1172 CtReq->CommandResponse.bits.CmdRsp =
1173 be16_to_cpu(SLI_CTNS_GID_FT);
1174 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001175 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001176 vport->port_state = LPFC_NS_QRY;
1177 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001178 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1179 rsp_size = FC_MAX_NS_RSP;
1180 break;
1181
James Smart92d7f7b2007-06-17 19:56:38 -05001182 case SLI_CTNS_GFF_ID:
1183 CtReq->CommandResponse.bits.CmdRsp =
1184 be16_to_cpu(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001185 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001186 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1187 break;
1188
dea31012005-04-17 16:05:31 -05001189 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001190 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001191 CtReq->CommandResponse.bits.CmdRsp =
1192 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001193 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001194 CtReq->un.rft.fcpReg = 1;
1195 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1196 break;
1197
1198 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001199 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001200 CtReq->CommandResponse.bits.CmdRsp =
1201 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001202 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001203 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001204 sizeof (struct lpfc_name));
1205 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1206 break;
1207
James Smart92d7f7b2007-06-17 19:56:38 -05001208 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001209 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001210 CtReq->CommandResponse.bits.CmdRsp =
1211 be16_to_cpu(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001212 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001213 size = sizeof(CtReq->un.rspn.symbname);
1214 CtReq->un.rspn.len =
1215 lpfc_vport_symbolic_port_name(vport,
1216 CtReq->un.rspn.symbname, size);
1217 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1218 break;
dea31012005-04-17 16:05:31 -05001219 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001220 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001221 CtReq->CommandResponse.bits.CmdRsp =
1222 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001223 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001224 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001225 size = sizeof(CtReq->un.rsnn.symbname);
1226 CtReq->un.rsnn.len =
1227 lpfc_vport_symbolic_node_name(vport,
1228 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001229 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1230 break;
James Smart7ee5d432007-10-27 13:37:17 -04001231 case SLI_CTNS_DA_ID:
1232 /* Implement DA_ID Nameserver request */
1233 CtReq->CommandResponse.bits.CmdRsp =
1234 be16_to_cpu(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001235 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001236 cmpl = lpfc_cmpl_ct_cmd_da_id;
1237 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001238 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001239 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001240 CtReq->CommandResponse.bits.CmdRsp =
1241 be16_to_cpu(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001242 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001243 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1244 CtReq->un.rff.type_code = FC_FCP_DATA;
1245 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1246 break;
dea31012005-04-17 16:05:31 -05001247 }
James Smarte47c9092008-02-08 18:49:26 -05001248 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1249 * to hold ndlp reference for the corresponding callback function.
1250 */
James Smart858c9f62007-06-17 19:56:39 -05001251 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001252 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001253 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1254 "Issue CT cmd: cmd:x%x did:x%x",
1255 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001256 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001257 }
James Smart858c9f62007-06-17 19:56:39 -05001258 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001259
1260 /* Decrement ndlp reference count to release ndlp reference held
1261 * for the failed command's callback function.
1262 */
James Smart51ef4c22007-08-02 11:10:31 -04001263 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001264
dea31012005-04-17 16:05:31 -05001265 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1266ns_cmd_free_bmp:
1267 kfree(bmp);
1268ns_cmd_free_mpvirt:
1269 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1270ns_cmd_free_mp:
1271 kfree(mp);
1272ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001273 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1274 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1275 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001276 return 1;
1277}
1278
1279static void
James Smart2e0fef82007-06-17 19:56:36 -05001280lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1281 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001282{
dea31012005-04-17 16:05:31 -05001283 struct lpfc_dmabuf *inp = cmdiocb->context1;
1284 struct lpfc_dmabuf *outp = cmdiocb->context2;
1285 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1286 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1287 struct lpfc_nodelist *ndlp;
1288 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1289 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001290 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001291 IOCB_t *irsp = &rspiocb->iocb;
1292 uint32_t latt;
1293
1294 latt = lpfc_els_chk_latt(vport);
1295
1296 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1297 "FDMI cmpl: status:x%x/x%x latt:%d",
1298 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1299
1300 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001301 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1302 "0229 FDMI cmd %04x failed, latt = %d "
1303 "ulpStatus: x%x, rid x%x\n",
1304 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1305 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001306 lpfc_ct_free_iocb(phba, cmdiocb);
1307 return;
1308 }
dea31012005-04-17 16:05:31 -05001309
James Smart2e0fef82007-06-17 19:56:36 -05001310 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001311 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1312 goto fail_out;
1313
dea31012005-04-17 16:05:31 -05001314 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1315 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001316 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1317 "0220 FDMI rsp failed Data: x%x\n",
1318 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001319 }
1320
1321 switch (be16_to_cpu(fdmi_cmd)) {
1322 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001323 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001324 break;
1325
1326 case SLI_MGMT_RPA:
1327 break;
1328
1329 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001330 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001331 break;
1332
1333 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001334 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001335 break;
1336 }
James Smarte47c9092008-02-08 18:49:26 -05001337
1338fail_out:
James Smart858c9f62007-06-17 19:56:39 -05001339 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001340 return;
1341}
James Smart2e0fef82007-06-17 19:56:36 -05001342
dea31012005-04-17 16:05:31 -05001343int
James Smart2e0fef82007-06-17 19:56:36 -05001344lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001345{
James Smart2e0fef82007-06-17 19:56:36 -05001346 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001347 struct lpfc_dmabuf *mp, *bmp;
1348 struct lpfc_sli_ct_request *CtReq;
1349 struct ulp_bde64 *bpl;
1350 uint32_t size;
1351 REG_HBA *rh;
1352 PORT_ENTRY *pe;
1353 REG_PORT_ATTRIBUTE *pab;
1354 ATTRIBUTE_BLOCK *ab;
1355 ATTRIBUTE_ENTRY *ae;
1356 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1357 struct lpfc_iocbq *);
1358
1359
1360 /* fill in BDEs for command */
1361 /* Allocate buffer for command payload */
1362 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1363 if (!mp)
1364 goto fdmi_cmd_exit;
1365
1366 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1367 if (!mp->virt)
1368 goto fdmi_cmd_free_mp;
1369
1370 /* Allocate buffer for Buffer ptr list */
1371 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1372 if (!bmp)
1373 goto fdmi_cmd_free_mpvirt;
1374
1375 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1376 if (!bmp->virt)
1377 goto fdmi_cmd_free_bmp;
1378
1379 INIT_LIST_HEAD(&mp->list);
1380 INIT_LIST_HEAD(&bmp->list);
1381
1382 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001383 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1384 "0218 FDMI Request Data: x%x x%x x%x\n",
1385 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001386 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1387
1388 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1389 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1390 CtReq->RevisionId.bits.InId = 0;
1391
1392 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1393 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1394 size = 0;
1395
1396 switch (cmdcode) {
1397 case SLI_MGMT_RHBA:
1398 {
1399 lpfc_vpd_t *vp = &phba->vpd;
1400 uint32_t i, j, incr;
1401 int len;
1402
1403 CtReq->CommandResponse.bits.CmdRsp =
1404 be16_to_cpu(SLI_MGMT_RHBA);
1405 CtReq->CommandResponse.bits.Size = 0;
1406 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001407 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001408 sizeof (struct lpfc_name));
1409 /* One entry (port) per adapter */
1410 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001411 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001412 sizeof (struct lpfc_name));
1413
1414 /* point to the HBA attribute block */
1415 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1416 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1417 ab->EntryCnt = 0;
1418
1419 /* Point to the beginning of the first HBA attribute
1420 entry */
1421 /* #1 HBA attribute entry */
1422 size += FOURBYTES;
1423 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1424 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1425 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1426 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001427 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001428 sizeof (struct lpfc_name));
1429 ab->EntryCnt++;
1430 size += FOURBYTES + sizeof (struct lpfc_name);
1431
1432 /* #2 HBA attribute entry */
1433 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1434 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1435 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1436 len = strlen(ae->un.Manufacturer);
1437 len += (len & 3) ? (4 - (len & 3)) : 4;
1438 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1439 ab->EntryCnt++;
1440 size += FOURBYTES + len;
1441
1442 /* #3 HBA attribute entry */
1443 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1444 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1445 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1446 len = strlen(ae->un.SerialNumber);
1447 len += (len & 3) ? (4 - (len & 3)) : 4;
1448 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1449 ab->EntryCnt++;
1450 size += FOURBYTES + len;
1451
1452 /* #4 HBA attribute entry */
1453 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1454 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1455 strcpy(ae->un.Model, phba->ModelName);
1456 len = strlen(ae->un.Model);
1457 len += (len & 3) ? (4 - (len & 3)) : 4;
1458 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1459 ab->EntryCnt++;
1460 size += FOURBYTES + len;
1461
1462 /* #5 HBA attribute entry */
1463 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1464 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1465 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1466 len = strlen(ae->un.ModelDescription);
1467 len += (len & 3) ? (4 - (len & 3)) : 4;
1468 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1469 ab->EntryCnt++;
1470 size += FOURBYTES + len;
1471
1472 /* #6 HBA attribute entry */
1473 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1474 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1475 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1476 /* Convert JEDEC ID to ascii for hardware version */
1477 incr = vp->rev.biuRev;
1478 for (i = 0; i < 8; i++) {
1479 j = (incr & 0xf);
1480 if (j <= 9)
1481 ae->un.HardwareVersion[7 - i] =
1482 (char)((uint8_t) 0x30 +
1483 (uint8_t) j);
1484 else
1485 ae->un.HardwareVersion[7 - i] =
1486 (char)((uint8_t) 0x61 +
1487 (uint8_t) (j - 10));
1488 incr = (incr >> 4);
1489 }
1490 ab->EntryCnt++;
1491 size += FOURBYTES + 8;
1492
1493 /* #7 HBA attribute entry */
1494 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1495 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1496 strcpy(ae->un.DriverVersion, lpfc_release_version);
1497 len = strlen(ae->un.DriverVersion);
1498 len += (len & 3) ? (4 - (len & 3)) : 4;
1499 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1500 ab->EntryCnt++;
1501 size += FOURBYTES + len;
1502
1503 /* #8 HBA attribute entry */
1504 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1505 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1506 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1507 len = strlen(ae->un.OptionROMVersion);
1508 len += (len & 3) ? (4 - (len & 3)) : 4;
1509 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1510 ab->EntryCnt++;
1511 size += FOURBYTES + len;
1512
1513 /* #9 HBA attribute entry */
1514 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1515 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1516 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1517 1);
1518 len = strlen(ae->un.FirmwareVersion);
1519 len += (len & 3) ? (4 - (len & 3)) : 4;
1520 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1521 ab->EntryCnt++;
1522 size += FOURBYTES + len;
1523
1524 /* #10 HBA attribute entry */
1525 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1526 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1527 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001528 init_utsname()->sysname,
1529 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001530 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001531 len = strlen(ae->un.OsNameVersion);
1532 len += (len & 3) ? (4 - (len & 3)) : 4;
1533 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1534 ab->EntryCnt++;
1535 size += FOURBYTES + len;
1536
1537 /* #11 HBA attribute entry */
1538 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1539 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1540 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1541 ae->un.MaxCTPayloadLen = (65 * 4096);
1542 ab->EntryCnt++;
1543 size += FOURBYTES + 4;
1544
1545 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1546 /* Total size */
1547 size = GID_REQUEST_SZ - 4 + size;
1548 }
1549 break;
1550
1551 case SLI_MGMT_RPA:
1552 {
1553 lpfc_vpd_t *vp;
1554 struct serv_parm *hsp;
1555 int len;
1556
1557 vp = &phba->vpd;
1558
1559 CtReq->CommandResponse.bits.CmdRsp =
1560 be16_to_cpu(SLI_MGMT_RPA);
1561 CtReq->CommandResponse.bits.Size = 0;
1562 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1563 size = sizeof (struct lpfc_name) + FOURBYTES;
1564 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001565 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001566 sizeof (struct lpfc_name));
1567 pab->ab.EntryCnt = 0;
1568
1569 /* #1 Port attribute entry */
1570 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1571 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1572 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1573 ae->un.SupportFC4Types[2] = 1;
1574 ae->un.SupportFC4Types[7] = 1;
1575 pab->ab.EntryCnt++;
1576 size += FOURBYTES + 32;
1577
1578 /* #2 Port attribute entry */
1579 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1580 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1581 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001582
1583 ae->un.SupportSpeed = 0;
1584 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001585 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001586 if (phba->lmt & LMT_8Gb)
1587 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1588 if (phba->lmt & LMT_4Gb)
1589 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1590 if (phba->lmt & LMT_2Gb)
1591 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1592 if (phba->lmt & LMT_1Gb)
1593 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1594
dea31012005-04-17 16:05:31 -05001595 pab->ab.EntryCnt++;
1596 size += FOURBYTES + 4;
1597
1598 /* #3 Port attribute entry */
1599 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1600 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1601 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1602 switch(phba->fc_linkspeed) {
1603 case LA_1GHZ_LINK:
1604 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1605 break;
1606 case LA_2GHZ_LINK:
1607 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1608 break;
1609 case LA_4GHZ_LINK:
1610 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1611 break;
James Smartb87eab32007-04-25 09:53:28 -04001612 case LA_8GHZ_LINK:
1613 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1614 break;
James Smartf4b4c682009-05-22 14:53:12 -04001615 case LA_10GHZ_LINK:
1616 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
1617 break;
dea31012005-04-17 16:05:31 -05001618 default:
1619 ae->un.PortSpeed =
1620 HBA_PORTSPEED_UNKNOWN;
1621 break;
1622 }
1623 pab->ab.EntryCnt++;
1624 size += FOURBYTES + 4;
1625
1626 /* #4 Port attribute entry */
1627 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1628 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1629 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001630 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001631 ae->un.MaxFrameSize =
1632 (((uint32_t) hsp->cmn.
1633 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1634 bbRcvSizeLsb;
1635 pab->ab.EntryCnt++;
1636 size += FOURBYTES + 4;
1637
1638 /* #5 Port attribute entry */
1639 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1640 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1641 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1642 len = strlen((char *)ae->un.OsDeviceName);
1643 len += (len & 3) ? (4 - (len & 3)) : 4;
1644 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1645 pab->ab.EntryCnt++;
1646 size += FOURBYTES + len;
1647
James Smart3de2a652007-08-02 11:09:59 -04001648 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001649 /* #6 Port attribute entry */
1650 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1651 size);
1652 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1653 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001654 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001655 len = strlen(ae->un.HostName);
1656 len += (len & 3) ? (4 - (len & 3)) : 4;
1657 ae->ad.bits.AttrLen =
1658 be16_to_cpu(FOURBYTES + len);
1659 pab->ab.EntryCnt++;
1660 size += FOURBYTES + len;
1661 }
1662
1663 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1664 /* Total size */
1665 size = GID_REQUEST_SZ - 4 + size;
1666 }
1667 break;
1668
1669 case SLI_MGMT_DHBA:
1670 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1671 CtReq->CommandResponse.bits.Size = 0;
1672 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1673 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001674 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001675 sizeof (struct lpfc_name));
1676 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1677 break;
1678
1679 case SLI_MGMT_DPRT:
1680 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1681 CtReq->CommandResponse.bits.Size = 0;
1682 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1683 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001684 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001685 sizeof (struct lpfc_name));
1686 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1687 break;
1688 }
1689
1690 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001691 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1692 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001693 bpl->tus.f.bdeFlags = 0;
1694 bpl->tus.f.bdeSize = size;
1695 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1696
1697 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1698
James Smarte47c9092008-02-08 18:49:26 -05001699 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1700 * to hold ndlp reference for the corresponding callback function.
1701 */
James Smart92d7f7b2007-06-17 19:56:38 -05001702 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001703 return 0;
1704
James Smarte47c9092008-02-08 18:49:26 -05001705 /* Decrement ndlp reference count to release ndlp reference held
1706 * for the failed command's callback function.
1707 */
James Smart51ef4c22007-08-02 11:10:31 -04001708 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001709
dea31012005-04-17 16:05:31 -05001710 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1711fdmi_cmd_free_bmp:
1712 kfree(bmp);
1713fdmi_cmd_free_mpvirt:
1714 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1715fdmi_cmd_free_mp:
1716 kfree(mp);
1717fdmi_cmd_exit:
1718 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001719 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1720 "0244 Issue FDMI request failed Data: x%x\n",
1721 cmdcode);
dea31012005-04-17 16:05:31 -05001722 return 1;
1723}
1724
1725void
1726lpfc_fdmi_tmo(unsigned long ptr)
1727{
James Smart2e0fef82007-06-17 19:56:36 -05001728 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1729 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001730 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05001731 unsigned long iflag;
1732
James Smart2e0fef82007-06-17 19:56:36 -05001733 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001734 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1735 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05001736 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04001737 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001738
James Smart5e9d9b82008-06-14 22:52:53 -04001739 if (!tmo_posted)
1740 lpfc_worker_wake_up(phba);
1741 return;
dea31012005-04-17 16:05:31 -05001742}
1743
1744void
James Smart2e0fef82007-06-17 19:56:36 -05001745lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001746{
1747 struct lpfc_nodelist *ndlp;
1748
James Smart2e0fef82007-06-17 19:56:36 -05001749 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001750 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001751 if (init_utsname()->nodename[0] != '\0')
1752 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1753 else
1754 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001755 }
dea31012005-04-17 16:05:31 -05001756 return;
1757}
1758
dea31012005-04-17 16:05:31 -05001759void
James Smart2e0fef82007-06-17 19:56:36 -05001760lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001761{
1762 struct lpfc_sli *psli = &phba->sli;
1763 lpfc_vpd_t *vp = &phba->vpd;
1764 uint32_t b1, b2, b3, b4, i, rev;
1765 char c;
1766 uint32_t *ptr, str[4];
1767 uint8_t *fwname;
1768
James Smartf1126682009-06-10 17:22:44 -04001769 if (phba->sli_rev == LPFC_SLI_REV4)
1770 sprintf(fwrevision, "%s", vp->rev.opFwName);
1771 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04001772 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001773 rev = vp->rev.sli2FwRev;
1774 else
1775 rev = vp->rev.sli1FwRev;
1776
1777 b1 = (rev & 0x0000f000) >> 12;
1778 b2 = (rev & 0x00000f00) >> 8;
1779 b3 = (rev & 0x000000c0) >> 6;
1780 b4 = (rev & 0x00000030) >> 4;
1781
1782 switch (b4) {
1783 case 0:
1784 c = 'N';
1785 break;
1786 case 1:
1787 c = 'A';
1788 break;
1789 case 2:
1790 c = 'B';
1791 break;
1792 default:
1793 c = 0;
1794 break;
1795 }
1796 b4 = (rev & 0x0000000f);
1797
James Smartf4b4c682009-05-22 14:53:12 -04001798 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001799 fwname = vp->rev.sli2FwName;
1800 else
1801 fwname = vp->rev.sli1FwName;
1802
1803 for (i = 0; i < 16; i++)
1804 if (fwname[i] == 0x20)
1805 fwname[i] = 0;
1806
1807 ptr = (uint32_t*)fwname;
1808
1809 for (i = 0; i < 3; i++)
1810 str[i] = be32_to_cpu(*ptr++);
1811
1812 if (c == 0) {
1813 if (flag)
1814 sprintf(fwrevision, "%d.%d%d (%s)",
1815 b1, b2, b3, (char *)str);
1816 else
1817 sprintf(fwrevision, "%d.%d%d", b1,
1818 b2, b3);
1819 } else {
1820 if (flag)
1821 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1822 b1, b2, b3, c,
1823 b4, (char *)str);
1824 else
1825 sprintf(fwrevision, "%d.%d%d%c%d",
1826 b1, b2, b3, c, b4);
1827 }
1828 } else {
1829 rev = vp->rev.smFwRev;
1830
1831 b1 = (rev & 0xff000000) >> 24;
1832 b2 = (rev & 0x00f00000) >> 20;
1833 b3 = (rev & 0x000f0000) >> 16;
1834 c = (rev & 0x0000ff00) >> 8;
1835 b4 = (rev & 0x000000ff);
1836
1837 if (flag)
1838 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1839 b2, b3, c, b4);
1840 else
1841 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1842 b2, b3, c, b4);
1843 }
1844 return;
1845}