]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/lpfc/lpfc_ct.c
[SCSI] lpfc 8.3.5: fix VPI registration, error clean up and add support for vlink...
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / lpfc / lpfc_ct.c
CommitLineData
dea3101e
JB
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
d8e93df1 4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e
JB
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
9 * 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. *
dea3101e
JB
19 *******************************************************************/
20
21/*
09372820 22 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea3101e
JB
23 */
24
25#include <linux/blkdev.h>
26#include <linux/pci.h>
27#include <linux/interrupt.h>
28#include <linux/utsname.h>
29
91886523 30#include <scsi/scsi.h>
dea3101e
JB
31#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
f888ba3c 33#include <scsi/scsi_transport_fc.h>
dea3101e 34
da0436e9 35#include "lpfc_hw4.h"
dea3101e
JB
36#include "lpfc_hw.h"
37#include "lpfc_sli.h"
da0436e9 38#include "lpfc_sli4.h"
ea2151b4 39#include "lpfc_nl.h"
dea3101e
JB
40#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"
92d7f7b0 46#include "lpfc_vport.h"
858c9f6c 47#include "lpfc_debugfs.h"
dea3101e
JB
48
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
ed957684 63static void
9c2face6
JS
64lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
65 struct lpfc_dmabuf *mp, uint32_t size)
ed957684
JS
66{
67 if (!mp) {
9c2face6 68 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
97eab634 69 "0146 Ignoring unsolicited CT No HBQ "
9c2face6
JS
70 "status = x%x\n",
71 piocbq->iocb.ulpStatus);
ed957684 72 }
9c2face6
JS
73 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);
ed957684
JS
77}
78
79static void
9c2face6
JS
80lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct lpfc_dmabuf *mp, uint32_t size)
ed957684 82{
9c2face6 83 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
ed957684
JS
84}
85
dea3101e 86void
2e0fef85
JS
87lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
88 struct lpfc_iocbq *piocbq)
dea3101e 89{
ed957684 90 struct lpfc_dmabuf *mp = NULL;
dea3101e 91 IOCB_t *icmd = &piocbq->iocb;
ed957684
JS
92 int i;
93 struct lpfc_iocbq *iocbq;
94 dma_addr_t paddr;
95 uint32_t size;
9c2face6
JS
96 struct list_head head;
97 struct lpfc_dmabuf *bdeBuf;
dea3101e 98
f1c3b0fc
JS
99 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
100
92d7f7b0
JS
101 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)) {
dea3101e
JB
105 /* Not enough posted buffers; Try posting more buffers */
106 phba->fc_stat.NoRcvBuf++;
92d7f7b0 107 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
495a714c 108 lpfc_post_buffer(phba, pring, 2);
dea3101e
JB
109 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
ed957684 118 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9c2face6
JS
119 INIT_LIST_HEAD(&head);
120 list_add_tail(&head, &piocbq->list);
121 list_for_each_entry(iocbq, &head, list) {
ed957684 122 icmd = &iocbq->iocb;
9c2face6 123 if (icmd->ulpBdeCount == 0)
ed957684 124 continue;
9c2face6
JS
125 bdeBuf = iocbq->context2;
126 iocbq->context2 = NULL;
ed957684 127 size = icmd->un.cont64[0].tus.f.bdeSize;
9c2face6
JS
128 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
129 lpfc_in_buf_free(phba, bdeBuf);
ed957684 130 if (icmd->ulpBdeCount == 2) {
9c2face6
JS
131 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);
ed957684 137 }
dea3101e 138 }
9c2face6 139 list_del(&head);
ed957684 140 } else {
d7c255b2
JS
141 INIT_LIST_HEAD(&head);
142 list_add_tail(&head, &piocbq->list);
143 list_for_each_entry(iocbq, &head, list) {
ed957684 144 icmd = &iocbq->iocb;
9c2face6 145 if (icmd->ulpBdeCount == 0)
d7c255b2 146 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
ed957684
JS
147 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;
d7c255b2 153 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
92d7f7b0 154 lpfc_in_buf_free(phba, mp);
ed957684 155 }
495a714c 156 lpfc_post_buffer(phba, pring, i);
dea3101e 157 }
d7c255b2 158 list_del(&head);
dea3101e 159 }
dea3101e
JB
160}
161
6669f9bb
JS
162/**
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
dea3101e 195static void
2e0fef85 196lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea3101e
JB
197{
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 *
2e0fef85 211lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea3101e
JB
212 uint32_t size, int *entries)
213{
214 struct lpfc_dmabuf *mlist = NULL;
215 struct lpfc_dmabuf *mp;
216 int cnt, i = 0;
217
09372820 218 /* We get chunks of FCELSSIZE */
dea3101e
JB
219 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
92d7f7b0
JS
232 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
233 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea3101e
JB
234 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);
0b3a82d3
ES
240 if (mlist)
241 lpfc_free_ct_rsp(phba, mlist);
dea3101e
JB
242 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
34b02dcd 251 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea3101e 252 /* build buffer ptr list for IOCB */
92d7f7b0
JS
253 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
254 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea3101e
JB
255 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
858c9f6c
JS
267int
268lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
269{
270 struct lpfc_dmabuf *buf_ptr;
271
51ef4c26
JS
272 if (ctiocb->context_un.ndlp) {
273 lpfc_nlp_put(ctiocb->context_un.ndlp);
274 ctiocb->context_un.ndlp = NULL;
275 }
858c9f6c
JS
276 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
dea3101e 297static int
2e0fef85 298lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea3101e
JB
299 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,
92d7f7b0 303 uint32_t tmo, uint8_t retry)
dea3101e 304{
2e0fef85 305 struct lpfc_hba *phba = vport->phba;
dea3101e 306 IOCB_t *icmd;
0bd4ca25 307 struct lpfc_iocbq *geniocb;
92d7f7b0 308 int rc;
dea3101e
JB
309
310 /* Allocate buffer for command iocb */
0bd4ca25 311 geniocb = lpfc_sli_get_iocbq(phba);
dea3101e
JB
312
313 if (geniocb == NULL)
314 return 1;
dea3101e
JB
315
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);
34b02dcd 320 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea3101e
JB
321 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;
e47c9093 331 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea3101e
JB
332
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
c9f8735b
JW
342 if (!tmo) {
343 /* FC spec states we need 3 * ratov for CT requests */
344 tmo = (3 * phba->fc_ratov);
345 }
dea3101e
JB
346 icmd->ulpTimeout = tmo;
347 icmd->ulpBdeCount = 1;
348 icmd->ulpLe = 1;
349 icmd->ulpClass = CLASS3;
350 icmd->ulpContext = ndlp->nlp_rpi;
351
92d7f7b0
JS
352 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
dea3101e 358 /* Issue GEN REQ IOCB for NPORT <did> */
e8b62011
JS
359 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);
dea3101e
JB
364 geniocb->iocb_cmpl = cmpl;
365 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
2e0fef85 366 geniocb->vport = vport;
92d7f7b0 367 geniocb->retry = retry;
3772a991 368 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
92d7f7b0
JS
369
370 if (rc == IOCB_ERROR) {
604a3e30 371 lpfc_sli_release_iocbq(phba, geniocb);
dea3101e
JB
372 return 1;
373 }
dea3101e
JB
374
375 return 0;
376}
377
378static int
2e0fef85 379lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea3101e
JB
380 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
381 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
382 struct lpfc_iocbq *),
92d7f7b0 383 uint32_t rsp_size, uint8_t retry)
dea3101e 384{
2e0fef85 385 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
386 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
2e0fef85 399 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
92d7f7b0 400 cnt+1, 0, retry);
dea3101e
JB
401 if (status) {
402 lpfc_free_ct_rsp(phba, outmp);
403 return -ENOMEM;
404 }
405 return 0;
406}
407
549e55cd 408struct lpfc_vport *
92d7f7b0 409lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
92d7f7b0 410 struct lpfc_vport *vport_curr;
549e55cd 411 unsigned long flags;
92d7f7b0 412
549e55cd 413 spin_lock_irqsave(&phba->hbalock, flags);
92d7f7b0 414 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
549e55cd
JS
415 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
416 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0 417 return vport_curr;
549e55cd 418 }
92d7f7b0 419 }
549e55cd 420 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0
JS
421 return NULL;
422}
423
dea3101e 424static int
2e0fef85 425lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea3101e 426{
2e0fef85 427 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
428 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;
2e0fef85 433 uint32_t Did, CTentry;
dea3101e
JB
434 int Cnt;
435 struct list_head head;
436
2e0fef85 437 lpfc_set_disctmo(vport);
92d7f7b0 438 vport->num_disc_nodes = 0;
0ff10d46 439 vport->fc_ns_retry = 0;
dea3101e 440
dea3101e
JB
441
442 list_add_tail(&head, &mp->list);
443 list_for_each_entry_safe(mp, next_mp, &head, list) {
444 mlast = mp;
445
7054a606
JS
446 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
447
dea3101e
JB
448 Size -= Cnt;
449
1dcb58e5 450 if (!ctptr) {
dea3101e 451 ctptr = (uint32_t *) mlast->virt;
1dcb58e5 452 } else
dea3101e
JB
453 Cnt -= 16; /* subtract length of CT header */
454
455 /* Loop through entire NameServer list of DIDs */
7054a606 456 while (Cnt >= sizeof (uint32_t)) {
dea3101e
JB
457 /* Get next DID from NameServer List */
458 CTentry = *ctptr++;
459 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
92d7f7b0 460
dea3101e 461 ndlp = NULL;
92d7f7b0
JS
462
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) ||
3de2a653 470 vport->cfg_peer_port_login)) {
92d7f7b0 471 if ((vport->port_type != LPFC_NPIV_PORT) ||
98c9ea5c 472 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
3de2a653 473 (!vport->cfg_restrict_login)) {
92d7f7b0 474 ndlp = lpfc_setup_disc_node(vport, Did);
58da1ffb 475 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
858c9f6c
JS
476 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
e8b62011
JS
483 lpfc_printf_vlog(vport,
484 KERN_INFO,
92d7f7b0 485 LOG_DISCOVERY,
e8b62011 486 "0238 Process "
92d7f7b0
JS
487 "x%x NameServer Rsp"
488 "Data: x%x x%x x%x\n",
e8b62011 489 Did, ndlp->nlp_flag,
92d7f7b0
JS
490 vport->fc_flag,
491 vport->fc_rscn_id_cnt);
492 } else {
858c9f6c
JS
493 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
e8b62011
JS
500 lpfc_printf_vlog(vport,
501 KERN_INFO,
92d7f7b0 502 LOG_DISCOVERY,
e8b62011 503 "0239 Skip x%x "
92d7f7b0
JS
504 "NameServer Rsp Data: "
505 "x%x x%x\n",
e8b62011 506 Did, vport->fc_flag,
92d7f7b0
JS
507 vport->fc_rscn_id_cnt);
508 }
509
510 } else {
511 if (!(vport->fc_flag & FC_RSCN_MODE) ||
512 (lpfc_rscn_payload_check(vport, Did))) {
858c9f6c
JS
513 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
0ff10d46
JS
520 /* 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);
e47c9093
JS
526 if (ndlp &&
527 NLP_CHK_NODE_ACT(ndlp)
528 && (ndlp->nlp_type &
529 NLP_FCP_TARGET))
0ff10d46
JS
530 lpfc_setup_disc_node
531 (vport, Did);
532 else if (lpfc_ns_cmd(vport,
92d7f7b0
JS
533 SLI_CTNS_GFF_ID,
534 0, Did) == 0)
535 vport->num_disc_nodes++;
536 }
537 else {
858c9f6c
JS
538 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
e8b62011
JS
545 lpfc_printf_vlog(vport,
546 KERN_INFO,
92d7f7b0 547 LOG_DISCOVERY,
e8b62011 548 "0245 Skip x%x "
92d7f7b0
JS
549 "NameServer Rsp Data: "
550 "x%x x%x\n",
e8b62011 551 Did, vport->fc_flag,
92d7f7b0
JS
552 vport->fc_rscn_id_cnt);
553 }
554 }
dea3101e 555 }
dea3101e
JB
556 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);
dea3101e
JB
566 return 0;
567}
568
dea3101e 569static void
2e0fef85
JS
570lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
571 struct lpfc_iocbq *rspiocb)
dea3101e 572{
2e0fef85 573 struct lpfc_vport *vport = cmdiocb->vport;
92d7f7b0 574 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 575 IOCB_t *irsp;
dea3101e 576 struct lpfc_dmabuf *bmp;
dea3101e 577 struct lpfc_dmabuf *outp;
dea3101e 578 struct lpfc_sli_ct_request *CTrsp;
51ef4c26 579 struct lpfc_nodelist *ndlp;
58da1ffb 580 int rc;
dea3101e 581
51ef4c26
JS
582 /* First save ndlp, before we overwrite it */
583 ndlp = cmdiocb->context_un.ndlp;
584
dea3101e
JB
585 /* we pass cmdiocb to state machine which needs rspiocb as well */
586 cmdiocb->context_un.rsp_iocb = rspiocb;
587
dea3101e
JB
588 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
589 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
858c9f6c
JS
590 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);
dea3101e 595
92d7f7b0 596 /* Don't bother processing response if vport is being torn down. */
eada272d
JS
597 if (vport->load_flag & FC_UNLOADING) {
598 if (vport->fc_flag & FC_RSCN_MODE)
599 lpfc_els_flush_rscn(vport);
92d7f7b0 600 goto out;
eada272d 601 }
92d7f7b0 602
58da1ffb 603 if (lpfc_els_chk_latt(vport)) {
e8b62011
JS
604 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
605 "0216 Link event during NS query\n");
eada272d
JS
606 if (vport->fc_flag & FC_RSCN_MODE)
607 lpfc_els_flush_rscn(vport);
858c9f6c
JS
608 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
609 goto out;
610 }
58da1ffb
JS
611 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");
eada272d
JS
614 if (vport->fc_flag & FC_RSCN_MODE)
615 lpfc_els_flush_rscn(vport);
58da1ffb
JS
616 goto out;
617 }
858c9f6c 618 if (irsp->ulpStatus) {
dea3101e 619 /* Check for retry */
2e0fef85 620 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
58da1ffb
JS
621 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
622 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
858c9f6c 623 vport->fc_ns_retry++;
0ff10d46 624
58da1ffb
JS
625 /* CT command is being retried */
626 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
92d7f7b0 627 vport->fc_ns_retry, 0);
58da1ffb
JS
628 if (rc == 0)
629 goto out;
92d7f7b0 630 }
eada272d
JS
631 if (vport->fc_flag & FC_RSCN_MODE)
632 lpfc_els_flush_rscn(vport);
92d7f7b0 633 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
e8b62011
JS
634 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);
dea3101e
JB
637 } 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)) {
e8b62011
JS
642 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
643 "0208 NameServer Rsp Data: x%x\n",
644 vport->fc_flag);
2e0fef85 645 lpfc_ns_rsp(vport, outp,
dea3101e
JB
646 (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 */
a58cbd52
JS
650 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
651 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
e8b62011
JS
652 lpfc_printf_vlog(vport, KERN_INFO,
653 LOG_DISCOVERY,
654 "0269 No NameServer Entries "
a58cbd52 655 "Data: x%x x%x x%x x%x\n",
a58cbd52
JS
656 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);
e8b62011
JS
666 } else {
667 lpfc_printf_vlog(vport, KERN_INFO,
668 LOG_DISCOVERY,
669 "0240 NameServer Rsp Error "
dea3101e 670 "Data: x%x x%x x%x x%x\n",
dea3101e
JB
671 CTrsp->CommandResponse.bits.CmdRsp,
672 (uint32_t) CTrsp->ReasonCode,
673 (uint32_t) CTrsp->Explanation,
2e0fef85 674 vport->fc_flag);
858c9f6c 675
a58cbd52 676 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
858c9f6c
JS
677 "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);
a58cbd52
JS
681 }
682
858c9f6c 683
dea3101e
JB
684 } else {
685 /* NameServer Rsp Error */
e8b62011
JS
686 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
687 "0241 NameServer Rsp Error "
dea3101e 688 "Data: x%x x%x x%x x%x\n",
dea3101e
JB
689 CTrsp->CommandResponse.bits.CmdRsp,
690 (uint32_t) CTrsp->ReasonCode,
691 (uint32_t) CTrsp->Explanation,
2e0fef85 692 vport->fc_flag);
858c9f6c
JS
693
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);
dea3101e
JB
699 }
700 }
701 /* Link up / RSCN discovery */
92d7f7b0
JS
702 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 }
721out:
51ef4c26 722 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 723 lpfc_ct_free_iocb(phba, cmdiocb);
92d7f7b0
JS
724 return;
725}
726
311464ec 727static void
92d7f7b0
JS
728lpfc_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;
92d7f7b0
JS
734 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;
0ff10d46 737 int did, rc, retry;
92d7f7b0
JS
738 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
858c9f6c
JS
744 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
92d7f7b0
JS
748 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)) {
e8b62011
JS
757 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);
92d7f7b0
JS
763 goto out;
764 }
765 }
766 }
858c9f6c 767 else {
0ff10d46
JS
768 /* 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 }
e8b62011
JS
801 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],
7f5f3d0d 805 vport->fc_flag, vport->fc_rscn_id_cnt);
858c9f6c
JS
806 }
807
92d7f7b0
JS
808 /* This is a target port, unregistered port, or the GFF_ID failed */
809 ndlp = lpfc_setup_disc_node(vport, did);
58da1ffb 810 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
e8b62011
JS
811 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);
92d7f7b0 816 } else {
e8b62011
JS
817 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);
92d7f7b0 821 }
dea3101e 822out:
92d7f7b0
JS
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 }
858c9f6c 844 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e
JB
845 return;
846}
847
92d7f7b0 848
dea3101e 849static void
7ee5d43e
JS
850lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
851 struct lpfc_iocbq *rspiocb)
dea3101e 852{
92d7f7b0 853 struct lpfc_vport *vport = cmdiocb->vport;
dea3101e
JB
854 struct lpfc_dmabuf *inp;
855 struct lpfc_dmabuf *outp;
856 IOCB_t *irsp;
857 struct lpfc_sli_ct_request *CTrsp;
51ef4c26 858 struct lpfc_nodelist *ndlp;
92d7f7b0
JS
859 int cmdcode, rc;
860 uint8_t retry;
858c9f6c 861 uint32_t latt;
dea3101e 862
51ef4c26
JS
863 /* First save ndlp, before we overwrite it */
864 ndlp = cmdiocb->context_un.ndlp;
865
dea3101e
JB
866 /* 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;
dea3101e
JB
871 irsp = &rspiocb->iocb;
872
92d7f7b0
JS
873 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
874 CommandResponse.bits.CmdRsp);
dea3101e
JB
875 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
876
858c9f6c
JS
877 latt = lpfc_els_chk_latt(vport);
878
879 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
e8b62011 880 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7ee5d43e 881 "0209 CT Request completes, latt %d, "
e8b62011
JS
882 "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);
dea3101e 886
858c9f6c
JS
887 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
92d7f7b0 891 if (irsp->ulpStatus) {
e8b62011
JS
892 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]);
858c9f6c 895
92d7f7b0
JS
896 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++;
e8b62011 906 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
d7c255b2 907 "0250 Retrying NS cmd %x\n", cmdcode);
92d7f7b0
JS
908 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
909 if (rc == 0)
910 goto out;
911 }
912
913out:
51ef4c26 914 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 915 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e
JB
916 return;
917}
918
7ee5d43e
JS
919static void
920lpfc_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
98c9ea5c
JS
926 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 }
7ee5d43e
JS
936 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
937 return;
938}
939
dea3101e 940static void
2e0fef85
JS
941lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
942 struct lpfc_iocbq *rspiocb)
dea3101e 943{
7ee5d43e
JS
944 IOCB_t *irsp = &rspiocb->iocb;
945 struct lpfc_vport *vport = cmdiocb->vport;
946
98c9ea5c
JS
947 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 }
7ee5d43e 957 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea3101e
JB
958 return;
959}
960
92d7f7b0
JS
961static void
962lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
963 struct lpfc_iocbq *rspiocb)
964{
7ee5d43e
JS
965 IOCB_t *irsp = &rspiocb->iocb;
966 struct lpfc_vport *vport = cmdiocb->vport;
967
98c9ea5c
JS
968 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 }
7ee5d43e 978 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
92d7f7b0
JS
979 return;
980}
981
dea3101e 982static void
2e0fef85
JS
983lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
984 struct lpfc_iocbq *rspiocb)
dea3101e 985{
7ee5d43e
JS
986 IOCB_t *irsp = &rspiocb->iocb;
987 struct lpfc_vport *vport = cmdiocb->vport;
988
98c9ea5c
JS
989 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 }
7ee5d43e
JS
999 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);
dea3101e
JB
1012 return;
1013}
1014
2fb9bd8b 1015static void
92d7f7b0
JS
1016lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1017 struct lpfc_iocbq *rspiocb)
2fb9bd8b 1018{
92d7f7b0
JS
1019 IOCB_t *irsp = &rspiocb->iocb;
1020 struct lpfc_vport *vport = cmdiocb->vport;
1021
98c9ea5c
JS
1022 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 }
7ee5d43e 1032 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
2fb9bd8b
JS
1033 return;
1034}
1035
495a714c 1036int
92d7f7b0
JS
1037lpfc_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
eada272d
JS
1054 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);
92d7f7b0
JS
1058 return n;
1059}
1060
1061int
1062lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1063 size_t size)
dea3101e
JB
1064{
1065 char fwrev[16];
92d7f7b0 1066 int n;
dea3101e 1067
92d7f7b0 1068 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea3101e 1069
92d7f7b0
JS
1070 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1071 vport->phba->ModelName, fwrev, lpfc_release_version);
1072 return n;
dea3101e
JB
1073}
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
92d7f7b0
JS
1083lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1084 uint8_t retry, uint32_t context)
dea3101e 1085{
92d7f7b0 1086 struct lpfc_nodelist * ndlp;
2e0fef85 1087 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1088 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;
92d7f7b0 1094 size_t size;
858c9f6c 1095 int rc = 0;
92d7f7b0
JS
1096
1097 ndlp = lpfc_findnode_did(vport, NameServer_DID);
e47c9093
JS
1098 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1099 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
858c9f6c
JS
1100 rc=1;
1101 goto ns_cmd_exit;
1102 }
dea3101e
JB
1103
1104 /* fill in BDEs for command */
1105 /* Allocate buffer for command payload */
1106 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1107 if (!mp) {
1108 rc=2;
dea3101e 1109 goto ns_cmd_exit;
858c9f6c 1110 }
dea3101e
JB
1111
1112 INIT_LIST_HEAD(&mp->list);
1113 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
858c9f6c
JS
1114 if (!mp->virt) {
1115 rc=3;
dea3101e 1116 goto ns_cmd_free_mp;
858c9f6c 1117 }
dea3101e
JB
1118
1119 /* Allocate buffer for Buffer ptr list */
1120 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1121 if (!bmp) {
1122 rc=4;
dea3101e 1123 goto ns_cmd_free_mpvirt;
858c9f6c 1124 }
dea3101e
JB
1125
1126 INIT_LIST_HEAD(&bmp->list);
1127 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
858c9f6c
JS
1128 if (!bmp->virt) {
1129 rc=5;
dea3101e 1130 goto ns_cmd_free_bmp;
858c9f6c 1131 }
dea3101e
JB
1132
1133 /* NameServer Req */
e8b62011
JS
1134 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);
dea3101e
JB
1137
1138 bpl = (struct ulp_bde64 *) bmp->virt;
1139 memset(bpl, 0, sizeof(struct ulp_bde64));
92d7f7b0
JS
1140 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1141 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea3101e
JB
1142 bpl->tus.f.bdeFlags = 0;
1143 if (cmdcode == SLI_CTNS_GID_FT)
1144 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
92d7f7b0
JS
1145 else if (cmdcode == SLI_CTNS_GFF_ID)
1146 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea3101e
JB
1147 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;
92d7f7b0
JS
1151 else if (cmdcode == SLI_CTNS_RSPN_ID)
1152 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea3101e
JB
1153 else if (cmdcode == SLI_CTNS_RSNN_NN)
1154 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
7ee5d43e
JS
1155 else if (cmdcode == SLI_CTNS_DA_ID)
1156 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
2fb9bd8b
JS
1157 else if (cmdcode == SLI_CTNS_RFF_ID)
1158 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea3101e
JB
1159 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;
92d7f7b0 1175 if (vport->port_state < LPFC_NS_QRY)
2e0fef85
JS
1176 vport->port_state = LPFC_NS_QRY;
1177 lpfc_set_disctmo(vport);
dea3101e
JB
1178 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1179 rsp_size = FC_MAX_NS_RSP;
1180 break;
1181
92d7f7b0
JS
1182 case SLI_CTNS_GFF_ID:
1183 CtReq->CommandResponse.bits.CmdRsp =
1184 be16_to_cpu(SLI_CTNS_GFF_ID);
09372820 1185 CtReq->un.gff.PortId = cpu_to_be32(context);
92d7f7b0
JS
1186 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1187 break;
1188
dea3101e 1189 case SLI_CTNS_RFT_ID:
7ee5d43e 1190 vport->ct_flags &= ~FC_CT_RFT_ID;
dea3101e
JB
1191 CtReq->CommandResponse.bits.CmdRsp =
1192 be16_to_cpu(SLI_CTNS_RFT_ID);
09372820 1193 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea3101e
JB
1194 CtReq->un.rft.fcpReg = 1;
1195 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1196 break;
1197
1198 case SLI_CTNS_RNN_ID:
7ee5d43e 1199 vport->ct_flags &= ~FC_CT_RNN_ID;
dea3101e
JB
1200 CtReq->CommandResponse.bits.CmdRsp =
1201 be16_to_cpu(SLI_CTNS_RNN_ID);
09372820 1202 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
2e0fef85 1203 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea3101e
JB
1204 sizeof (struct lpfc_name));
1205 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1206 break;
1207
92d7f7b0 1208 case SLI_CTNS_RSPN_ID:
7ee5d43e 1209 vport->ct_flags &= ~FC_CT_RSPN_ID;
92d7f7b0
JS
1210 CtReq->CommandResponse.bits.CmdRsp =
1211 be16_to_cpu(SLI_CTNS_RSPN_ID);
09372820 1212 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
92d7f7b0
JS
1213 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;
dea3101e 1219 case SLI_CTNS_RSNN_NN:
7ee5d43e 1220 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea3101e
JB
1221 CtReq->CommandResponse.bits.CmdRsp =
1222 be16_to_cpu(SLI_CTNS_RSNN_NN);
2e0fef85 1223 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea3101e 1224 sizeof (struct lpfc_name));
92d7f7b0
JS
1225 size = sizeof(CtReq->un.rsnn.symbname);
1226 CtReq->un.rsnn.len =
1227 lpfc_vport_symbolic_node_name(vport,
1228 CtReq->un.rsnn.symbname, size);
dea3101e
JB
1229 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1230 break;
7ee5d43e
JS
1231 case SLI_CTNS_DA_ID:
1232 /* Implement DA_ID Nameserver request */
1233 CtReq->CommandResponse.bits.CmdRsp =
1234 be16_to_cpu(SLI_CTNS_DA_ID);
09372820 1235 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
7ee5d43e
JS
1236 cmpl = lpfc_cmpl_ct_cmd_da_id;
1237 break;
92d7f7b0 1238 case SLI_CTNS_RFF_ID:
7ee5d43e 1239 vport->ct_flags &= ~FC_CT_RFF_ID;
92d7f7b0
JS
1240 CtReq->CommandResponse.bits.CmdRsp =
1241 be16_to_cpu(SLI_CTNS_RFF_ID);
a419aef8 1242 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
92d7f7b0
JS
1243 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;
dea3101e 1247 }
e47c9093
JS
1248 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1249 * to hold ndlp reference for the corresponding callback function.
1250 */
858c9f6c 1251 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea3101e 1252 /* On success, The cmpl function will free the buffers */
858c9f6c
JS
1253 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);
dea3101e 1256 return 0;
858c9f6c 1257 }
858c9f6c 1258 rc=6;
e47c9093
JS
1259
1260 /* Decrement ndlp reference count to release ndlp reference held
1261 * for the failed command's callback function.
1262 */
51ef4c26 1263 lpfc_nlp_put(ndlp);
e47c9093 1264
dea3101e
JB
1265 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:
e8b62011
JS
1273 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);
dea3101e
JB
1276 return 1;
1277}
1278
1279static void
2e0fef85
JS
1280lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1281 struct lpfc_iocbq * rspiocb)
dea3101e 1282{
dea3101e
JB
1283 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;
2e0fef85 1290 struct lpfc_vport *vport = cmdiocb->vport;
858c9f6c
JS
1291 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) {
e8b62011
JS
1301 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]);
858c9f6c
JS
1306 lpfc_ct_free_iocb(phba, cmdiocb);
1307 return;
1308 }
dea3101e 1309
2e0fef85 1310 ndlp = lpfc_findnode_did(vport, FDMI_DID);
e47c9093
JS
1311 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1312 goto fail_out;
1313
dea3101e
JB
1314 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1315 /* FDMI rsp failed */
e8b62011
JS
1316 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1317 "0220 FDMI rsp failed Data: x%x\n",
1318 be16_to_cpu(fdmi_cmd));
dea3101e
JB
1319 }
1320
1321 switch (be16_to_cpu(fdmi_cmd)) {
1322 case SLI_MGMT_RHBA:
2e0fef85 1323 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea3101e
JB
1324 break;
1325
1326 case SLI_MGMT_RPA:
1327 break;
1328
1329 case SLI_MGMT_DHBA:
2e0fef85 1330 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea3101e
JB
1331 break;
1332
1333 case SLI_MGMT_DPRT:
2e0fef85 1334 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea3101e
JB
1335 break;
1336 }
e47c9093
JS
1337
1338fail_out:
858c9f6c 1339 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e
JB
1340 return;
1341}
2e0fef85 1342
dea3101e 1343int
2e0fef85 1344lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea3101e 1345{
2e0fef85 1346 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1347 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 */
e8b62011
JS
1383 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);
dea3101e
JB
1386 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;
2e0fef85 1407 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea3101e
JB
1408 sizeof (struct lpfc_name));
1409 /* One entry (port) per adapter */
1410 rh->rpl.EntryCnt = be32_to_cpu(1);
2e0fef85 1411 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea3101e
JB
1412 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));
2e0fef85 1427 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea3101e
JB
1428 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",
2fb9bd8b
JS
1528 init_utsname()->sysname,
1529 init_utsname()->release,
96b644bd 1530 init_utsname()->version);
dea3101e
JB
1531 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,
2e0fef85 1565 (uint8_t *) & vport->fc_sparam.portName,
dea3101e
JB
1566 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);
74b72a59
JW
1582
1583 ae->un.SupportSpeed = 0;
1584 if (phba->lmt & LMT_10Gb)
dea3101e 1585 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
74b72a59
JW
1586 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
dea3101e
JB
1595 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;
b87eab38
JS
1612 case LA_8GHZ_LINK:
1613 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1614 break;
f4b4c68f
JS
1615 case LA_10GHZ_LINK:
1616 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
1617 break;
dea3101e
JB
1618 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);
2e0fef85 1630 hsp = (struct serv_parm *) & vport->fc_sparam;
dea3101e
JB
1631 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
3de2a653 1648 if (vport->cfg_fdmi_on == 2) {
dea3101e
JB
1649 /* #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",
96b644bd 1654 init_utsname()->nodename);
dea3101e
JB
1655 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,
2e0fef85 1674 (uint8_t *) & vport->fc_sparam.portName,
dea3101e
JB
1675 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,
2e0fef85 1684 (uint8_t *) & vport->fc_sparam.portName,
dea3101e
JB
1685 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;
92d7f7b0
JS
1691 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1692 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea3101e
JB
1693 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
e47c9093
JS
1699 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1700 * to hold ndlp reference for the corresponding callback function.
1701 */
92d7f7b0 1702 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea3101e
JB
1703 return 0;
1704
e47c9093
JS
1705 /* Decrement ndlp reference count to release ndlp reference held
1706 * for the failed command's callback function.
1707 */
51ef4c26 1708 lpfc_nlp_put(ndlp);
e47c9093 1709
dea3101e
JB
1710 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 */
e8b62011
JS
1719 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1720 "0244 Issue FDMI request failed Data: x%x\n",
1721 cmdcode);
dea3101e
JB
1722 return 1;
1723}
1724
1725void
1726lpfc_fdmi_tmo(unsigned long ptr)
1727{
2e0fef85
JS
1728 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1729 struct lpfc_hba *phba = vport->phba;
5e9d9b82 1730 uint32_t tmo_posted;
dea3101e
JB
1731 unsigned long iflag;
1732
2e0fef85 1733 spin_lock_irqsave(&vport->work_port_lock, iflag);
5e9d9b82
JS
1734 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1735 if (!tmo_posted)
2e0fef85 1736 vport->work_port_events |= WORKER_FDMI_TMO;
5e9d9b82 1737 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
92d7f7b0 1738
5e9d9b82
JS
1739 if (!tmo_posted)
1740 lpfc_worker_wake_up(phba);
1741 return;
dea3101e
JB
1742}
1743
1744void
2e0fef85 1745lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea3101e
JB
1746{
1747 struct lpfc_nodelist *ndlp;
1748
2e0fef85 1749 ndlp = lpfc_findnode_did(vport, FDMI_DID);
e47c9093 1750 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2e0fef85
JS
1751 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);
dea3101e 1755 }
dea3101e
JB
1756 return;
1757}
1758
dea3101e 1759void
2e0fef85 1760lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea3101e
JB
1761{
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
f1126688
JS
1769 if (phba->sli_rev == LPFC_SLI_REV4)
1770 sprintf(fwrevision, "%s", vp->rev.opFwName);
1771 else if (vp->rev.rBit) {
f4b4c68f 1772 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea3101e
JB
1773 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
f4b4c68f 1798 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea3101e
JB
1799 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}