lpfc: remove set but not used variables
[deliverable/linux.git] / drivers / scsi / lpfc / lpfc_ct.c
CommitLineData
dea3101e 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
f25e8e79 4 * Copyright (C) 2004-2015 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 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 19 *******************************************************************/
20
21/*
09372820 22 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea3101e 23 */
24
25#include <linux/blkdev.h>
26#include <linux/pci.h>
27#include <linux/interrupt.h>
5a0e3ad6 28#include <linux/slab.h>
dea3101e 29#include <linux/utsname.h>
30
91886523 31#include <scsi/scsi.h>
dea3101e 32#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
f888ba3c 34#include <scsi/scsi_transport_fc.h>
6a9c52cf 35#include <scsi/fc/fc_fs.h>
dea3101e 36
da0436e9 37#include "lpfc_hw4.h"
dea3101e 38#include "lpfc_hw.h"
39#include "lpfc_sli.h"
da0436e9 40#include "lpfc_sli4.h"
ea2151b4 41#include "lpfc_nl.h"
dea3101e 42#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_crtn.h"
47#include "lpfc_version.h"
92d7f7b0 48#include "lpfc_vport.h"
858c9f6c 49#include "lpfc_debugfs.h"
dea3101e 50
76a95d75
JS
51/* FDMI Port Speed definitions */
52#define HBA_PORTSPEED_1GBIT 0x0001 /* 1 GBit/sec */
53#define HBA_PORTSPEED_2GBIT 0x0002 /* 2 GBit/sec */
54#define HBA_PORTSPEED_4GBIT 0x0008 /* 4 GBit/sec */
55#define HBA_PORTSPEED_10GBIT 0x0004 /* 10 GBit/sec */
56#define HBA_PORTSPEED_8GBIT 0x0010 /* 8 GBit/sec */
57#define HBA_PORTSPEED_16GBIT 0x0020 /* 16 GBit/sec */
58#define HBA_PORTSPEED_UNKNOWN 0x0800 /* Unknown */
dea3101e 59
60#define FOURBYTES 4
61
62
63static char *lpfc_release_version = LPFC_DRIVER_VERSION;
64
ed957684 65static void
9c2face6
JS
66lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
67 struct lpfc_dmabuf *mp, uint32_t size)
ed957684
JS
68{
69 if (!mp) {
9c2face6 70 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
97eab634 71 "0146 Ignoring unsolicited CT No HBQ "
9c2face6
JS
72 "status = x%x\n",
73 piocbq->iocb.ulpStatus);
ed957684 74 }
9c2face6
JS
75 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
76 "0145 Ignoring unsolicted CT HBQ Size:%d "
77 "status = x%x\n",
78 size, piocbq->iocb.ulpStatus);
ed957684
JS
79}
80
81static void
9c2face6
JS
82lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
83 struct lpfc_dmabuf *mp, uint32_t size)
ed957684 84{
9c2face6 85 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
ed957684
JS
86}
87
dea3101e 88void
2e0fef85
JS
89lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
90 struct lpfc_iocbq *piocbq)
dea3101e 91{
ed957684 92 struct lpfc_dmabuf *mp = NULL;
dea3101e 93 IOCB_t *icmd = &piocbq->iocb;
ed957684
JS
94 int i;
95 struct lpfc_iocbq *iocbq;
96 dma_addr_t paddr;
97 uint32_t size;
9c2face6
JS
98 struct list_head head;
99 struct lpfc_dmabuf *bdeBuf;
dea3101e 100
4fede78f
JS
101 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
102 return;
f1c3b0fc 103
92d7f7b0
JS
104 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
105 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
106 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
e3d2b802
JS
107 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
108 IOERR_RCV_BUFFER_WAITING)) {
dea3101e 109 /* Not enough posted buffers; Try posting more buffers */
110 phba->fc_stat.NoRcvBuf++;
92d7f7b0 111 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
495a714c 112 lpfc_post_buffer(phba, pring, 2);
dea3101e 113 return;
114 }
115
116 /* If there are no BDEs associated with this IOCB,
117 * there is nothing to do.
118 */
119 if (icmd->ulpBdeCount == 0)
120 return;
121
ed957684 122 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9c2face6
JS
123 INIT_LIST_HEAD(&head);
124 list_add_tail(&head, &piocbq->list);
125 list_for_each_entry(iocbq, &head, list) {
ed957684 126 icmd = &iocbq->iocb;
9c2face6 127 if (icmd->ulpBdeCount == 0)
ed957684 128 continue;
9c2face6
JS
129 bdeBuf = iocbq->context2;
130 iocbq->context2 = NULL;
ed957684 131 size = icmd->un.cont64[0].tus.f.bdeSize;
9c2face6
JS
132 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
133 lpfc_in_buf_free(phba, bdeBuf);
ed957684 134 if (icmd->ulpBdeCount == 2) {
9c2face6
JS
135 bdeBuf = iocbq->context3;
136 iocbq->context3 = NULL;
137 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
138 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
139 size);
140 lpfc_in_buf_free(phba, bdeBuf);
ed957684 141 }
dea3101e 142 }
9c2face6 143 list_del(&head);
ed957684 144 } else {
d7c255b2
JS
145 INIT_LIST_HEAD(&head);
146 list_add_tail(&head, &piocbq->list);
147 list_for_each_entry(iocbq, &head, list) {
ed957684 148 icmd = &iocbq->iocb;
9c2face6 149 if (icmd->ulpBdeCount == 0)
d7c255b2 150 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
ed957684
JS
151 for (i = 0; i < icmd->ulpBdeCount; i++) {
152 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
153 icmd->un.cont64[i].addrLow);
154 mp = lpfc_sli_ringpostbuf_get(phba, pring,
155 paddr);
156 size = icmd->un.cont64[i].tus.f.bdeSize;
d7c255b2 157 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
92d7f7b0 158 lpfc_in_buf_free(phba, mp);
ed957684 159 }
495a714c 160 lpfc_post_buffer(phba, pring, i);
dea3101e 161 }
d7c255b2 162 list_del(&head);
dea3101e 163 }
dea3101e 164}
165
6669f9bb 166/**
6dd9e31c 167 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
6669f9bb 168 * @phba: Pointer to HBA context object.
6dd9e31c 169 * @dmabuf: pointer to a dmabuf that describes the FC sequence
6669f9bb 170 *
6dd9e31c
JS
171 * This function serves as the upper level protocol abort handler for CT
172 * protocol.
173 *
174 * Return 1 if abort has been handled, 0 otherwise.
6669f9bb 175 **/
6dd9e31c
JS
176int
177lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
6669f9bb 178{
6dd9e31c 179 int handled;
6669f9bb 180
6dd9e31c
JS
181 /* CT upper level goes through BSG */
182 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
6669f9bb 183
6dd9e31c 184 return handled;
6669f9bb
JS
185}
186
dea3101e 187static void
2e0fef85 188lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea3101e 189{
190 struct lpfc_dmabuf *mlast, *next_mlast;
191
192 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
193 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
194 list_del(&mlast->list);
195 kfree(mlast);
196 }
197 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
198 kfree(mlist);
199 return;
200}
201
202static struct lpfc_dmabuf *
2e0fef85 203lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea3101e 204 uint32_t size, int *entries)
205{
206 struct lpfc_dmabuf *mlist = NULL;
207 struct lpfc_dmabuf *mp;
208 int cnt, i = 0;
209
09372820 210 /* We get chunks of FCELSSIZE */
dea3101e 211 cnt = size > FCELSSIZE ? FCELSSIZE: size;
212
213 while (size) {
214 /* Allocate buffer for rsp payload */
215 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
216 if (!mp) {
217 if (mlist)
218 lpfc_free_ct_rsp(phba, mlist);
219 return NULL;
220 }
221
222 INIT_LIST_HEAD(&mp->list);
223
92d7f7b0
JS
224 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
225 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea3101e 226 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
227 else
228 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
229
230 if (!mp->virt) {
231 kfree(mp);
0b3a82d3
ES
232 if (mlist)
233 lpfc_free_ct_rsp(phba, mlist);
dea3101e 234 return NULL;
235 }
236
237 /* Queue it to a linked list */
238 if (!mlist)
239 mlist = mp;
240 else
241 list_add_tail(&mp->list, &mlist->list);
242
34b02dcd 243 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea3101e 244 /* build buffer ptr list for IOCB */
92d7f7b0
JS
245 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
246 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea3101e 247 bpl->tus.f.bdeSize = (uint16_t) cnt;
248 bpl->tus.w = le32_to_cpu(bpl->tus.w);
249 bpl++;
250
251 i++;
252 size -= cnt;
253 }
254
255 *entries = i;
256 return mlist;
257}
258
858c9f6c
JS
259int
260lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
261{
262 struct lpfc_dmabuf *buf_ptr;
263
51ef4c26
JS
264 if (ctiocb->context_un.ndlp) {
265 lpfc_nlp_put(ctiocb->context_un.ndlp);
266 ctiocb->context_un.ndlp = NULL;
267 }
858c9f6c
JS
268 if (ctiocb->context1) {
269 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
270 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
271 kfree(buf_ptr);
272 ctiocb->context1 = NULL;
273 }
274 if (ctiocb->context2) {
275 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
276 ctiocb->context2 = NULL;
277 }
278
279 if (ctiocb->context3) {
280 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
281 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
282 kfree(buf_ptr);
1109c944 283 ctiocb->context3 = NULL;
858c9f6c
JS
284 }
285 lpfc_sli_release_iocbq(phba, ctiocb);
286 return 0;
287}
288
dea3101e 289static int
2e0fef85 290lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea3101e 291 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
292 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
293 struct lpfc_iocbq *),
294 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
92d7f7b0 295 uint32_t tmo, uint8_t retry)
dea3101e 296{
2e0fef85 297 struct lpfc_hba *phba = vport->phba;
dea3101e 298 IOCB_t *icmd;
0bd4ca25 299 struct lpfc_iocbq *geniocb;
92d7f7b0 300 int rc;
dea3101e 301
302 /* Allocate buffer for command iocb */
0bd4ca25 303 geniocb = lpfc_sli_get_iocbq(phba);
dea3101e 304
305 if (geniocb == NULL)
306 return 1;
dea3101e 307
308 icmd = &geniocb->iocb;
309 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
310 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
311 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
34b02dcd 312 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea3101e 313 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
314
315 if (usr_flg)
316 geniocb->context3 = NULL;
317 else
318 geniocb->context3 = (uint8_t *) bmp;
319
320 /* Save for completion so we can release these resources */
321 geniocb->context1 = (uint8_t *) inp;
322 geniocb->context2 = (uint8_t *) outp;
e47c9093 323 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea3101e 324
325 /* Fill in payload, bp points to frame payload */
326 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
327
328 /* Fill in rest of iocb */
329 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
330 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
6a9c52cf
JS
331 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
332 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea3101e 333
c9f8735b
JW
334 if (!tmo) {
335 /* FC spec states we need 3 * ratov for CT requests */
336 tmo = (3 * phba->fc_ratov);
337 }
dea3101e 338 icmd->ulpTimeout = tmo;
339 icmd->ulpBdeCount = 1;
340 icmd->ulpLe = 1;
341 icmd->ulpClass = CLASS3;
342 icmd->ulpContext = ndlp->nlp_rpi;
6d368e53
JS
343 if (phba->sli_rev == LPFC_SLI_REV4)
344 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea3101e 345
92d7f7b0
JS
346 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
347 /* For GEN_REQUEST64_CR, use the RPI */
348 icmd->ulpCt_h = 0;
349 icmd->ulpCt_l = 0;
350 }
351
dea3101e 352 /* Issue GEN REQ IOCB for NPORT <did> */
e8b62011
JS
353 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
354 "0119 Issue GEN REQ IOCB to NPORT x%x "
355 "Data: x%x x%x\n",
356 ndlp->nlp_DID, icmd->ulpIoTag,
357 vport->port_state);
dea3101e 358 geniocb->iocb_cmpl = cmpl;
359 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
2e0fef85 360 geniocb->vport = vport;
92d7f7b0 361 geniocb->retry = retry;
3772a991 362 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
92d7f7b0
JS
363
364 if (rc == IOCB_ERROR) {
604a3e30 365 lpfc_sli_release_iocbq(phba, geniocb);
dea3101e 366 return 1;
367 }
dea3101e 368
369 return 0;
370}
371
372static int
2e0fef85 373lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea3101e 374 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
375 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
376 struct lpfc_iocbq *),
92d7f7b0 377 uint32_t rsp_size, uint8_t retry)
dea3101e 378{
2e0fef85 379 struct lpfc_hba *phba = vport->phba;
dea3101e 380 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
381 struct lpfc_dmabuf *outmp;
382 int cnt = 0, status;
383 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
384 CommandResponse.bits.CmdRsp;
385
386 bpl++; /* Skip past ct request */
387
388 /* Put buffer(s) for ct rsp in bpl */
389 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
390 if (!outmp)
391 return -ENOMEM;
6a9c52cf
JS
392 /*
393 * Form the CT IOCB. The total number of BDEs in this IOCB
394 * is the single command plus response count from
395 * lpfc_alloc_ct_rsp.
396 */
397 cnt += 1;
2e0fef85 398 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
6a9c52cf 399 cnt, 0, retry);
dea3101e 400 if (status) {
401 lpfc_free_ct_rsp(phba, outmp);
402 return -ENOMEM;
403 }
404 return 0;
405}
406
549e55cd 407struct lpfc_vport *
92d7f7b0 408lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
92d7f7b0 409 struct lpfc_vport *vport_curr;
549e55cd 410 unsigned long flags;
92d7f7b0 411
549e55cd 412 spin_lock_irqsave(&phba->hbalock, flags);
92d7f7b0 413 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
549e55cd
JS
414 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
415 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0 416 return vport_curr;
549e55cd 417 }
92d7f7b0 418 }
549e55cd 419 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0
JS
420 return NULL;
421}
422
dea3101e 423static int
2e0fef85 424lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea3101e 425{
2e0fef85 426 struct lpfc_hba *phba = vport->phba;
dea3101e 427 struct lpfc_sli_ct_request *Response =
428 (struct lpfc_sli_ct_request *) mp->virt;
429 struct lpfc_nodelist *ndlp = NULL;
430 struct lpfc_dmabuf *mlast, *next_mp;
431 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
2e0fef85 432 uint32_t Did, CTentry;
dea3101e 433 int Cnt;
434 struct list_head head;
435
2e0fef85 436 lpfc_set_disctmo(vport);
92d7f7b0 437 vport->num_disc_nodes = 0;
0ff10d46 438 vport->fc_ns_retry = 0;
dea3101e 439
dea3101e 440
441 list_add_tail(&head, &mp->list);
442 list_for_each_entry_safe(mp, next_mp, &head, list) {
443 mlast = mp;
444
7054a606
JS
445 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
446
dea3101e 447 Size -= Cnt;
448
1dcb58e5 449 if (!ctptr) {
dea3101e 450 ctptr = (uint32_t *) mlast->virt;
1dcb58e5 451 } else
dea3101e 452 Cnt -= 16; /* subtract length of CT header */
453
454 /* Loop through entire NameServer list of DIDs */
7054a606 455 while (Cnt >= sizeof (uint32_t)) {
dea3101e 456 /* Get next DID from NameServer List */
457 CTentry = *ctptr++;
458 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
92d7f7b0 459
dea3101e 460 ndlp = NULL;
92d7f7b0
JS
461
462 /*
463 * Check for rscn processing or not
464 * To conserve rpi's, filter out addresses for other
465 * vports on the same physical HBAs.
466 */
467 if ((Did != vport->fc_myDID) &&
468 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
3de2a653 469 vport->cfg_peer_port_login)) {
92d7f7b0 470 if ((vport->port_type != LPFC_NPIV_PORT) ||
98c9ea5c 471 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
3de2a653 472 (!vport->cfg_restrict_login)) {
92d7f7b0 473 ndlp = lpfc_setup_disc_node(vport, Did);
58da1ffb 474 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
858c9f6c
JS
475 lpfc_debugfs_disc_trc(vport,
476 LPFC_DISC_TRC_CT,
477 "Parse GID_FTrsp: "
478 "did:x%x flg:x%x x%x",
479 Did, ndlp->nlp_flag,
480 vport->fc_flag);
481
e8b62011
JS
482 lpfc_printf_vlog(vport,
483 KERN_INFO,
92d7f7b0 484 LOG_DISCOVERY,
e8b62011 485 "0238 Process "
92d7f7b0
JS
486 "x%x NameServer Rsp"
487 "Data: x%x x%x x%x\n",
e8b62011 488 Did, ndlp->nlp_flag,
92d7f7b0
JS
489 vport->fc_flag,
490 vport->fc_rscn_id_cnt);
491 } else {
858c9f6c
JS
492 lpfc_debugfs_disc_trc(vport,
493 LPFC_DISC_TRC_CT,
494 "Skip1 GID_FTrsp: "
495 "did:x%x flg:x%x cnt:%d",
496 Did, vport->fc_flag,
497 vport->fc_rscn_id_cnt);
498
e8b62011
JS
499 lpfc_printf_vlog(vport,
500 KERN_INFO,
92d7f7b0 501 LOG_DISCOVERY,
e8b62011 502 "0239 Skip x%x "
92d7f7b0
JS
503 "NameServer Rsp Data: "
504 "x%x x%x\n",
e8b62011 505 Did, vport->fc_flag,
92d7f7b0
JS
506 vport->fc_rscn_id_cnt);
507 }
508
509 } else {
510 if (!(vport->fc_flag & FC_RSCN_MODE) ||
511 (lpfc_rscn_payload_check(vport, Did))) {
858c9f6c
JS
512 lpfc_debugfs_disc_trc(vport,
513 LPFC_DISC_TRC_CT,
514 "Query GID_FTrsp: "
515 "did:x%x flg:x%x cnt:%d",
516 Did, vport->fc_flag,
517 vport->fc_rscn_id_cnt);
518
0ff10d46
JS
519 /* This NPortID was previously
520 * a FCP target, * Don't even
521 * bother to send GFF_ID.
522 */
523 ndlp = lpfc_findnode_did(vport,
524 Did);
e47c9093
JS
525 if (ndlp &&
526 NLP_CHK_NODE_ACT(ndlp)
527 && (ndlp->nlp_type &
528 NLP_FCP_TARGET))
0ff10d46
JS
529 lpfc_setup_disc_node
530 (vport, Did);
531 else if (lpfc_ns_cmd(vport,
92d7f7b0
JS
532 SLI_CTNS_GFF_ID,
533 0, Did) == 0)
534 vport->num_disc_nodes++;
6a9c52cf
JS
535 else
536 lpfc_setup_disc_node
537 (vport, Did);
92d7f7b0
JS
538 }
539 else {
858c9f6c
JS
540 lpfc_debugfs_disc_trc(vport,
541 LPFC_DISC_TRC_CT,
542 "Skip2 GID_FTrsp: "
543 "did:x%x flg:x%x cnt:%d",
544 Did, vport->fc_flag,
545 vport->fc_rscn_id_cnt);
546
e8b62011
JS
547 lpfc_printf_vlog(vport,
548 KERN_INFO,
92d7f7b0 549 LOG_DISCOVERY,
e8b62011 550 "0245 Skip x%x "
92d7f7b0
JS
551 "NameServer Rsp Data: "
552 "x%x x%x\n",
e8b62011 553 Did, vport->fc_flag,
92d7f7b0
JS
554 vport->fc_rscn_id_cnt);
555 }
556 }
dea3101e 557 }
76b2c34a 558 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
dea3101e 559 goto nsout1;
560 Cnt -= sizeof (uint32_t);
561 }
562 ctptr = NULL;
563
564 }
565
566nsout1:
567 list_del(&head);
dea3101e 568 return 0;
569}
570
dea3101e 571static void
2e0fef85
JS
572lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
573 struct lpfc_iocbq *rspiocb)
dea3101e 574{
2e0fef85 575 struct lpfc_vport *vport = cmdiocb->vport;
92d7f7b0 576 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 577 IOCB_t *irsp;
dea3101e 578 struct lpfc_dmabuf *outp;
dea3101e 579 struct lpfc_sli_ct_request *CTrsp;
51ef4c26 580 struct lpfc_nodelist *ndlp;
58da1ffb 581 int rc;
dea3101e 582
51ef4c26
JS
583 /* First save ndlp, before we overwrite it */
584 ndlp = cmdiocb->context_un.ndlp;
585
dea3101e 586 /* we pass cmdiocb to state machine which needs rspiocb as well */
587 cmdiocb->context_un.rsp_iocb = rspiocb;
588
dea3101e 589 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
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 621 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
edb22f06 622 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
e3d2b802 623 IOERR_NO_RESOURCES)
858c9f6c 624 vport->fc_ns_retry++;
0ff10d46 625
58da1ffb
JS
626 /* CT command is being retried */
627 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
92d7f7b0 628 vport->fc_ns_retry, 0);
58da1ffb
JS
629 if (rc == 0)
630 goto out;
92d7f7b0 631 }
eada272d
JS
632 if (vport->fc_flag & FC_RSCN_MODE)
633 lpfc_els_flush_rscn(vport);
92d7f7b0 634 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
e8b62011
JS
635 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
636 "0257 GID_FT Query error: 0x%x 0x%x\n",
637 irsp->ulpStatus, vport->fc_ns_retry);
dea3101e 638 } else {
639 /* Good status, continue checking */
640 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
641 if (CTrsp->CommandResponse.bits.CmdRsp ==
76b2c34a 642 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
e8b62011
JS
643 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
644 "0208 NameServer Rsp Data: x%x\n",
645 vport->fc_flag);
2e0fef85 646 lpfc_ns_rsp(vport, outp,
dea3101e 647 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
648 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
649 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
650 /* NameServer Rsp Error */
a58cbd52
JS
651 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
652 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
e8b62011
JS
653 lpfc_printf_vlog(vport, KERN_INFO,
654 LOG_DISCOVERY,
655 "0269 No NameServer Entries "
a58cbd52 656 "Data: x%x x%x x%x x%x\n",
a58cbd52
JS
657 CTrsp->CommandResponse.bits.CmdRsp,
658 (uint32_t) CTrsp->ReasonCode,
659 (uint32_t) CTrsp->Explanation,
660 vport->fc_flag);
661
662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
663 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
664 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
665 (uint32_t) CTrsp->ReasonCode,
666 (uint32_t) CTrsp->Explanation);
e8b62011
JS
667 } else {
668 lpfc_printf_vlog(vport, KERN_INFO,
669 LOG_DISCOVERY,
670 "0240 NameServer Rsp Error "
dea3101e 671 "Data: x%x x%x x%x x%x\n",
dea3101e 672 CTrsp->CommandResponse.bits.CmdRsp,
673 (uint32_t) CTrsp->ReasonCode,
674 (uint32_t) CTrsp->Explanation,
2e0fef85 675 vport->fc_flag);
858c9f6c 676
a58cbd52 677 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
858c9f6c
JS
678 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
679 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
680 (uint32_t) CTrsp->ReasonCode,
681 (uint32_t) CTrsp->Explanation);
a58cbd52
JS
682 }
683
858c9f6c 684
dea3101e 685 } else {
686 /* NameServer Rsp Error */
e8b62011
JS
687 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
688 "0241 NameServer Rsp Error "
dea3101e 689 "Data: x%x x%x x%x x%x\n",
dea3101e 690 CTrsp->CommandResponse.bits.CmdRsp,
691 (uint32_t) CTrsp->ReasonCode,
692 (uint32_t) CTrsp->Explanation,
2e0fef85 693 vport->fc_flag);
858c9f6c
JS
694
695 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
696 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
697 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
698 (uint32_t) CTrsp->ReasonCode,
699 (uint32_t) CTrsp->Explanation);
dea3101e 700 }
701 }
702 /* Link up / RSCN discovery */
92d7f7b0
JS
703 if (vport->num_disc_nodes == 0) {
704 /*
705 * The driver has cycled through all Nports in the RSCN payload.
706 * Complete the handling by cleaning up and marking the
707 * current driver state.
708 */
709 if (vport->port_state >= LPFC_DISC_AUTH) {
710 if (vport->fc_flag & FC_RSCN_MODE) {
711 lpfc_els_flush_rscn(vport);
712 spin_lock_irq(shost->host_lock);
713 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
714 spin_unlock_irq(shost->host_lock);
715 }
716 else
717 lpfc_els_flush_rscn(vport);
718 }
719
720 lpfc_disc_start(vport);
721 }
722out:
51ef4c26 723 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 724 lpfc_ct_free_iocb(phba, cmdiocb);
92d7f7b0
JS
725 return;
726}
727
311464ec 728static void
92d7f7b0
JS
729lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
730 struct lpfc_iocbq *rspiocb)
731{
732 struct lpfc_vport *vport = cmdiocb->vport;
733 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
734 IOCB_t *irsp = &rspiocb->iocb;
92d7f7b0
JS
735 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
736 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
737 struct lpfc_sli_ct_request *CTrsp;
0ff10d46 738 int did, rc, retry;
92d7f7b0
JS
739 uint8_t fbits;
740 struct lpfc_nodelist *ndlp;
741
742 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
743 did = be32_to_cpu(did);
744
858c9f6c
JS
745 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
746 "GFF_ID cmpl: status:x%x/x%x did:x%x",
747 irsp->ulpStatus, irsp->un.ulpWord[4], did);
748
92d7f7b0
JS
749 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
750 /* Good status, continue checking */
751 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
752 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
753
754 if (CTrsp->CommandResponse.bits.CmdRsp ==
755 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
756 if ((fbits & FC4_FEATURE_INIT) &&
757 !(fbits & FC4_FEATURE_TARGET)) {
e8b62011
JS
758 lpfc_printf_vlog(vport, KERN_INFO,
759 LOG_DISCOVERY,
760 "0270 Skip x%x GFF "
761 "NameServer Rsp Data: (init) "
762 "x%x x%x\n", did, fbits,
763 vport->fc_rscn_id_cnt);
92d7f7b0
JS
764 goto out;
765 }
766 }
767 }
858c9f6c 768 else {
0ff10d46
JS
769 /* Check for retry */
770 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
771 retry = 1;
772 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
e3d2b802
JS
773 switch ((irsp->un.ulpWord[4] &
774 IOERR_PARAM_MASK)) {
775
0ff10d46
JS
776 case IOERR_NO_RESOURCES:
777 /* We don't increment the retry
778 * count for this case.
779 */
780 break;
781 case IOERR_LINK_DOWN:
782 case IOERR_SLI_ABORTED:
783 case IOERR_SLI_DOWN:
784 retry = 0;
785 break;
786 default:
787 cmdiocb->retry++;
788 }
789 }
790 else
791 cmdiocb->retry++;
792
793 if (retry) {
794 /* CT command is being retried */
795 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
796 cmdiocb->retry, did);
797 if (rc == 0) {
798 /* success */
799 lpfc_ct_free_iocb(phba, cmdiocb);
800 return;
801 }
802 }
803 }
e8b62011
JS
804 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
805 "0267 NameServer GFF Rsp "
806 "x%x Error (%d %d) Data: x%x x%x\n",
807 did, irsp->ulpStatus, irsp->un.ulpWord[4],
7f5f3d0d 808 vport->fc_flag, vport->fc_rscn_id_cnt);
858c9f6c
JS
809 }
810
92d7f7b0
JS
811 /* This is a target port, unregistered port, or the GFF_ID failed */
812 ndlp = lpfc_setup_disc_node(vport, did);
58da1ffb 813 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
e8b62011
JS
814 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
815 "0242 Process x%x GFF "
816 "NameServer Rsp Data: x%x x%x x%x\n",
817 did, ndlp->nlp_flag, vport->fc_flag,
818 vport->fc_rscn_id_cnt);
92d7f7b0 819 } else {
e8b62011
JS
820 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
821 "0243 Skip x%x GFF "
822 "NameServer Rsp Data: x%x x%x\n", did,
823 vport->fc_flag, vport->fc_rscn_id_cnt);
92d7f7b0 824 }
dea3101e 825out:
92d7f7b0
JS
826 /* Link up / RSCN discovery */
827 if (vport->num_disc_nodes)
828 vport->num_disc_nodes--;
829 if (vport->num_disc_nodes == 0) {
830 /*
831 * The driver has cycled through all Nports in the RSCN payload.
832 * Complete the handling by cleaning up and marking the
833 * current driver state.
834 */
835 if (vport->port_state >= LPFC_DISC_AUTH) {
836 if (vport->fc_flag & FC_RSCN_MODE) {
837 lpfc_els_flush_rscn(vport);
838 spin_lock_irq(shost->host_lock);
839 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
840 spin_unlock_irq(shost->host_lock);
841 }
842 else
843 lpfc_els_flush_rscn(vport);
844 }
845 lpfc_disc_start(vport);
846 }
858c9f6c 847 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e 848 return;
849}
850
92d7f7b0 851
dea3101e 852static void
7ee5d43e
JS
853lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
854 struct lpfc_iocbq *rspiocb)
dea3101e 855{
92d7f7b0 856 struct lpfc_vport *vport = cmdiocb->vport;
dea3101e 857 struct lpfc_dmabuf *inp;
858 struct lpfc_dmabuf *outp;
859 IOCB_t *irsp;
860 struct lpfc_sli_ct_request *CTrsp;
51ef4c26 861 struct lpfc_nodelist *ndlp;
92d7f7b0
JS
862 int cmdcode, rc;
863 uint8_t retry;
858c9f6c 864 uint32_t latt;
dea3101e 865
51ef4c26
JS
866 /* First save ndlp, before we overwrite it */
867 ndlp = cmdiocb->context_un.ndlp;
868
dea3101e 869 /* we pass cmdiocb to state machine which needs rspiocb as well */
870 cmdiocb->context_un.rsp_iocb = rspiocb;
871
872 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
873 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea3101e 874 irsp = &rspiocb->iocb;
875
92d7f7b0
JS
876 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
877 CommandResponse.bits.CmdRsp);
dea3101e 878 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
879
858c9f6c
JS
880 latt = lpfc_els_chk_latt(vport);
881
882 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
e8b62011 883 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7ee5d43e 884 "0209 CT Request completes, latt %d, "
e8b62011
JS
885 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
886 latt, irsp->ulpStatus,
887 CTrsp->CommandResponse.bits.CmdRsp,
888 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea3101e 889
858c9f6c
JS
890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
891 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
892 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
893
92d7f7b0 894 if (irsp->ulpStatus) {
e8b62011 895 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6e15520d 896 "0268 NS cmd x%x Error (x%x x%x)\n",
e8b62011 897 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
858c9f6c 898
92d7f7b0 899 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
e3d2b802
JS
900 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
901 IOERR_SLI_DOWN) ||
902 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
903 IOERR_SLI_ABORTED)))
92d7f7b0
JS
904 goto out;
905
906 retry = cmdiocb->retry;
907 if (retry >= LPFC_MAX_NS_RETRY)
908 goto out;
909
910 retry++;
e8b62011 911 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
d7c255b2 912 "0250 Retrying NS cmd %x\n", cmdcode);
92d7f7b0
JS
913 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
914 if (rc == 0)
915 goto out;
916 }
917
918out:
51ef4c26 919 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 920 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e 921 return;
922}
923
7ee5d43e
JS
924static void
925lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
926 struct lpfc_iocbq *rspiocb)
927{
928 IOCB_t *irsp = &rspiocb->iocb;
929 struct lpfc_vport *vport = cmdiocb->vport;
930
98c9ea5c
JS
931 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
932 struct lpfc_dmabuf *outp;
933 struct lpfc_sli_ct_request *CTrsp;
934
935 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
936 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
937 if (CTrsp->CommandResponse.bits.CmdRsp ==
938 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
939 vport->ct_flags |= FC_CT_RFT_ID;
940 }
7ee5d43e
JS
941 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
942 return;
943}
944
dea3101e 945static void
2e0fef85
JS
946lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
947 struct lpfc_iocbq *rspiocb)
dea3101e 948{
7ee5d43e
JS
949 IOCB_t *irsp = &rspiocb->iocb;
950 struct lpfc_vport *vport = cmdiocb->vport;
951
98c9ea5c
JS
952 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
953 struct lpfc_dmabuf *outp;
954 struct lpfc_sli_ct_request *CTrsp;
955
956 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
957 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
958 if (CTrsp->CommandResponse.bits.CmdRsp ==
959 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
960 vport->ct_flags |= FC_CT_RNN_ID;
961 }
7ee5d43e 962 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea3101e 963 return;
964}
965
92d7f7b0
JS
966static void
967lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
968 struct lpfc_iocbq *rspiocb)
969{
7ee5d43e
JS
970 IOCB_t *irsp = &rspiocb->iocb;
971 struct lpfc_vport *vport = cmdiocb->vport;
972
98c9ea5c
JS
973 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
974 struct lpfc_dmabuf *outp;
975 struct lpfc_sli_ct_request *CTrsp;
976
977 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
978 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
979 if (CTrsp->CommandResponse.bits.CmdRsp ==
980 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
981 vport->ct_flags |= FC_CT_RSPN_ID;
982 }
7ee5d43e 983 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
92d7f7b0
JS
984 return;
985}
986
dea3101e 987static void
2e0fef85
JS
988lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
989 struct lpfc_iocbq *rspiocb)
dea3101e 990{
7ee5d43e
JS
991 IOCB_t *irsp = &rspiocb->iocb;
992 struct lpfc_vport *vport = cmdiocb->vport;
993
98c9ea5c
JS
994 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
995 struct lpfc_dmabuf *outp;
996 struct lpfc_sli_ct_request *CTrsp;
997
998 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
999 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1000 if (CTrsp->CommandResponse.bits.CmdRsp ==
1001 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1002 vport->ct_flags |= FC_CT_RSNN_NN;
1003 }
7ee5d43e
JS
1004 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1005 return;
1006}
1007
1008static void
1009lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1010 struct lpfc_iocbq *rspiocb)
1011{
1012 struct lpfc_vport *vport = cmdiocb->vport;
1013
1014 /* even if it fails we will act as though it succeeded. */
1015 vport->ct_flags = 0;
1016 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea3101e 1017 return;
1018}
1019
2fb9bd8b 1020static void
92d7f7b0
JS
1021lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1022 struct lpfc_iocbq *rspiocb)
2fb9bd8b 1023{
92d7f7b0
JS
1024 IOCB_t *irsp = &rspiocb->iocb;
1025 struct lpfc_vport *vport = cmdiocb->vport;
1026
98c9ea5c
JS
1027 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1028 struct lpfc_dmabuf *outp;
1029 struct lpfc_sli_ct_request *CTrsp;
1030
1031 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1032 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1033 if (CTrsp->CommandResponse.bits.CmdRsp ==
1034 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1035 vport->ct_flags |= FC_CT_RFF_ID;
1036 }
7ee5d43e 1037 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
2fb9bd8b
JS
1038 return;
1039}
1040
495a714c 1041int
92d7f7b0
JS
1042lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1043 size_t size)
1044{
1045 int n;
1046 uint8_t *wwn = vport->phba->wwpn;
1047
1048 n = snprintf(symbol, size,
1049 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1050 wwn[0], wwn[1], wwn[2], wwn[3],
1051 wwn[4], wwn[5], wwn[6], wwn[7]);
1052
1053 if (vport->port_type == LPFC_PHYSICAL_PORT)
1054 return n;
1055
1056 if (n < size)
1057 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1058
eada272d
JS
1059 if (n < size &&
1060 strlen(vport->fc_vport->symbolic_name))
1061 n += snprintf(symbol + n, size - n, " VName-%s",
1062 vport->fc_vport->symbolic_name);
92d7f7b0
JS
1063 return n;
1064}
1065
1066int
1067lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1068 size_t size)
dea3101e 1069{
6b5151fd 1070 char fwrev[FW_REV_STR_SIZE];
92d7f7b0 1071 int n;
dea3101e 1072
92d7f7b0 1073 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea3101e 1074
f0bf5f91
JS
1075 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1076
1077 if (size < n)
1078 return n;
1079 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
1080
1081 if (size < n)
1082 return n;
1083 n += snprintf(symbol + n, size - n, " DV%s", lpfc_release_version);
1084
1085 if (size < n)
1086 return n;
1087 n += snprintf(symbol + n, size - n, " HN:%s", init_utsname()->nodename);
1088
1089 /* Note :- OS name is "Linux" */
1090 if (size < n)
1091 return n;
1092 n += snprintf(symbol + n, size - n, " OS:%s", init_utsname()->sysname);
1093
92d7f7b0 1094 return n;
dea3101e 1095}
1096
76b2c34a
JS
1097static uint32_t
1098lpfc_find_map_node(struct lpfc_vport *vport)
1099{
1100 struct lpfc_nodelist *ndlp, *next_ndlp;
1101 struct Scsi_Host *shost;
1102 uint32_t cnt = 0;
1103
1104 shost = lpfc_shost_from_vport(vport);
1105 spin_lock_irq(shost->host_lock);
1106 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1107 if (ndlp->nlp_type & NLP_FABRIC)
1108 continue;
1109 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1110 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1111 cnt++;
1112 }
1113 spin_unlock_irq(shost->host_lock);
1114 return cnt;
1115}
1116
dea3101e 1117/*
1118 * lpfc_ns_cmd
1119 * Description:
1120 * Issue Cmd to NameServer
1121 * SLI_CTNS_GID_FT
1122 * LI_CTNS_RFT_ID
1123 */
1124int
92d7f7b0
JS
1125lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1126 uint8_t retry, uint32_t context)
dea3101e 1127{
92d7f7b0 1128 struct lpfc_nodelist * ndlp;
2e0fef85 1129 struct lpfc_hba *phba = vport->phba;
dea3101e 1130 struct lpfc_dmabuf *mp, *bmp;
1131 struct lpfc_sli_ct_request *CtReq;
1132 struct ulp_bde64 *bpl;
1133 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1134 struct lpfc_iocbq *) = NULL;
1135 uint32_t rsp_size = 1024;
92d7f7b0 1136 size_t size;
858c9f6c 1137 int rc = 0;
92d7f7b0
JS
1138
1139 ndlp = lpfc_findnode_did(vport, NameServer_DID);
e47c9093
JS
1140 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1141 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
858c9f6c
JS
1142 rc=1;
1143 goto ns_cmd_exit;
1144 }
dea3101e 1145
1146 /* fill in BDEs for command */
1147 /* Allocate buffer for command payload */
1148 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1149 if (!mp) {
1150 rc=2;
dea3101e 1151 goto ns_cmd_exit;
858c9f6c 1152 }
dea3101e 1153
1154 INIT_LIST_HEAD(&mp->list);
1155 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
858c9f6c
JS
1156 if (!mp->virt) {
1157 rc=3;
dea3101e 1158 goto ns_cmd_free_mp;
858c9f6c 1159 }
dea3101e 1160
1161 /* Allocate buffer for Buffer ptr list */
1162 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1163 if (!bmp) {
1164 rc=4;
dea3101e 1165 goto ns_cmd_free_mpvirt;
858c9f6c 1166 }
dea3101e 1167
1168 INIT_LIST_HEAD(&bmp->list);
1169 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
858c9f6c
JS
1170 if (!bmp->virt) {
1171 rc=5;
dea3101e 1172 goto ns_cmd_free_bmp;
858c9f6c 1173 }
dea3101e 1174
1175 /* NameServer Req */
e8b62011
JS
1176 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1177 "0236 NameServer Req Data: x%x x%x x%x\n",
1178 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea3101e 1179
1180 bpl = (struct ulp_bde64 *) bmp->virt;
1181 memset(bpl, 0, sizeof(struct ulp_bde64));
92d7f7b0
JS
1182 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1183 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea3101e 1184 bpl->tus.f.bdeFlags = 0;
1185 if (cmdcode == SLI_CTNS_GID_FT)
1186 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
92d7f7b0
JS
1187 else if (cmdcode == SLI_CTNS_GFF_ID)
1188 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea3101e 1189 else if (cmdcode == SLI_CTNS_RFT_ID)
1190 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1191 else if (cmdcode == SLI_CTNS_RNN_ID)
1192 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
92d7f7b0
JS
1193 else if (cmdcode == SLI_CTNS_RSPN_ID)
1194 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea3101e 1195 else if (cmdcode == SLI_CTNS_RSNN_NN)
1196 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
7ee5d43e
JS
1197 else if (cmdcode == SLI_CTNS_DA_ID)
1198 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
2fb9bd8b
JS
1199 else if (cmdcode == SLI_CTNS_RFF_ID)
1200 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea3101e 1201 else
1202 bpl->tus.f.bdeSize = 0;
1203 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1204
1205 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1206 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1207 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1208 CtReq->RevisionId.bits.InId = 0;
1209 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1210 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1211 CtReq->CommandResponse.bits.Size = 0;
1212 switch (cmdcode) {
1213 case SLI_CTNS_GID_FT:
1214 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1215 cpu_to_be16(SLI_CTNS_GID_FT);
dea3101e 1216 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
92d7f7b0 1217 if (vport->port_state < LPFC_NS_QRY)
2e0fef85
JS
1218 vport->port_state = LPFC_NS_QRY;
1219 lpfc_set_disctmo(vport);
dea3101e 1220 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1221 rsp_size = FC_MAX_NS_RSP;
1222 break;
1223
92d7f7b0
JS
1224 case SLI_CTNS_GFF_ID:
1225 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1226 cpu_to_be16(SLI_CTNS_GFF_ID);
09372820 1227 CtReq->un.gff.PortId = cpu_to_be32(context);
92d7f7b0
JS
1228 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1229 break;
1230
dea3101e 1231 case SLI_CTNS_RFT_ID:
7ee5d43e 1232 vport->ct_flags &= ~FC_CT_RFT_ID;
dea3101e 1233 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1234 cpu_to_be16(SLI_CTNS_RFT_ID);
09372820 1235 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea3101e 1236 CtReq->un.rft.fcpReg = 1;
1237 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1238 break;
1239
1240 case SLI_CTNS_RNN_ID:
7ee5d43e 1241 vport->ct_flags &= ~FC_CT_RNN_ID;
dea3101e 1242 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1243 cpu_to_be16(SLI_CTNS_RNN_ID);
09372820 1244 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
2e0fef85 1245 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea3101e 1246 sizeof (struct lpfc_name));
1247 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1248 break;
1249
92d7f7b0 1250 case SLI_CTNS_RSPN_ID:
7ee5d43e 1251 vport->ct_flags &= ~FC_CT_RSPN_ID;
92d7f7b0 1252 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1253 cpu_to_be16(SLI_CTNS_RSPN_ID);
09372820 1254 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
92d7f7b0
JS
1255 size = sizeof(CtReq->un.rspn.symbname);
1256 CtReq->un.rspn.len =
1257 lpfc_vport_symbolic_port_name(vport,
1258 CtReq->un.rspn.symbname, size);
1259 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1260 break;
dea3101e 1261 case SLI_CTNS_RSNN_NN:
7ee5d43e 1262 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea3101e 1263 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1264 cpu_to_be16(SLI_CTNS_RSNN_NN);
2e0fef85 1265 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea3101e 1266 sizeof (struct lpfc_name));
92d7f7b0
JS
1267 size = sizeof(CtReq->un.rsnn.symbname);
1268 CtReq->un.rsnn.len =
1269 lpfc_vport_symbolic_node_name(vport,
1270 CtReq->un.rsnn.symbname, size);
dea3101e 1271 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1272 break;
7ee5d43e
JS
1273 case SLI_CTNS_DA_ID:
1274 /* Implement DA_ID Nameserver request */
1275 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1276 cpu_to_be16(SLI_CTNS_DA_ID);
09372820 1277 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
7ee5d43e
JS
1278 cmpl = lpfc_cmpl_ct_cmd_da_id;
1279 break;
92d7f7b0 1280 case SLI_CTNS_RFF_ID:
7ee5d43e 1281 vport->ct_flags &= ~FC_CT_RFF_ID;
92d7f7b0 1282 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1283 cpu_to_be16(SLI_CTNS_RFF_ID);
a419aef8 1284 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
92d7f7b0 1285 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
6a9c52cf 1286 CtReq->un.rff.type_code = FC_TYPE_FCP;
92d7f7b0
JS
1287 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1288 break;
dea3101e 1289 }
e47c9093
JS
1290 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1291 * to hold ndlp reference for the corresponding callback function.
1292 */
858c9f6c 1293 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea3101e 1294 /* On success, The cmpl function will free the buffers */
858c9f6c
JS
1295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1296 "Issue CT cmd: cmd:x%x did:x%x",
1297 cmdcode, ndlp->nlp_DID, 0);
dea3101e 1298 return 0;
858c9f6c 1299 }
858c9f6c 1300 rc=6;
e47c9093
JS
1301
1302 /* Decrement ndlp reference count to release ndlp reference held
1303 * for the failed command's callback function.
1304 */
51ef4c26 1305 lpfc_nlp_put(ndlp);
e47c9093 1306
dea3101e 1307 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1308ns_cmd_free_bmp:
1309 kfree(bmp);
1310ns_cmd_free_mpvirt:
1311 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1312ns_cmd_free_mp:
1313 kfree(mp);
1314ns_cmd_exit:
e8b62011
JS
1315 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1316 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1317 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea3101e 1318 return 1;
1319}
1320
1321static void
2e0fef85
JS
1322lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1323 struct lpfc_iocbq * rspiocb)
dea3101e 1324{
dea3101e 1325 struct lpfc_dmabuf *inp = cmdiocb->context1;
1326 struct lpfc_dmabuf *outp = cmdiocb->context2;
1327 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1328 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1329 struct lpfc_nodelist *ndlp;
1330 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1331 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
2e0fef85 1332 struct lpfc_vport *vport = cmdiocb->vport;
858c9f6c
JS
1333 IOCB_t *irsp = &rspiocb->iocb;
1334 uint32_t latt;
1335
1336 latt = lpfc_els_chk_latt(vport);
858c9f6c
JS
1337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1338 "FDMI cmpl: status:x%x/x%x latt:%d",
1339 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1340
1341 if (latt || irsp->ulpStatus) {
e8b62011
JS
1342 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1343 "0229 FDMI cmd %04x failed, latt = %d "
1344 "ulpStatus: x%x, rid x%x\n",
1345 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1346 irsp->un.ulpWord[4]);
76b2c34a 1347 goto fail_out;
858c9f6c 1348 }
dea3101e 1349
2e0fef85 1350 ndlp = lpfc_findnode_did(vport, FDMI_DID);
e47c9093
JS
1351 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1352 goto fail_out;
1353
76b2c34a 1354 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
dea3101e 1355 /* FDMI rsp failed */
e8b62011
JS
1356 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1357 "0220 FDMI rsp failed Data: x%x\n",
1358 be16_to_cpu(fdmi_cmd));
dea3101e 1359 }
1360
76b2c34a
JS
1361fail_out:
1362 lpfc_ct_free_iocb(phba, cmdiocb);
1363}
1364
1365static void
1366lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1367 struct lpfc_iocbq *rspiocb)
1368{
1369 struct lpfc_vport *vport = cmdiocb->vport;
1370 struct lpfc_dmabuf *inp = cmdiocb->context1;
1371 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1372 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1373 struct lpfc_nodelist *ndlp;
1374
1375 lpfc_cmpl_ct_cmd_fdmi(phba, cmdiocb, rspiocb);
1376
1377 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1378 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1379 return;
1380
1381 /*
1382 * Need to cycle thru FDMI registration for discovery
1383 * DHBA -> DPRT -> RHBA -> RPA
1384 */
dea3101e 1385 switch (be16_to_cpu(fdmi_cmd)) {
1386 case SLI_MGMT_RHBA:
2e0fef85 1387 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea3101e 1388 break;
1389
dea3101e 1390 case SLI_MGMT_DHBA:
2e0fef85 1391 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea3101e 1392 break;
1393
1394 case SLI_MGMT_DPRT:
2e0fef85 1395 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea3101e 1396 break;
1397 }
dea3101e 1398}
2e0fef85 1399
76b2c34a 1400
dea3101e 1401int
2e0fef85 1402lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea3101e 1403{
2e0fef85 1404 struct lpfc_hba *phba = vport->phba;
dea3101e 1405 struct lpfc_dmabuf *mp, *bmp;
1406 struct lpfc_sli_ct_request *CtReq;
1407 struct ulp_bde64 *bpl;
1408 uint32_t size;
76b2c34a
JS
1409 uint32_t rsp_size;
1410 struct lpfc_fdmi_reg_hba *rh;
1411 struct lpfc_fdmi_port_entry *pe;
1412 struct lpfc_fdmi_reg_portattr *pab = NULL;
1413 struct lpfc_fdmi_attr_block *ab = NULL;
1414 struct lpfc_fdmi_attr_entry *ae;
1415 struct lpfc_fdmi_attr_def *ad;
dea3101e 1416 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1417 struct lpfc_iocbq *);
1418
76b2c34a
JS
1419 if (ndlp == NULL) {
1420 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1421 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1422 return 0;
1423 cmpl = lpfc_cmpl_ct_cmd_fdmi; /* cmd interface */
1424 } else {
1425 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
1426 }
dea3101e 1427
1428 /* fill in BDEs for command */
1429 /* Allocate buffer for command payload */
76b2c34a 1430 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea3101e 1431 if (!mp)
1432 goto fdmi_cmd_exit;
1433
1434 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1435 if (!mp->virt)
1436 goto fdmi_cmd_free_mp;
1437
1438 /* Allocate buffer for Buffer ptr list */
76b2c34a 1439 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea3101e 1440 if (!bmp)
1441 goto fdmi_cmd_free_mpvirt;
1442
1443 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1444 if (!bmp->virt)
1445 goto fdmi_cmd_free_bmp;
1446
1447 INIT_LIST_HEAD(&mp->list);
1448 INIT_LIST_HEAD(&bmp->list);
1449
1450 /* FDMI request */
e8b62011
JS
1451 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1452 "0218 FDMI Request Data: x%x x%x x%x\n",
1453 vport->fc_flag, vport->port_state, cmdcode);
76b2c34a 1454 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
dea3101e 1455
76b2c34a 1456 /* First populate the CT_IU preamble */
dea3101e 1457 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1458 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1459 CtReq->RevisionId.bits.InId = 0;
1460
1461 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1462 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
76b2c34a
JS
1463
1464 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
1465 rsp_size = LPFC_BPL_SIZE;
dea3101e 1466 size = 0;
1467
76b2c34a 1468 /* Next fill in the specific FDMI cmd information */
dea3101e 1469 switch (cmdcode) {
76b2c34a 1470 case SLI_MGMT_RHAT:
dea3101e 1471 case SLI_MGMT_RHBA:
1472 {
1473 lpfc_vpd_t *vp = &phba->vpd;
1474 uint32_t i, j, incr;
76b2c34a 1475 int len = 0;
dea3101e 1476
76b2c34a
JS
1477 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
1478 /* HBA Identifier */
2e0fef85 1479 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
76b2c34a
JS
1480 sizeof(struct lpfc_name));
1481
1482 if (cmdcode == SLI_MGMT_RHBA) {
1483 /* Registered Port List */
1484 /* One entry (port) per adapter */
1485 rh->rpl.EntryCnt = cpu_to_be32(1);
1486 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
1487 sizeof(struct lpfc_name));
1488
1489 /* point to the HBA attribute block */
1490 size = 2 * sizeof(struct lpfc_name) +
1491 FOURBYTES;
1492 } else {
1493 size = sizeof(struct lpfc_name);
1494 }
1495 ab = (struct lpfc_fdmi_attr_block *)
1496 ((uint8_t *)rh + size);
dea3101e 1497 ab->EntryCnt = 0;
76b2c34a 1498 size += FOURBYTES;
dea3101e 1499
76b2c34a
JS
1500 /*
1501 * Point to beginning of first HBA attribute entry
1502 */
dea3101e 1503 /* #1 HBA attribute entry */
76b2c34a
JS
1504 ad = (struct lpfc_fdmi_attr_def *)
1505 ((uint8_t *)rh + size);
1506 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1507 memset(ae, 0, sizeof(struct lpfc_name));
1508 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1509 ad->AttrLen = cpu_to_be16(FOURBYTES
1510 + sizeof(struct lpfc_name));
2e0fef85 1511 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
76b2c34a 1512 sizeof(struct lpfc_name));
dea3101e 1513 ab->EntryCnt++;
76b2c34a
JS
1514 size += FOURBYTES + sizeof(struct lpfc_name);
1515 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1516 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1517 goto hba_out;
dea3101e 1518
1519 /* #2 HBA attribute entry */
76b2c34a
JS
1520 ad = (struct lpfc_fdmi_attr_def *)
1521 ((uint8_t *)rh + size);
1522 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1523 memset(ae, 0, sizeof(ae->un.Manufacturer));
1524 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1525 strncpy(ae->un.Manufacturer, "Emulex Corporation",
1526 sizeof(ae->un.Manufacturer));
1527 len = strnlen(ae->un.Manufacturer,
1528 sizeof(ae->un.Manufacturer));
dea3101e 1529 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1530 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1531 ab->EntryCnt++;
1532 size += FOURBYTES + len;
76b2c34a
JS
1533 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1534 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1535 goto hba_out;
dea3101e 1536
1537 /* #3 HBA attribute entry */
76b2c34a
JS
1538 ad = (struct lpfc_fdmi_attr_def *)
1539 ((uint8_t *)rh + size);
1540 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1541 memset(ae, 0, sizeof(ae->un.SerialNumber));
1542 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1543 strncpy(ae->un.SerialNumber, phba->SerialNumber,
1544 sizeof(ae->un.SerialNumber));
1545 len = strnlen(ae->un.SerialNumber,
1546 sizeof(ae->un.SerialNumber));
dea3101e 1547 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1548 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1549 ab->EntryCnt++;
1550 size += FOURBYTES + len;
76b2c34a
JS
1551 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1552 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1553 goto hba_out;
dea3101e 1554
1555 /* #4 HBA attribute entry */
76b2c34a
JS
1556 ad = (struct lpfc_fdmi_attr_def *)
1557 ((uint8_t *)rh + size);
1558 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1559 memset(ae, 0, sizeof(ae->un.Model));
1560 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1561 strncpy(ae->un.Model, phba->ModelName,
1562 sizeof(ae->un.Model));
1563 len = strnlen(ae->un.Model, sizeof(ae->un.Model));
dea3101e 1564 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1565 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1566 ab->EntryCnt++;
1567 size += FOURBYTES + len;
76b2c34a
JS
1568 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1569 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1570 goto hba_out;
dea3101e 1571
1572 /* #5 HBA attribute entry */
76b2c34a
JS
1573 ad = (struct lpfc_fdmi_attr_def *)
1574 ((uint8_t *)rh + size);
1575 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1576 memset(ae, 0, sizeof(ae->un.ModelDescription));
1577 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1578 strncpy(ae->un.ModelDescription, phba->ModelDesc,
1579 sizeof(ae->un.ModelDescription));
1580 len = strnlen(ae->un.ModelDescription,
1581 sizeof(ae->un.ModelDescription));
dea3101e 1582 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1583 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1584 ab->EntryCnt++;
1585 size += FOURBYTES + len;
76b2c34a
JS
1586 if ((size + 8) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1587 goto hba_out;
dea3101e 1588
1589 /* #6 HBA attribute entry */
76b2c34a
JS
1590 ad = (struct lpfc_fdmi_attr_def *)
1591 ((uint8_t *)rh + size);
1592 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1593 memset(ae, 0, 8);
1594 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1595 ad->AttrLen = cpu_to_be16(FOURBYTES + 8);
dea3101e 1596 /* Convert JEDEC ID to ascii for hardware version */
1597 incr = vp->rev.biuRev;
1598 for (i = 0; i < 8; i++) {
1599 j = (incr & 0xf);
1600 if (j <= 9)
1601 ae->un.HardwareVersion[7 - i] =
76b2c34a
JS
1602 (char)((uint8_t)0x30 +
1603 (uint8_t)j);
dea3101e 1604 else
1605 ae->un.HardwareVersion[7 - i] =
76b2c34a
JS
1606 (char)((uint8_t)0x61 +
1607 (uint8_t)(j - 10));
dea3101e 1608 incr = (incr >> 4);
1609 }
1610 ab->EntryCnt++;
1611 size += FOURBYTES + 8;
76b2c34a
JS
1612 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1613 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1614 goto hba_out;
dea3101e 1615
1616 /* #7 HBA attribute entry */
76b2c34a
JS
1617 ad = (struct lpfc_fdmi_attr_def *)
1618 ((uint8_t *)rh + size);
1619 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1620 memset(ae, 0, sizeof(ae->un.DriverVersion));
1621 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1622 strncpy(ae->un.DriverVersion, lpfc_release_version,
1623 sizeof(ae->un.DriverVersion));
1624 len = strnlen(ae->un.DriverVersion,
1625 sizeof(ae->un.DriverVersion));
dea3101e 1626 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1627 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1628 ab->EntryCnt++;
1629 size += FOURBYTES + len;
76b2c34a
JS
1630 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1631 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1632 goto hba_out;
dea3101e 1633
1634 /* #8 HBA attribute entry */
76b2c34a
JS
1635 ad = (struct lpfc_fdmi_attr_def *)
1636 ((uint8_t *)rh + size);
1637 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1638 memset(ae, 0, sizeof(ae->un.OptionROMVersion));
1639 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1640 strncpy(ae->un.OptionROMVersion, phba->OptionROMVersion,
1641 sizeof(ae->un.OptionROMVersion));
1642 len = strnlen(ae->un.OptionROMVersion,
1643 sizeof(ae->un.OptionROMVersion));
dea3101e 1644 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1645 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1646 ab->EntryCnt++;
1647 size += FOURBYTES + len;
76b2c34a
JS
1648 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1649 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1650 goto hba_out;
dea3101e 1651
1652 /* #9 HBA attribute entry */
76b2c34a
JS
1653 ad = (struct lpfc_fdmi_attr_def *)
1654 ((uint8_t *)rh + size);
1655 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1656 memset(ae, 0, sizeof(ae->un.FirmwareVersion));
1657 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
dea3101e 1658 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1659 1);
76b2c34a
JS
1660 len = strnlen(ae->un.FirmwareVersion,
1661 sizeof(ae->un.FirmwareVersion));
dea3101e 1662 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1663 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1664 ab->EntryCnt++;
1665 size += FOURBYTES + len;
76b2c34a
JS
1666 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1667 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1668 goto hba_out;
dea3101e 1669
1670 /* #10 HBA attribute entry */
76b2c34a
JS
1671 ad = (struct lpfc_fdmi_attr_def *)
1672 ((uint8_t *)rh + size);
1673 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1674 memset(ae, 0, sizeof(ae->un.OsNameVersion));
1675 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1676 snprintf(ae->un.OsNameVersion,
1677 sizeof(ae->un.OsNameVersion),
1678 "%s %s %s",
1679 init_utsname()->sysname,
1680 init_utsname()->release,
1681 init_utsname()->version);
1682 len = strnlen(ae->un.OsNameVersion,
1683 sizeof(ae->un.OsNameVersion));
dea3101e 1684 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1685 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1686 ab->EntryCnt++;
1687 size += FOURBYTES + len;
76b2c34a
JS
1688 if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1689 goto hba_out;
dea3101e 1690
1691 /* #11 HBA attribute entry */
76b2c34a
JS
1692 ad = (struct lpfc_fdmi_attr_def *)
1693 ((uint8_t *)rh + size);
1694 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1695 ad->AttrType =
1696 cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1697 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
1698 ae->un.MaxCTPayloadLen = cpu_to_be32(LPFC_MAX_CT_SIZE);
dea3101e 1699 ab->EntryCnt++;
1700 size += FOURBYTES + 4;
76b2c34a
JS
1701 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1702 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1703 goto hba_out;
dea3101e 1704
76b2c34a
JS
1705 /*
1706 * Currently switches don't seem to support the
1707 * following extended HBA attributes.
1708 */
1709 if (!(vport->cfg_fdmi_on & LPFC_FDMI_ALL_ATTRIB))
1710 goto hba_out;
1711
1712 /* #12 HBA attribute entry */
1713 ad = (struct lpfc_fdmi_attr_def *)
1714 ((uint8_t *)rh + size);
1715 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1716 memset(ae, 0, sizeof(ae->un.NodeSymName));
1717 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1718 len = lpfc_vport_symbolic_node_name(vport,
1719 ae->un.NodeSymName, sizeof(ae->un.NodeSymName));
1720 len += (len & 3) ? (4 - (len & 3)) : 4;
1721 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
1722 ab->EntryCnt++;
1723 size += FOURBYTES + len;
1724hba_out:
1725 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
dea3101e 1726 /* Total size */
1727 size = GID_REQUEST_SZ - 4 + size;
1728 }
1729 break;
1730
76b2c34a 1731 case SLI_MGMT_RPRT:
dea3101e 1732 case SLI_MGMT_RPA:
1733 {
dea3101e 1734 struct serv_parm *hsp;
76b2c34a 1735 int len = 0;
dea3101e 1736
76b2c34a
JS
1737 if (cmdcode == SLI_MGMT_RPRT) {
1738 rh = (struct lpfc_fdmi_reg_hba *)
1739 &CtReq->un.PortID;
1740 /* HBA Identifier */
1741 memcpy(&rh->hi.PortName,
1742 &vport->fc_sparam.portName,
1743 sizeof(struct lpfc_name));
1744 pab = (struct lpfc_fdmi_reg_portattr *)
1745 &rh->rpl.EntryCnt;
1746 } else
1747 pab = (struct lpfc_fdmi_reg_portattr *)
1748 &CtReq->un.PortID;
1749 size = sizeof(struct lpfc_name) + FOURBYTES;
1750 memcpy((uint8_t *)&pab->PortName,
1751 (uint8_t *)&vport->fc_sparam.portName,
1752 sizeof(struct lpfc_name));
dea3101e 1753 pab->ab.EntryCnt = 0;
1754
1755 /* #1 Port attribute entry */
76b2c34a
JS
1756 ad = (struct lpfc_fdmi_attr_def *)
1757 ((uint8_t *)pab + size);
1758 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1759 memset(ae, 0, sizeof(ae->un.FC4Types));
1760 ad->AttrType =
1761 cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
1762 ad->AttrLen = cpu_to_be16(FOURBYTES + 32);
1763 ae->un.FC4Types[0] = 0x40; /* Type 1 - ELS */
1764 ae->un.FC4Types[1] = 0x80; /* Type 8 - FCP */
1765 ae->un.FC4Types[4] = 0x80; /* Type 32 - CT */
dea3101e 1766 pab->ab.EntryCnt++;
1767 size += FOURBYTES + 32;
1768
1769 /* #2 Port attribute entry */
76b2c34a
JS
1770 ad = (struct lpfc_fdmi_attr_def *)
1771 ((uint8_t *)pab + size);
1772 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1773 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
1774 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
74b72a59 1775 ae->un.SupportSpeed = 0;
76a95d75
JS
1776 if (phba->lmt & LMT_16Gb)
1777 ae->un.SupportSpeed |= HBA_PORTSPEED_16GBIT;
74b72a59 1778 if (phba->lmt & LMT_10Gb)
76a95d75 1779 ae->un.SupportSpeed |= HBA_PORTSPEED_10GBIT;
74b72a59
JW
1780 if (phba->lmt & LMT_8Gb)
1781 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1782 if (phba->lmt & LMT_4Gb)
1783 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1784 if (phba->lmt & LMT_2Gb)
1785 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1786 if (phba->lmt & LMT_1Gb)
1787 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
76b2c34a
JS
1788 ae->un.SupportSpeed =
1789 cpu_to_be32(ae->un.SupportSpeed);
74b72a59 1790
dea3101e 1791 pab->ab.EntryCnt++;
1792 size += FOURBYTES + 4;
1793
1794 /* #3 Port attribute entry */
76b2c34a
JS
1795 ad = (struct lpfc_fdmi_attr_def *)
1796 ((uint8_t *)pab + size);
1797 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1798 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
1799 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
1800 switch (phba->fc_linkspeed) {
76a95d75
JS
1801 case LPFC_LINK_SPEED_1GHZ:
1802 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
dea3101e 1803 break;
76a95d75
JS
1804 case LPFC_LINK_SPEED_2GHZ:
1805 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
dea3101e 1806 break;
76a95d75
JS
1807 case LPFC_LINK_SPEED_4GHZ:
1808 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
dea3101e 1809 break;
76a95d75
JS
1810 case LPFC_LINK_SPEED_8GHZ:
1811 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
b87eab38 1812 break;
76a95d75
JS
1813 case LPFC_LINK_SPEED_10GHZ:
1814 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
f4b4c68f 1815 break;
76a95d75
JS
1816 case LPFC_LINK_SPEED_16GHZ:
1817 ae->un.PortSpeed = HBA_PORTSPEED_16GBIT;
1818 break;
1819 default:
1820 ae->un.PortSpeed = HBA_PORTSPEED_UNKNOWN;
dea3101e 1821 break;
1822 }
76b2c34a 1823 ae->un.PortSpeed = cpu_to_be32(ae->un.PortSpeed);
dea3101e 1824 pab->ab.EntryCnt++;
1825 size += FOURBYTES + 4;
1826
1827 /* #4 Port attribute entry */
76b2c34a
JS
1828 ad = (struct lpfc_fdmi_attr_def *)
1829 ((uint8_t *)pab + size);
1830 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1831 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
1832 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
1833 hsp = (struct serv_parm *)&vport->fc_sparam;
dea3101e 1834 ae->un.MaxFrameSize =
76b2c34a
JS
1835 (((uint32_t)hsp->cmn.
1836 bbRcvSizeMsb) << 8) | (uint32_t)hsp->cmn.
dea3101e 1837 bbRcvSizeLsb;
76b2c34a
JS
1838 ae->un.MaxFrameSize =
1839 cpu_to_be32(ae->un.MaxFrameSize);
dea3101e 1840 pab->ab.EntryCnt++;
1841 size += FOURBYTES + 4;
76b2c34a
JS
1842 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1843 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1844 goto port_out;
dea3101e 1845
1846 /* #5 Port attribute entry */
76b2c34a
JS
1847 ad = (struct lpfc_fdmi_attr_def *)
1848 ((uint8_t *)pab + size);
1849 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1850 memset(ae, 0, sizeof(ae->un.OsDeviceName));
1851 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
1852 strncpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME,
1853 sizeof(ae->un.OsDeviceName));
1854 len = strnlen((char *)ae->un.OsDeviceName,
1855 sizeof(ae->un.OsDeviceName));
dea3101e 1856 len += (len & 3) ? (4 - (len & 3)) : 4;
76b2c34a 1857 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
dea3101e 1858 pab->ab.EntryCnt++;
1859 size += FOURBYTES + len;
76b2c34a
JS
1860 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1861 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1862 goto port_out;
1863
1864 /* #6 Port attribute entry */
1865 ad = (struct lpfc_fdmi_attr_def *)
1866 ((uint8_t *)pab + size);
1867 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1868 memset(ae, 0, sizeof(ae->un.HostName));
1869 snprintf(ae->un.HostName, sizeof(ae->un.HostName), "%s",
1870 init_utsname()->nodename);
1871 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
1872 len = strnlen(ae->un.HostName,
1873 sizeof(ae->un.HostName));
1874 len += (len & 3) ? (4 - (len & 3)) : 4;
1875 ad->AttrLen =
1876 cpu_to_be16(FOURBYTES + len);
1877 pab->ab.EntryCnt++;
1878 size += FOURBYTES + len;
1879 if ((size + sizeof(struct lpfc_name)) >
1880 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1881 goto port_out;
dea3101e 1882
76b2c34a
JS
1883 /*
1884 * Currently switches don't seem to support the
1885 * following extended Port attributes.
1886 */
1887 if (!(vport->cfg_fdmi_on & LPFC_FDMI_ALL_ATTRIB))
1888 goto port_out;
1889
1890 /* #7 Port attribute entry */
1891 ad = (struct lpfc_fdmi_attr_def *)
1892 ((uint8_t *)pab + size);
1893 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1894 memset(ae, 0, sizeof(struct lpfc_name));
1895 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
1896 ad->AttrLen = cpu_to_be16(FOURBYTES
1897 + sizeof(struct lpfc_name));
1898 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
1899 sizeof(struct lpfc_name));
1900 pab->ab.EntryCnt++;
1901 size += FOURBYTES + sizeof(struct lpfc_name);
1902 if ((size + sizeof(struct lpfc_name)) >
1903 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1904 goto port_out;
1905
1906 /* #8 Port attribute entry */
1907 ad = (struct lpfc_fdmi_attr_def *)
1908 ((uint8_t *)pab + size);
1909 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1910 memset(ae, 0, sizeof(struct lpfc_name));
1911 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
1912 ad->AttrLen = cpu_to_be16(FOURBYTES
1913 + sizeof(struct lpfc_name));
1914 memcpy(&ae->un.PortName, &vport->fc_sparam.portName,
1915 sizeof(struct lpfc_name));
1916 pab->ab.EntryCnt++;
1917 size += FOURBYTES + sizeof(struct lpfc_name);
1918 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1919 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1920 goto port_out;
1921
1922 /* #9 Port attribute entry */
1923 ad = (struct lpfc_fdmi_attr_def *)
1924 ((uint8_t *)pab + size);
1925 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1926 memset(ae, 0, sizeof(ae->un.NodeSymName));
1927 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
1928 len = lpfc_vport_symbolic_port_name(vport,
1929 ae->un.NodeSymName, sizeof(ae->un.NodeSymName));
1930 len += (len & 3) ? (4 - (len & 3)) : 4;
1931 ad->AttrLen = cpu_to_be16(FOURBYTES + len);
1932 pab->ab.EntryCnt++;
1933 size += FOURBYTES + len;
1934 if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1935 goto port_out;
1936
1937 /* #10 Port attribute entry */
1938 ad = (struct lpfc_fdmi_attr_def *)
1939 ((uint8_t *)pab + size);
1940 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1941 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
1942 ae->un.PortState = 0;
1943 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
1944 pab->ab.EntryCnt++;
1945 size += FOURBYTES + 4;
1946 if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1947 goto port_out;
1948
1949 /* #11 Port attribute entry */
1950 ad = (struct lpfc_fdmi_attr_def *)
1951 ((uint8_t *)pab + size);
1952 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1953 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
1954 ae->un.SupportClass =
1955 cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
1956 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
1957 pab->ab.EntryCnt++;
1958 size += FOURBYTES + 4;
1959 if ((size + sizeof(struct lpfc_name)) >
1960 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1961 goto port_out;
1962
1963 /* #12 Port attribute entry */
1964 ad = (struct lpfc_fdmi_attr_def *)
1965 ((uint8_t *)pab + size);
1966 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1967 memset(ae, 0, sizeof(struct lpfc_name));
1968 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
1969 ad->AttrLen = cpu_to_be16(FOURBYTES
1970 + sizeof(struct lpfc_name));
1971 memcpy(&ae->un.FabricName, &vport->fabric_nodename,
1972 sizeof(struct lpfc_name));
1973 pab->ab.EntryCnt++;
1974 size += FOURBYTES + sizeof(struct lpfc_name);
1975 if ((size + LPFC_FDMI_MAX_AE_SIZE) >
1976 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1977 goto port_out;
1978
1979 /* #13 Port attribute entry */
1980 ad = (struct lpfc_fdmi_attr_def *)
1981 ((uint8_t *)pab + size);
1982 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1983 memset(ae, 0, sizeof(ae->un.FC4Types));
1984 ad->AttrType =
1985 cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
1986 ad->AttrLen = cpu_to_be16(FOURBYTES + 32);
1987 ae->un.FC4Types[0] = 0x40; /* Type 1 - ELS */
1988 ae->un.FC4Types[1] = 0x80; /* Type 8 - FCP */
1989 ae->un.FC4Types[4] = 0x80; /* Type 32 - CT */
1990 pab->ab.EntryCnt++;
1991 size += FOURBYTES + 32;
1992 if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
1993 goto port_out;
1994
1995 /* #257 Port attribute entry */
1996 ad = (struct lpfc_fdmi_attr_def *)
1997 ((uint8_t *)pab + size);
1998 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1999 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2000 ae->un.PortState = 0;
2001 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
2002 pab->ab.EntryCnt++;
2003 size += FOURBYTES + 4;
2004 if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2005 goto port_out;
2006
2007 /* #258 Port attribute entry */
2008 ad = (struct lpfc_fdmi_attr_def *)
2009 ((uint8_t *)pab + size);
2010 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2011 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2012 ae->un.PortState = lpfc_find_map_node(vport);
2013 ae->un.PortState = cpu_to_be32(ae->un.PortState);
2014 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
2015 pab->ab.EntryCnt++;
2016 size += FOURBYTES + 4;
2017 if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2018 goto port_out;
2019
2020 /* #259 Port attribute entry */
2021 ad = (struct lpfc_fdmi_attr_def *)
2022 ((uint8_t *)pab + size);
2023 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2024 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2025 ae->un.PortId = cpu_to_be32(vport->fc_myDID);
2026 ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
2027 pab->ab.EntryCnt++;
2028 size += FOURBYTES + 4;
2029port_out:
2030 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
dea3101e 2031 /* Total size */
2032 size = GID_REQUEST_SZ - 4 + size;
2033 }
2034 break;
2035
76b2c34a
JS
2036 case SLI_MGMT_GHAT:
2037 case SLI_MGMT_GRPL:
2038 rsp_size = FC_MAX_NS_RSP;
dea3101e 2039 case SLI_MGMT_DHBA:
76b2c34a
JS
2040 case SLI_MGMT_DHAT:
2041 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2042 memcpy((uint8_t *)&pe->PortName,
2043 (uint8_t *)&vport->fc_sparam.portName,
2044 sizeof(struct lpfc_name));
2045 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea3101e 2046 break;
2047
76b2c34a
JS
2048 case SLI_MGMT_GPAT:
2049 case SLI_MGMT_GPAS:
2050 rsp_size = FC_MAX_NS_RSP;
dea3101e 2051 case SLI_MGMT_DPRT:
76b2c34a
JS
2052 case SLI_MGMT_DPA:
2053 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2054 memcpy((uint8_t *)&pe->PortName,
2055 (uint8_t *)&vport->fc_sparam.portName,
2056 sizeof(struct lpfc_name));
2057 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2058 break;
2059 case SLI_MGMT_GRHL:
2060 size = GID_REQUEST_SZ - 4;
dea3101e 2061 break;
76b2c34a
JS
2062 default:
2063 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2064 "0298 FDMI cmdcode x%x not supported\n",
2065 cmdcode);
2066 goto fdmi_cmd_free_bmpvirt;
dea3101e 2067 }
76b2c34a 2068 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
dea3101e 2069
76b2c34a
JS
2070 bpl = (struct ulp_bde64 *)bmp->virt;
2071 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2072 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
dea3101e 2073 bpl->tus.f.bdeFlags = 0;
2074 bpl->tus.f.bdeSize = size;
dea3101e 2075
76b2c34a
JS
2076 /*
2077 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
e47c9093
JS
2078 * to hold ndlp reference for the corresponding callback function.
2079 */
76b2c34a 2080 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
dea3101e 2081 return 0;
2082
76b2c34a
JS
2083 /*
2084 * Decrement ndlp reference count to release ndlp reference held
e47c9093
JS
2085 * for the failed command's callback function.
2086 */
51ef4c26 2087 lpfc_nlp_put(ndlp);
e47c9093 2088
76b2c34a 2089fdmi_cmd_free_bmpvirt:
dea3101e 2090 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2091fdmi_cmd_free_bmp:
2092 kfree(bmp);
2093fdmi_cmd_free_mpvirt:
2094 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2095fdmi_cmd_free_mp:
2096 kfree(mp);
2097fdmi_cmd_exit:
2098 /* Issue FDMI request failed */
e8b62011
JS
2099 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2100 "0244 Issue FDMI request failed Data: x%x\n",
2101 cmdcode);
dea3101e 2102 return 1;
2103}
2104
92494144
JS
2105/**
2106 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2107 * @ptr - Context object of the timer.
2108 *
2109 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2110 * the worker thread.
2111 **/
2112void
2113lpfc_delayed_disc_tmo(unsigned long ptr)
2114{
2115 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
2116 struct lpfc_hba *phba = vport->phba;
2117 uint32_t tmo_posted;
2118 unsigned long iflag;
2119
2120 spin_lock_irqsave(&vport->work_port_lock, iflag);
2121 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2122 if (!tmo_posted)
2123 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2124 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2125
2126 if (!tmo_posted)
2127 lpfc_worker_wake_up(phba);
2128 return;
2129}
2130
2131/**
2132 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2133 * handle delayed discovery.
2134 * @vport: pointer to a host virtual N_Port data structure.
2135 *
2136 * This function start nport discovery of the vport.
2137 **/
2138void
2139lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2140{
2141 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2142
2143 spin_lock_irq(shost->host_lock);
2144 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2145 spin_unlock_irq(shost->host_lock);
2146 return;
2147 }
2148 vport->fc_flag &= ~FC_DISC_DELAYED;
2149 spin_unlock_irq(shost->host_lock);
2150
2151 lpfc_do_scr_ns_plogi(vport->phba, vport);
2152}
2153
dea3101e 2154void
2155lpfc_fdmi_tmo(unsigned long ptr)
2156{
2e0fef85
JS
2157 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
2158 struct lpfc_hba *phba = vport->phba;
5e9d9b82 2159 uint32_t tmo_posted;
dea3101e 2160 unsigned long iflag;
2161
2e0fef85 2162 spin_lock_irqsave(&vport->work_port_lock, iflag);
5e9d9b82
JS
2163 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
2164 if (!tmo_posted)
2e0fef85 2165 vport->work_port_events |= WORKER_FDMI_TMO;
5e9d9b82 2166 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
92d7f7b0 2167
5e9d9b82
JS
2168 if (!tmo_posted)
2169 lpfc_worker_wake_up(phba);
2170 return;
dea3101e 2171}
2172
2173void
2e0fef85 2174lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea3101e 2175{
2176 struct lpfc_nodelist *ndlp;
2177
2e0fef85 2178 ndlp = lpfc_findnode_did(vport, FDMI_DID);
e47c9093 2179 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
2e0fef85
JS
2180 if (init_utsname()->nodename[0] != '\0')
2181 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2182 else
256ec0d0
JS
2183 mod_timer(&vport->fc_fdmitmo, jiffies +
2184 msecs_to_jiffies(1000 * 60));
dea3101e 2185 }
dea3101e 2186 return;
2187}
2188
dea3101e 2189void
2e0fef85 2190lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea3101e 2191{
2192 struct lpfc_sli *psli = &phba->sli;
2193 lpfc_vpd_t *vp = &phba->vpd;
2194 uint32_t b1, b2, b3, b4, i, rev;
2195 char c;
2196 uint32_t *ptr, str[4];
2197 uint8_t *fwname;
2198
f1126688 2199 if (phba->sli_rev == LPFC_SLI_REV4)
6b5151fd 2200 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
f1126688 2201 else if (vp->rev.rBit) {
f4b4c68f 2202 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea3101e 2203 rev = vp->rev.sli2FwRev;
2204 else
2205 rev = vp->rev.sli1FwRev;
2206
2207 b1 = (rev & 0x0000f000) >> 12;
2208 b2 = (rev & 0x00000f00) >> 8;
2209 b3 = (rev & 0x000000c0) >> 6;
2210 b4 = (rev & 0x00000030) >> 4;
2211
2212 switch (b4) {
2213 case 0:
2214 c = 'N';
2215 break;
2216 case 1:
2217 c = 'A';
2218 break;
2219 case 2:
2220 c = 'B';
2221 break;
73d91e50
JS
2222 case 3:
2223 c = 'X';
2224 break;
dea3101e 2225 default:
2226 c = 0;
2227 break;
2228 }
2229 b4 = (rev & 0x0000000f);
2230
f4b4c68f 2231 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea3101e 2232 fwname = vp->rev.sli2FwName;
2233 else
2234 fwname = vp->rev.sli1FwName;
2235
2236 for (i = 0; i < 16; i++)
2237 if (fwname[i] == 0x20)
2238 fwname[i] = 0;
2239
2240 ptr = (uint32_t*)fwname;
2241
2242 for (i = 0; i < 3; i++)
2243 str[i] = be32_to_cpu(*ptr++);
2244
2245 if (c == 0) {
2246 if (flag)
2247 sprintf(fwrevision, "%d.%d%d (%s)",
2248 b1, b2, b3, (char *)str);
2249 else
2250 sprintf(fwrevision, "%d.%d%d", b1,
2251 b2, b3);
2252 } else {
2253 if (flag)
2254 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
2255 b1, b2, b3, c,
2256 b4, (char *)str);
2257 else
2258 sprintf(fwrevision, "%d.%d%d%c%d",
2259 b1, b2, b3, c, b4);
2260 }
2261 } else {
2262 rev = vp->rev.smFwRev;
2263
2264 b1 = (rev & 0xff000000) >> 24;
2265 b2 = (rev & 0x00f00000) >> 20;
2266 b3 = (rev & 0x000f0000) >> 16;
2267 c = (rev & 0x0000ff00) >> 8;
2268 b4 = (rev & 0x000000ff);
2269
d44a6d2b 2270 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea3101e 2271 }
2272 return;
2273}
This page took 3.583582 seconds and 5 git commands to generate.