]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/scsi/lpfc/lpfc_ct.c
Merge tag 'efi-urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi into...
[mirror_ubuntu-artful-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. *
d080abe0
JS
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
50611577 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
c44ce173 7 * EMULEX and SLI are trademarks of Emulex. *
d080abe0 8 * www.broadcom.com *
dea3101e
JB
9 * *
10 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
dea3101e
JB
21 *******************************************************************/
22
23/*
09372820 24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea3101e
JB
25 */
26
27#include <linux/blkdev.h>
28#include <linux/pci.h>
29#include <linux/interrupt.h>
5a0e3ad6 30#include <linux/slab.h>
dea3101e
JB
31#include <linux/utsname.h>
32
91886523 33#include <scsi/scsi.h>
dea3101e
JB
34#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
f888ba3c 36#include <scsi/scsi_transport_fc.h>
6a9c52cf 37#include <scsi/fc/fc_fs.h>
dea3101e 38
da0436e9 39#include "lpfc_hw4.h"
dea3101e
JB
40#include "lpfc_hw.h"
41#include "lpfc_sli.h"
da0436e9 42#include "lpfc_sli4.h"
ea2151b4 43#include "lpfc_nl.h"
dea3101e 44#include "lpfc_disc.h"
dea3101e 45#include "lpfc.h"
a0f2d3ef
JS
46#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
dea3101e
JB
48#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
50#include "lpfc_version.h"
92d7f7b0 51#include "lpfc_vport.h"
858c9f6c 52#include "lpfc_debugfs.h"
dea3101e 53
a085e87c
JS
54/* FDMI Port Speed definitions - FC-GS-7 */
55#define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
56#define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
57#define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
58#define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
59#define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
60#define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
61#define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
62#define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
63#define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
64#define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
65#define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
66#define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
67#define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
68#define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
69#define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
70#define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
71#define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
72#define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
73#define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
dea3101e
JB
74
75#define FOURBYTES 4
76
77
78static char *lpfc_release_version = LPFC_DRIVER_VERSION;
79
ed957684 80static void
9c2face6
JS
81lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
ed957684
JS
83{
84 if (!mp) {
9c2face6 85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
97eab634 86 "0146 Ignoring unsolicited CT No HBQ "
9c2face6
JS
87 "status = x%x\n",
88 piocbq->iocb.ulpStatus);
ed957684 89 }
9c2face6
JS
90 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
92 "status = x%x\n",
93 size, piocbq->iocb.ulpStatus);
ed957684
JS
94}
95
96static void
9c2face6
JS
97lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
ed957684 99{
9c2face6 100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
ed957684
JS
101}
102
dea3101e 103void
2e0fef85
JS
104lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
dea3101e 106{
ed957684 107 struct lpfc_dmabuf *mp = NULL;
dea3101e 108 IOCB_t *icmd = &piocbq->iocb;
ed957684
JS
109 int i;
110 struct lpfc_iocbq *iocbq;
111 dma_addr_t paddr;
112 uint32_t size;
9c2face6
JS
113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
dea3101e 115
4fede78f
JS
116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
117 return;
f1c3b0fc 118
92d7f7b0
JS
119 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
120 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
121 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
e3d2b802
JS
122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
dea3101e
JB
124 /* Not enough posted buffers; Try posting more buffers */
125 phba->fc_stat.NoRcvBuf++;
92d7f7b0 126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
495a714c 127 lpfc_post_buffer(phba, pring, 2);
dea3101e
JB
128 return;
129 }
130
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
133 */
134 if (icmd->ulpBdeCount == 0)
135 return;
136
ed957684 137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
9c2face6
JS
138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
ed957684 141 icmd = &iocbq->iocb;
9c2face6 142 if (icmd->ulpBdeCount == 0)
ed957684 143 continue;
9c2face6
JS
144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
ed957684 146 size = icmd->un.cont64[0].tus.f.bdeSize;
9c2face6
JS
147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
ed957684 149 if (icmd->ulpBdeCount == 2) {
9c2face6
JS
150 bdeBuf = iocbq->context3;
151 iocbq->context3 = NULL;
152 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
153 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
154 size);
155 lpfc_in_buf_free(phba, bdeBuf);
ed957684 156 }
dea3101e 157 }
9c2face6 158 list_del(&head);
ed957684 159 } else {
d7c255b2
JS
160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
ed957684 163 icmd = &iocbq->iocb;
9c2face6 164 if (icmd->ulpBdeCount == 0)
d7c255b2 165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
ed957684
JS
166 for (i = 0; i < icmd->ulpBdeCount; i++) {
167 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
168 icmd->un.cont64[i].addrLow);
169 mp = lpfc_sli_ringpostbuf_get(phba, pring,
170 paddr);
171 size = icmd->un.cont64[i].tus.f.bdeSize;
d7c255b2 172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
92d7f7b0 173 lpfc_in_buf_free(phba, mp);
ed957684 174 }
495a714c 175 lpfc_post_buffer(phba, pring, i);
dea3101e 176 }
d7c255b2 177 list_del(&head);
dea3101e 178 }
dea3101e
JB
179}
180
6669f9bb 181/**
6dd9e31c 182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
6669f9bb 183 * @phba: Pointer to HBA context object.
6dd9e31c 184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
6669f9bb 185 *
6dd9e31c
JS
186 * This function serves as the upper level protocol abort handler for CT
187 * protocol.
188 *
189 * Return 1 if abort has been handled, 0 otherwise.
6669f9bb 190 **/
6dd9e31c
JS
191int
192lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
6669f9bb 193{
6dd9e31c 194 int handled;
6669f9bb 195
6dd9e31c
JS
196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
6669f9bb 198
6dd9e31c 199 return handled;
6669f9bb
JS
200}
201
dea3101e 202static void
2e0fef85 203lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea3101e
JB
204{
205 struct lpfc_dmabuf *mlast, *next_mlast;
206
207 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
208 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
209 list_del(&mlast->list);
210 kfree(mlast);
211 }
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
213 kfree(mlist);
214 return;
215}
216
217static struct lpfc_dmabuf *
2e0fef85 218lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea3101e
JB
219 uint32_t size, int *entries)
220{
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
223 int cnt, i = 0;
224
09372820 225 /* We get chunks of FCELSSIZE */
dea3101e
JB
226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
227
228 while (size) {
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
231 if (!mp) {
232 if (mlist)
233 lpfc_free_ct_rsp(phba, mlist);
234 return NULL;
235 }
236
237 INIT_LIST_HEAD(&mp->list);
238
92d7f7b0
JS
239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea3101e
JB
241 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
242 else
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
244
245 if (!mp->virt) {
246 kfree(mp);
0b3a82d3
ES
247 if (mlist)
248 lpfc_free_ct_rsp(phba, mlist);
dea3101e
JB
249 return NULL;
250 }
251
252 /* Queue it to a linked list */
253 if (!mlist)
254 mlist = mp;
255 else
256 list_add_tail(&mp->list, &mlist->list);
257
34b02dcd 258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea3101e 259 /* build buffer ptr list for IOCB */
92d7f7b0
JS
260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea3101e
JB
262 bpl->tus.f.bdeSize = (uint16_t) cnt;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264 bpl++;
265
266 i++;
267 size -= cnt;
268 }
269
270 *entries = i;
271 return mlist;
272}
273
858c9f6c
JS
274int
275lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
276{
277 struct lpfc_dmabuf *buf_ptr;
278
51ef4c26
JS
279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
282 }
858c9f6c
JS
283 if (ctiocb->context1) {
284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
286 kfree(buf_ptr);
287 ctiocb->context1 = NULL;
288 }
289 if (ctiocb->context2) {
290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
291 ctiocb->context2 = NULL;
292 }
293
294 if (ctiocb->context3) {
295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
297 kfree(buf_ptr);
1109c944 298 ctiocb->context3 = NULL;
858c9f6c
JS
299 }
300 lpfc_sli_release_iocbq(phba, ctiocb);
301 return 0;
302}
303
4258e98e
JS
304/**
305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
306 * @vport: pointer to a host virtual N_Port data structure.
307 * @bmp: Pointer to BPL for SLI command
308 * @inp: Pointer to data buffer for response data.
309 * @outp: Pointer to data buffer that hold the CT command.
310 * @cmpl: completion routine to call when command completes
311 * @ndlp: Destination NPort nodelist entry
312 *
313 * This function as the final part for issuing a CT command.
314 */
dea3101e 315static int
2e0fef85 316lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea3101e
JB
317 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
319 struct lpfc_iocbq *),
320 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
92d7f7b0 321 uint32_t tmo, uint8_t retry)
dea3101e 322{
2e0fef85 323 struct lpfc_hba *phba = vport->phba;
dea3101e 324 IOCB_t *icmd;
0bd4ca25 325 struct lpfc_iocbq *geniocb;
92d7f7b0 326 int rc;
dea3101e
JB
327
328 /* Allocate buffer for command iocb */
0bd4ca25 329 geniocb = lpfc_sli_get_iocbq(phba);
dea3101e
JB
330
331 if (geniocb == NULL)
332 return 1;
dea3101e
JB
333
334 icmd = &geniocb->iocb;
335 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
336 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
337 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
34b02dcd 338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
4258e98e 339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
dea3101e
JB
340
341 if (usr_flg)
342 geniocb->context3 = NULL;
343 else
344 geniocb->context3 = (uint8_t *) bmp;
345
346 /* Save for completion so we can release these resources */
347 geniocb->context1 = (uint8_t *) inp;
348 geniocb->context2 = (uint8_t *) outp;
e47c9093 349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea3101e
JB
350
351 /* Fill in payload, bp points to frame payload */
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
353
354 /* Fill in rest of iocb */
355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
356 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
6a9c52cf
JS
357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea3101e 359
c9f8735b
JW
360 if (!tmo) {
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
363 }
dea3101e
JB
364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
366 icmd->ulpLe = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
6d368e53
JS
369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea3101e 371
92d7f7b0
JS
372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373 /* For GEN_REQUEST64_CR, use the RPI */
374 icmd->ulpCt_h = 0;
375 icmd->ulpCt_l = 0;
376 }
377
dea3101e 378 /* Issue GEN REQ IOCB for NPORT <did> */
e8b62011
JS
379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
380 "0119 Issue GEN REQ IOCB to NPORT x%x "
381 "Data: x%x x%x\n",
382 ndlp->nlp_DID, icmd->ulpIoTag,
383 vport->port_state);
dea3101e
JB
384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
2e0fef85 386 geniocb->vport = vport;
92d7f7b0 387 geniocb->retry = retry;
3772a991 388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
92d7f7b0
JS
389
390 if (rc == IOCB_ERROR) {
604a3e30 391 lpfc_sli_release_iocbq(phba, geniocb);
dea3101e
JB
392 return 1;
393 }
dea3101e
JB
394
395 return 0;
396}
397
4258e98e
JS
398/**
399 * lpfc_ct_cmd - Build and issue a CT command
400 * @vport: pointer to a host virtual N_Port data structure.
401 * @inmp: Pointer to data buffer for response data.
402 * @bmp: Pointer to BPL for SLI command
403 * @ndlp: Destination NPort nodelist entry
404 * @cmpl: completion routine to call when command completes
405 *
406 * This function is called for issuing a CT command.
407 */
dea3101e 408static int
2e0fef85 409lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea3101e
JB
410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
92d7f7b0 413 uint32_t rsp_size, uint8_t retry)
dea3101e 414{
2e0fef85 415 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
417 struct lpfc_dmabuf *outmp;
418 int cnt = 0, status;
419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
420 CommandResponse.bits.CmdRsp;
421
422 bpl++; /* Skip past ct request */
423
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
426 if (!outmp)
427 return -ENOMEM;
6a9c52cf
JS
428 /*
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
431 * lpfc_alloc_ct_rsp.
432 */
433 cnt += 1;
2e0fef85 434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
6a9c52cf 435 cnt, 0, retry);
dea3101e
JB
436 if (status) {
437 lpfc_free_ct_rsp(phba, outmp);
438 return -ENOMEM;
439 }
440 return 0;
441}
442
549e55cd 443struct lpfc_vport *
92d7f7b0 444lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
92d7f7b0 445 struct lpfc_vport *vport_curr;
549e55cd 446 unsigned long flags;
92d7f7b0 447
549e55cd 448 spin_lock_irqsave(&phba->hbalock, flags);
92d7f7b0 449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
549e55cd
JS
450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0 452 return vport_curr;
549e55cd 453 }
92d7f7b0 454 }
549e55cd 455 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0
JS
456 return NULL;
457}
458
a0f2d3ef
JS
459static void
460lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
461{
462 struct lpfc_nodelist *ndlp;
463
464 if ((vport->port_type != LPFC_NPIV_PORT) ||
465 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
466
467 ndlp = lpfc_setup_disc_node(vport, Did);
468
469 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
bd2cdd5e
JS
470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
471 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
472 Did, ndlp->nlp_flag, vport->fc_flag);
473
a0f2d3ef
JS
474 /* By default, the driver expects to support FCP FC4 */
475 if (fc4_type == FC_TYPE_FCP)
476 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
477
478 if (fc4_type == FC_TYPE_NVME)
479 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
480
481 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
482 "0238 Process x%06x NameServer Rsp "
483 "Data: x%x x%x x%x x%x\n", Did,
484 ndlp->nlp_flag, ndlp->nlp_fc4_type,
485 vport->fc_flag,
486 vport->fc_rscn_id_cnt);
bd2cdd5e
JS
487 } else {
488 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
489 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
490 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
491
a0f2d3ef
JS
492 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
493 "0239 Skip x%06x NameServer Rsp "
494 "Data: x%x x%x\n", Did,
495 vport->fc_flag,
496 vport->fc_rscn_id_cnt);
bd2cdd5e 497 }
a0f2d3ef
JS
498 } else {
499 if (!(vport->fc_flag & FC_RSCN_MODE) ||
500 lpfc_rscn_payload_check(vport, Did)) {
bd2cdd5e
JS
501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
502 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
503 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
504
a0f2d3ef
JS
505 /*
506 * This NPortID was previously a FCP target,
507 * Don't even bother to send GFF_ID.
508 */
509 ndlp = lpfc_findnode_did(vport, Did);
510 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
511 ndlp->nlp_fc4_type = fc4_type;
512
513 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
514 ndlp->nlp_fc4_type = fc4_type;
515
516 if (ndlp->nlp_type & NLP_FCP_TARGET)
517 lpfc_setup_disc_node(vport, Did);
518
519 else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
520 0, Did) == 0)
521 vport->num_disc_nodes++;
522
523 else
524 lpfc_setup_disc_node(vport, Did);
525 }
bd2cdd5e
JS
526 } else {
527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
528 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
529 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
530
a0f2d3ef
JS
531 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
532 "0245 Skip x%06x NameServer Rsp "
533 "Data: x%x x%x\n", Did,
534 vport->fc_flag,
535 vport->fc_rscn_id_cnt);
bd2cdd5e 536 }
a0f2d3ef
JS
537 }
538}
539
dea3101e 540static int
a0f2d3ef
JS
541lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
542 uint32_t Size)
dea3101e 543{
2e0fef85 544 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
545 struct lpfc_sli_ct_request *Response =
546 (struct lpfc_sli_ct_request *) mp->virt;
547 struct lpfc_nodelist *ndlp = NULL;
548 struct lpfc_dmabuf *mlast, *next_mp;
549 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
2e0fef85 550 uint32_t Did, CTentry;
dea3101e
JB
551 int Cnt;
552 struct list_head head;
553
2e0fef85 554 lpfc_set_disctmo(vport);
92d7f7b0 555 vport->num_disc_nodes = 0;
0ff10d46 556 vport->fc_ns_retry = 0;
dea3101e 557
dea3101e
JB
558
559 list_add_tail(&head, &mp->list);
560 list_for_each_entry_safe(mp, next_mp, &head, list) {
561 mlast = mp;
562
7054a606
JS
563 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
564
dea3101e
JB
565 Size -= Cnt;
566
1dcb58e5 567 if (!ctptr) {
dea3101e 568 ctptr = (uint32_t *) mlast->virt;
1dcb58e5 569 } else
dea3101e
JB
570 Cnt -= 16; /* subtract length of CT header */
571
572 /* Loop through entire NameServer list of DIDs */
4258e98e 573 while (Cnt >= sizeof(uint32_t)) {
dea3101e
JB
574 /* Get next DID from NameServer List */
575 CTentry = *ctptr++;
576 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
92d7f7b0 577
dea3101e 578 ndlp = NULL;
92d7f7b0
JS
579
580 /*
581 * Check for rscn processing or not
582 * To conserve rpi's, filter out addresses for other
583 * vports on the same physical HBAs.
584 */
585 if ((Did != vport->fc_myDID) &&
586 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
a0f2d3ef
JS
587 vport->cfg_peer_port_login))
588 lpfc_prep_node_fc4type(vport, Did, fc4_type);
589
76b2c34a 590 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
dea3101e 591 goto nsout1;
a0f2d3ef 592
4258e98e 593 Cnt -= sizeof(uint32_t);
dea3101e
JB
594 }
595 ctptr = NULL;
596
597 }
598
599nsout1:
600 list_del(&head);
dea3101e
JB
601 return 0;
602}
603
dea3101e 604static void
2e0fef85
JS
605lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
606 struct lpfc_iocbq *rspiocb)
dea3101e 607{
2e0fef85 608 struct lpfc_vport *vport = cmdiocb->vport;
92d7f7b0 609 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 610 IOCB_t *irsp;
dea3101e 611 struct lpfc_dmabuf *outp;
a0f2d3ef 612 struct lpfc_dmabuf *inp;
dea3101e 613 struct lpfc_sli_ct_request *CTrsp;
a0f2d3ef 614 struct lpfc_sli_ct_request *CTreq;
51ef4c26 615 struct lpfc_nodelist *ndlp;
a0f2d3ef 616 int rc, type;
dea3101e 617
51ef4c26
JS
618 /* First save ndlp, before we overwrite it */
619 ndlp = cmdiocb->context_un.ndlp;
620
dea3101e
JB
621 /* we pass cmdiocb to state machine which needs rspiocb as well */
622 cmdiocb->context_un.rsp_iocb = rspiocb;
a0f2d3ef 623 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
dea3101e 624 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
858c9f6c
JS
625 irsp = &rspiocb->iocb;
626
627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
628 "GID_FT cmpl: status:x%x/x%x rtry:%d",
629 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea3101e 630
92d7f7b0 631 /* Don't bother processing response if vport is being torn down. */
eada272d
JS
632 if (vport->load_flag & FC_UNLOADING) {
633 if (vport->fc_flag & FC_RSCN_MODE)
634 lpfc_els_flush_rscn(vport);
92d7f7b0 635 goto out;
eada272d 636 }
92d7f7b0 637
58da1ffb 638 if (lpfc_els_chk_latt(vport)) {
e8b62011
JS
639 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
640 "0216 Link event during NS query\n");
eada272d
JS
641 if (vport->fc_flag & FC_RSCN_MODE)
642 lpfc_els_flush_rscn(vport);
858c9f6c
JS
643 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
644 goto out;
645 }
58da1ffb
JS
646 if (lpfc_error_lost_link(irsp)) {
647 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
648 "0226 NS query failed due to link event\n");
eada272d
JS
649 if (vport->fc_flag & FC_RSCN_MODE)
650 lpfc_els_flush_rscn(vport);
58da1ffb
JS
651 goto out;
652 }
858c9f6c 653 if (irsp->ulpStatus) {
dea3101e 654 /* Check for retry */
2e0fef85 655 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
58da1ffb 656 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
edb22f06 657 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
e3d2b802 658 IOERR_NO_RESOURCES)
858c9f6c 659 vport->fc_ns_retry++;
0ff10d46 660
a0f2d3ef
JS
661 type = lpfc_get_gidft_type(vport, cmdiocb);
662 if (type == 0)
663 goto out;
664
58da1ffb 665 /* CT command is being retried */
a0f2d3ef 666 vport->gidft_inp--;
58da1ffb 667 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
a0f2d3ef 668 vport->fc_ns_retry, type);
58da1ffb
JS
669 if (rc == 0)
670 goto out;
92d7f7b0 671 }
eada272d
JS
672 if (vport->fc_flag & FC_RSCN_MODE)
673 lpfc_els_flush_rscn(vport);
92d7f7b0 674 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
e8b62011
JS
675 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
676 "0257 GID_FT Query error: 0x%x 0x%x\n",
677 irsp->ulpStatus, vport->fc_ns_retry);
dea3101e
JB
678 } else {
679 /* Good status, continue checking */
a0f2d3ef 680 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
dea3101e
JB
681 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
682 if (CTrsp->CommandResponse.bits.CmdRsp ==
76b2c34a 683 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
e8b62011 684 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
a0f2d3ef
JS
685 "0208 NameServer Rsp Data: x%x x%x\n",
686 vport->fc_flag,
687 CTreq->un.gid.Fc4Type);
688
689 lpfc_ns_rsp(vport,
690 outp,
691 CTreq->un.gid.Fc4Type,
dea3101e
JB
692 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
693 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
694 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
695 /* NameServer Rsp Error */
a58cbd52
JS
696 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
697 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
e8b62011
JS
698 lpfc_printf_vlog(vport, KERN_INFO,
699 LOG_DISCOVERY,
700 "0269 No NameServer Entries "
a58cbd52 701 "Data: x%x x%x x%x x%x\n",
a58cbd52
JS
702 CTrsp->CommandResponse.bits.CmdRsp,
703 (uint32_t) CTrsp->ReasonCode,
704 (uint32_t) CTrsp->Explanation,
705 vport->fc_flag);
706
707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
708 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
709 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
710 (uint32_t) CTrsp->ReasonCode,
711 (uint32_t) CTrsp->Explanation);
e8b62011
JS
712 } else {
713 lpfc_printf_vlog(vport, KERN_INFO,
714 LOG_DISCOVERY,
715 "0240 NameServer Rsp Error "
dea3101e 716 "Data: x%x x%x x%x x%x\n",
dea3101e
JB
717 CTrsp->CommandResponse.bits.CmdRsp,
718 (uint32_t) CTrsp->ReasonCode,
719 (uint32_t) CTrsp->Explanation,
2e0fef85 720 vport->fc_flag);
858c9f6c 721
a58cbd52 722 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
858c9f6c
JS
723 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
724 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
725 (uint32_t) CTrsp->ReasonCode,
726 (uint32_t) CTrsp->Explanation);
a58cbd52
JS
727 }
728
858c9f6c 729
dea3101e
JB
730 } else {
731 /* NameServer Rsp Error */
e8b62011
JS
732 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
733 "0241 NameServer Rsp Error "
dea3101e 734 "Data: x%x x%x x%x x%x\n",
dea3101e
JB
735 CTrsp->CommandResponse.bits.CmdRsp,
736 (uint32_t) CTrsp->ReasonCode,
737 (uint32_t) CTrsp->Explanation,
2e0fef85 738 vport->fc_flag);
858c9f6c
JS
739
740 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
741 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
742 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
743 (uint32_t) CTrsp->ReasonCode,
744 (uint32_t) CTrsp->Explanation);
dea3101e 745 }
a0f2d3ef 746 vport->gidft_inp--;
dea3101e
JB
747 }
748 /* Link up / RSCN discovery */
a0f2d3ef
JS
749 if ((vport->num_disc_nodes == 0) &&
750 (vport->gidft_inp == 0)) {
92d7f7b0
JS
751 /*
752 * The driver has cycled through all Nports in the RSCN payload.
753 * Complete the handling by cleaning up and marking the
754 * current driver state.
755 */
756 if (vport->port_state >= LPFC_DISC_AUTH) {
757 if (vport->fc_flag & FC_RSCN_MODE) {
758 lpfc_els_flush_rscn(vport);
759 spin_lock_irq(shost->host_lock);
760 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
761 spin_unlock_irq(shost->host_lock);
762 }
763 else
764 lpfc_els_flush_rscn(vport);
765 }
766
767 lpfc_disc_start(vport);
768 }
769out:
51ef4c26 770 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 771 lpfc_ct_free_iocb(phba, cmdiocb);
92d7f7b0
JS
772 return;
773}
774
311464ec 775static void
92d7f7b0
JS
776lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
777 struct lpfc_iocbq *rspiocb)
778{
779 struct lpfc_vport *vport = cmdiocb->vport;
780 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
781 IOCB_t *irsp = &rspiocb->iocb;
92d7f7b0
JS
782 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
783 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
784 struct lpfc_sli_ct_request *CTrsp;
0ff10d46 785 int did, rc, retry;
92d7f7b0
JS
786 uint8_t fbits;
787 struct lpfc_nodelist *ndlp;
788
789 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
790 did = be32_to_cpu(did);
791
858c9f6c
JS
792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
793 "GFF_ID cmpl: status:x%x/x%x did:x%x",
794 irsp->ulpStatus, irsp->un.ulpWord[4], did);
795
92d7f7b0
JS
796 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
797 /* Good status, continue checking */
798 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
799 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
800
801 if (CTrsp->CommandResponse.bits.CmdRsp ==
802 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
803 if ((fbits & FC4_FEATURE_INIT) &&
804 !(fbits & FC4_FEATURE_TARGET)) {
e8b62011
JS
805 lpfc_printf_vlog(vport, KERN_INFO,
806 LOG_DISCOVERY,
807 "0270 Skip x%x GFF "
808 "NameServer Rsp Data: (init) "
809 "x%x x%x\n", did, fbits,
810 vport->fc_rscn_id_cnt);
92d7f7b0
JS
811 goto out;
812 }
813 }
814 }
858c9f6c 815 else {
0ff10d46
JS
816 /* Check for retry */
817 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
818 retry = 1;
819 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
e3d2b802
JS
820 switch ((irsp->un.ulpWord[4] &
821 IOERR_PARAM_MASK)) {
822
0ff10d46
JS
823 case IOERR_NO_RESOURCES:
824 /* We don't increment the retry
825 * count for this case.
826 */
827 break;
828 case IOERR_LINK_DOWN:
829 case IOERR_SLI_ABORTED:
830 case IOERR_SLI_DOWN:
831 retry = 0;
832 break;
833 default:
834 cmdiocb->retry++;
835 }
836 }
837 else
838 cmdiocb->retry++;
839
840 if (retry) {
841 /* CT command is being retried */
842 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
843 cmdiocb->retry, did);
844 if (rc == 0) {
845 /* success */
846 lpfc_ct_free_iocb(phba, cmdiocb);
847 return;
848 }
849 }
850 }
e8b62011
JS
851 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
852 "0267 NameServer GFF Rsp "
853 "x%x Error (%d %d) Data: x%x x%x\n",
854 did, irsp->ulpStatus, irsp->un.ulpWord[4],
7f5f3d0d 855 vport->fc_flag, vport->fc_rscn_id_cnt);
858c9f6c
JS
856 }
857
92d7f7b0
JS
858 /* This is a target port, unregistered port, or the GFF_ID failed */
859 ndlp = lpfc_setup_disc_node(vport, did);
58da1ffb 860 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
e8b62011
JS
861 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
862 "0242 Process x%x GFF "
863 "NameServer Rsp Data: x%x x%x x%x\n",
864 did, ndlp->nlp_flag, vport->fc_flag,
865 vport->fc_rscn_id_cnt);
92d7f7b0 866 } else {
e8b62011
JS
867 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
868 "0243 Skip x%x GFF "
869 "NameServer Rsp Data: x%x x%x\n", did,
870 vport->fc_flag, vport->fc_rscn_id_cnt);
92d7f7b0 871 }
dea3101e 872out:
92d7f7b0
JS
873 /* Link up / RSCN discovery */
874 if (vport->num_disc_nodes)
875 vport->num_disc_nodes--;
876 if (vport->num_disc_nodes == 0) {
877 /*
878 * The driver has cycled through all Nports in the RSCN payload.
879 * Complete the handling by cleaning up and marking the
880 * current driver state.
881 */
882 if (vport->port_state >= LPFC_DISC_AUTH) {
883 if (vport->fc_flag & FC_RSCN_MODE) {
884 lpfc_els_flush_rscn(vport);
885 spin_lock_irq(shost->host_lock);
886 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
887 spin_unlock_irq(shost->host_lock);
888 }
889 else
890 lpfc_els_flush_rscn(vport);
891 }
892 lpfc_disc_start(vport);
893 }
858c9f6c 894 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e
JB
895 return;
896}
897
a0f2d3ef
JS
898static void
899lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
900 struct lpfc_iocbq *rspiocb)
901{
902 struct lpfc_vport *vport = cmdiocb->vport;
903 IOCB_t *irsp = &rspiocb->iocb;
904 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
905 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
906 struct lpfc_sli_ct_request *CTrsp;
907 int did;
908 struct lpfc_nodelist *ndlp;
909 uint32_t fc4_data_0, fc4_data_1;
910
911 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
912 did = be32_to_cpu(did);
913
bd2cdd5e
JS
914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
915 "GFT_ID cmpl: status:x%x/x%x did:x%x",
916 irsp->ulpStatus, irsp->un.ulpWord[4], did);
917
a0f2d3ef
JS
918 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
919 /* Good status, continue checking */
920 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
921 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
922 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
923 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
924 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
925 did, fc4_data_0, fc4_data_1);
926
927 ndlp = lpfc_findnode_did(vport, did);
928 if (ndlp) {
929 /* The bitmask value for FCP and NVME FCP types is
930 * the same because they are 32 bits distant from
931 * each other in word0 and word0.
932 */
933 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
934 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
935 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
936 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
937 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
938 "3064 Setting ndlp %p, DID x%06x with "
939 "FC4 x%08x, Data: x%08x x%08x\n",
940 ndlp, did, ndlp->nlp_fc4_type,
941 FC_TYPE_FCP, FC_TYPE_NVME);
942 }
943 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
944 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
945 lpfc_issue_els_prli(vport, ndlp, 0);
946 } else
947 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
948 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
949
950 lpfc_ct_free_iocb(phba, cmdiocb);
951}
92d7f7b0 952
dea3101e 953static void
7ee5d43e
JS
954lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
955 struct lpfc_iocbq *rspiocb)
dea3101e 956{
92d7f7b0 957 struct lpfc_vport *vport = cmdiocb->vport;
dea3101e
JB
958 struct lpfc_dmabuf *inp;
959 struct lpfc_dmabuf *outp;
960 IOCB_t *irsp;
961 struct lpfc_sli_ct_request *CTrsp;
51ef4c26 962 struct lpfc_nodelist *ndlp;
92d7f7b0
JS
963 int cmdcode, rc;
964 uint8_t retry;
858c9f6c 965 uint32_t latt;
dea3101e 966
51ef4c26
JS
967 /* First save ndlp, before we overwrite it */
968 ndlp = cmdiocb->context_un.ndlp;
969
dea3101e
JB
970 /* we pass cmdiocb to state machine which needs rspiocb as well */
971 cmdiocb->context_un.rsp_iocb = rspiocb;
972
973 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
974 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea3101e
JB
975 irsp = &rspiocb->iocb;
976
92d7f7b0
JS
977 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
978 CommandResponse.bits.CmdRsp);
dea3101e
JB
979 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
980
858c9f6c
JS
981 latt = lpfc_els_chk_latt(vport);
982
983 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
e8b62011 984 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7ee5d43e 985 "0209 CT Request completes, latt %d, "
e8b62011
JS
986 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
987 latt, irsp->ulpStatus,
988 CTrsp->CommandResponse.bits.CmdRsp,
989 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea3101e 990
858c9f6c
JS
991 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
992 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
993 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
994
92d7f7b0 995 if (irsp->ulpStatus) {
e8b62011 996 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6e15520d 997 "0268 NS cmd x%x Error (x%x x%x)\n",
e8b62011 998 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
858c9f6c 999
92d7f7b0 1000 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
e3d2b802
JS
1001 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1002 IOERR_SLI_DOWN) ||
1003 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1004 IOERR_SLI_ABORTED)))
92d7f7b0
JS
1005 goto out;
1006
1007 retry = cmdiocb->retry;
1008 if (retry >= LPFC_MAX_NS_RETRY)
1009 goto out;
1010
1011 retry++;
e8b62011 1012 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
d7c255b2 1013 "0250 Retrying NS cmd %x\n", cmdcode);
92d7f7b0
JS
1014 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1015 if (rc == 0)
1016 goto out;
1017 }
1018
1019out:
51ef4c26 1020 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 1021 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e
JB
1022 return;
1023}
1024
7ee5d43e
JS
1025static void
1026lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1027 struct lpfc_iocbq *rspiocb)
1028{
1029 IOCB_t *irsp = &rspiocb->iocb;
1030 struct lpfc_vport *vport = cmdiocb->vport;
1031
98c9ea5c
JS
1032 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1033 struct lpfc_dmabuf *outp;
1034 struct lpfc_sli_ct_request *CTrsp;
1035
1036 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1037 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1038 if (CTrsp->CommandResponse.bits.CmdRsp ==
1039 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1040 vport->ct_flags |= FC_CT_RFT_ID;
1041 }
7ee5d43e
JS
1042 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1043 return;
1044}
1045
dea3101e 1046static void
2e0fef85
JS
1047lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1048 struct lpfc_iocbq *rspiocb)
dea3101e 1049{
7ee5d43e
JS
1050 IOCB_t *irsp = &rspiocb->iocb;
1051 struct lpfc_vport *vport = cmdiocb->vport;
1052
98c9ea5c
JS
1053 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1054 struct lpfc_dmabuf *outp;
1055 struct lpfc_sli_ct_request *CTrsp;
1056
1057 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1058 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1059 if (CTrsp->CommandResponse.bits.CmdRsp ==
1060 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1061 vport->ct_flags |= FC_CT_RNN_ID;
1062 }
7ee5d43e 1063 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea3101e
JB
1064 return;
1065}
1066
92d7f7b0
JS
1067static void
1068lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1069 struct lpfc_iocbq *rspiocb)
1070{
7ee5d43e
JS
1071 IOCB_t *irsp = &rspiocb->iocb;
1072 struct lpfc_vport *vport = cmdiocb->vport;
1073
98c9ea5c
JS
1074 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1075 struct lpfc_dmabuf *outp;
1076 struct lpfc_sli_ct_request *CTrsp;
1077
1078 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1079 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1080 if (CTrsp->CommandResponse.bits.CmdRsp ==
1081 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1082 vport->ct_flags |= FC_CT_RSPN_ID;
1083 }
7ee5d43e 1084 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
92d7f7b0
JS
1085 return;
1086}
1087
dea3101e 1088static void
2e0fef85
JS
1089lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1090 struct lpfc_iocbq *rspiocb)
dea3101e 1091{
7ee5d43e
JS
1092 IOCB_t *irsp = &rspiocb->iocb;
1093 struct lpfc_vport *vport = cmdiocb->vport;
1094
98c9ea5c
JS
1095 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1096 struct lpfc_dmabuf *outp;
1097 struct lpfc_sli_ct_request *CTrsp;
1098
1099 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1100 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1101 if (CTrsp->CommandResponse.bits.CmdRsp ==
1102 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1103 vport->ct_flags |= FC_CT_RSNN_NN;
1104 }
7ee5d43e
JS
1105 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1106 return;
1107}
1108
1109static void
1110lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1111 struct lpfc_iocbq *rspiocb)
1112{
1113 struct lpfc_vport *vport = cmdiocb->vport;
1114
1115 /* even if it fails we will act as though it succeeded. */
1116 vport->ct_flags = 0;
1117 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea3101e
JB
1118 return;
1119}
1120
2fb9bd8b 1121static void
92d7f7b0
JS
1122lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1123 struct lpfc_iocbq *rspiocb)
2fb9bd8b 1124{
92d7f7b0
JS
1125 IOCB_t *irsp = &rspiocb->iocb;
1126 struct lpfc_vport *vport = cmdiocb->vport;
1127
98c9ea5c
JS
1128 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1129 struct lpfc_dmabuf *outp;
1130 struct lpfc_sli_ct_request *CTrsp;
1131
1132 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1133 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1134 if (CTrsp->CommandResponse.bits.CmdRsp ==
1135 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1136 vport->ct_flags |= FC_CT_RFF_ID;
1137 }
7ee5d43e 1138 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
2fb9bd8b
JS
1139 return;
1140}
1141
a0f2d3ef
JS
1142/*
1143 * Although the symbolic port name is thought to be an integer
1144 * as of January 18, 2016, leave it as a string until more of
1145 * the record state becomes defined.
1146 */
495a714c 1147int
92d7f7b0
JS
1148lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1149 size_t size)
1150{
1151 int n;
92d7f7b0 1152
a0f2d3ef
JS
1153 /*
1154 * Use the lpfc board number as the Symbolic Port
1155 * Name object. NPIV is not in play so this integer
1156 * value is sufficient and unique per FC-ID.
1157 */
1158 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
92d7f7b0
JS
1159 return n;
1160}
1161
a0f2d3ef 1162
92d7f7b0
JS
1163int
1164lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1165 size_t size)
dea3101e 1166{
6b5151fd 1167 char fwrev[FW_REV_STR_SIZE];
92d7f7b0 1168 int n;
dea3101e 1169
92d7f7b0 1170 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea3101e 1171
f0bf5f91 1172 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
f0bf5f91
JS
1173 if (size < n)
1174 return n;
f0bf5f91 1175
a0f2d3ef 1176 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
f0bf5f91
JS
1177 if (size < n)
1178 return n;
f0bf5f91 1179
a0f2d3ef
JS
1180 n += snprintf(symbol + n, size - n, " DV%s.",
1181 lpfc_release_version);
f0bf5f91
JS
1182 if (size < n)
1183 return n;
f0bf5f91 1184
a0f2d3ef
JS
1185 n += snprintf(symbol + n, size - n, " HN:%s.",
1186 init_utsname()->nodename);
f0bf5f91
JS
1187 if (size < n)
1188 return n;
f0bf5f91 1189
a0f2d3ef
JS
1190 /* Note :- OS name is "Linux" */
1191 n += snprintf(symbol + n, size - n, " OS:%s\n",
1192 init_utsname()->sysname);
92d7f7b0 1193 return n;
dea3101e
JB
1194}
1195
76b2c34a
JS
1196static uint32_t
1197lpfc_find_map_node(struct lpfc_vport *vport)
1198{
1199 struct lpfc_nodelist *ndlp, *next_ndlp;
1200 struct Scsi_Host *shost;
1201 uint32_t cnt = 0;
1202
1203 shost = lpfc_shost_from_vport(vport);
1204 spin_lock_irq(shost->host_lock);
1205 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1206 if (ndlp->nlp_type & NLP_FABRIC)
1207 continue;
1208 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1209 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1210 cnt++;
1211 }
1212 spin_unlock_irq(shost->host_lock);
1213 return cnt;
1214}
1215
a0f2d3ef
JS
1216/*
1217 * This routine will return the FC4 Type associated with the CT
1218 * GID_FT command.
1219 */
1220int
1221lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1222{
1223 struct lpfc_sli_ct_request *CtReq;
1224 struct lpfc_dmabuf *mp;
1225 uint32_t type;
1226
1227 mp = cmdiocb->context1;
1228 if (mp == NULL)
1229 return 0;
1230 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1231 type = (uint32_t)CtReq->un.gid.Fc4Type;
1232 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1233 return 0;
1234 return type;
1235}
1236
dea3101e
JB
1237/*
1238 * lpfc_ns_cmd
1239 * Description:
1240 * Issue Cmd to NameServer
1241 * SLI_CTNS_GID_FT
1242 * LI_CTNS_RFT_ID
1243 */
1244int
92d7f7b0
JS
1245lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1246 uint8_t retry, uint32_t context)
dea3101e 1247{
92d7f7b0 1248 struct lpfc_nodelist * ndlp;
2e0fef85 1249 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1250 struct lpfc_dmabuf *mp, *bmp;
1251 struct lpfc_sli_ct_request *CtReq;
1252 struct ulp_bde64 *bpl;
1253 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1254 struct lpfc_iocbq *) = NULL;
1255 uint32_t rsp_size = 1024;
92d7f7b0 1256 size_t size;
858c9f6c 1257 int rc = 0;
92d7f7b0
JS
1258
1259 ndlp = lpfc_findnode_did(vport, NameServer_DID);
e47c9093
JS
1260 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1261 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
858c9f6c
JS
1262 rc=1;
1263 goto ns_cmd_exit;
1264 }
dea3101e
JB
1265
1266 /* fill in BDEs for command */
1267 /* Allocate buffer for command payload */
4258e98e 1268 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1269 if (!mp) {
1270 rc=2;
dea3101e 1271 goto ns_cmd_exit;
858c9f6c 1272 }
dea3101e
JB
1273
1274 INIT_LIST_HEAD(&mp->list);
1275 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
858c9f6c
JS
1276 if (!mp->virt) {
1277 rc=3;
dea3101e 1278 goto ns_cmd_free_mp;
858c9f6c 1279 }
dea3101e
JB
1280
1281 /* Allocate buffer for Buffer ptr list */
4258e98e 1282 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1283 if (!bmp) {
1284 rc=4;
dea3101e 1285 goto ns_cmd_free_mpvirt;
858c9f6c 1286 }
dea3101e
JB
1287
1288 INIT_LIST_HEAD(&bmp->list);
1289 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
858c9f6c
JS
1290 if (!bmp->virt) {
1291 rc=5;
dea3101e 1292 goto ns_cmd_free_bmp;
858c9f6c 1293 }
dea3101e
JB
1294
1295 /* NameServer Req */
e8b62011 1296 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
a0f2d3ef
JS
1297 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1298 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1299 context);
dea3101e
JB
1300
1301 bpl = (struct ulp_bde64 *) bmp->virt;
1302 memset(bpl, 0, sizeof(struct ulp_bde64));
92d7f7b0
JS
1303 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1304 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea3101e
JB
1305 bpl->tus.f.bdeFlags = 0;
1306 if (cmdcode == SLI_CTNS_GID_FT)
1307 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
92d7f7b0
JS
1308 else if (cmdcode == SLI_CTNS_GFF_ID)
1309 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
a0f2d3ef
JS
1310 else if (cmdcode == SLI_CTNS_GFT_ID)
1311 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
dea3101e
JB
1312 else if (cmdcode == SLI_CTNS_RFT_ID)
1313 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1314 else if (cmdcode == SLI_CTNS_RNN_ID)
1315 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
92d7f7b0
JS
1316 else if (cmdcode == SLI_CTNS_RSPN_ID)
1317 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea3101e
JB
1318 else if (cmdcode == SLI_CTNS_RSNN_NN)
1319 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
7ee5d43e
JS
1320 else if (cmdcode == SLI_CTNS_DA_ID)
1321 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
2fb9bd8b
JS
1322 else if (cmdcode == SLI_CTNS_RFF_ID)
1323 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea3101e
JB
1324 else
1325 bpl->tus.f.bdeSize = 0;
1326 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1327
1328 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
4258e98e 1329 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
dea3101e
JB
1330 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1331 CtReq->RevisionId.bits.InId = 0;
1332 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1333 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1334 CtReq->CommandResponse.bits.Size = 0;
1335 switch (cmdcode) {
1336 case SLI_CTNS_GID_FT:
1337 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1338 cpu_to_be16(SLI_CTNS_GID_FT);
a0f2d3ef
JS
1339 CtReq->un.gid.Fc4Type = context;
1340
92d7f7b0 1341 if (vport->port_state < LPFC_NS_QRY)
2e0fef85
JS
1342 vport->port_state = LPFC_NS_QRY;
1343 lpfc_set_disctmo(vport);
dea3101e
JB
1344 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1345 rsp_size = FC_MAX_NS_RSP;
1346 break;
1347
92d7f7b0
JS
1348 case SLI_CTNS_GFF_ID:
1349 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1350 cpu_to_be16(SLI_CTNS_GFF_ID);
09372820 1351 CtReq->un.gff.PortId = cpu_to_be32(context);
92d7f7b0
JS
1352 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1353 break;
1354
a0f2d3ef
JS
1355 case SLI_CTNS_GFT_ID:
1356 CtReq->CommandResponse.bits.CmdRsp =
1357 cpu_to_be16(SLI_CTNS_GFT_ID);
1358 CtReq->un.gft.PortId = cpu_to_be32(context);
1359 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1360 break;
1361
dea3101e 1362 case SLI_CTNS_RFT_ID:
7ee5d43e 1363 vport->ct_flags &= ~FC_CT_RFT_ID;
dea3101e 1364 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1365 cpu_to_be16(SLI_CTNS_RFT_ID);
09372820 1366 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
a0f2d3ef
JS
1367
1368 /* Register FC4 FCP type if enabled. */
1369 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1370 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1371 CtReq->un.rft.fcpReg = 1;
1372
1373 /* Register NVME type if enabled. Defined LE and swapped.
1374 * rsvd[0] is used as word1 because of the hard-coded
1375 * word0 usage in the ct_request data structure.
1376 */
1377 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1378 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1379 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1380
dea3101e
JB
1381 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1382 break;
1383
1384 case SLI_CTNS_RNN_ID:
7ee5d43e 1385 vport->ct_flags &= ~FC_CT_RNN_ID;
dea3101e 1386 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1387 cpu_to_be16(SLI_CTNS_RNN_ID);
09372820 1388 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
2e0fef85 1389 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
4258e98e 1390 sizeof(struct lpfc_name));
dea3101e
JB
1391 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1392 break;
1393
92d7f7b0 1394 case SLI_CTNS_RSPN_ID:
7ee5d43e 1395 vport->ct_flags &= ~FC_CT_RSPN_ID;
92d7f7b0 1396 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1397 cpu_to_be16(SLI_CTNS_RSPN_ID);
09372820 1398 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
92d7f7b0
JS
1399 size = sizeof(CtReq->un.rspn.symbname);
1400 CtReq->un.rspn.len =
1401 lpfc_vport_symbolic_port_name(vport,
1402 CtReq->un.rspn.symbname, size);
1403 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1404 break;
dea3101e 1405 case SLI_CTNS_RSNN_NN:
7ee5d43e 1406 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea3101e 1407 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1408 cpu_to_be16(SLI_CTNS_RSNN_NN);
2e0fef85 1409 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
4258e98e 1410 sizeof(struct lpfc_name));
92d7f7b0
JS
1411 size = sizeof(CtReq->un.rsnn.symbname);
1412 CtReq->un.rsnn.len =
1413 lpfc_vport_symbolic_node_name(vport,
1414 CtReq->un.rsnn.symbname, size);
dea3101e
JB
1415 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1416 break;
7ee5d43e
JS
1417 case SLI_CTNS_DA_ID:
1418 /* Implement DA_ID Nameserver request */
1419 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1420 cpu_to_be16(SLI_CTNS_DA_ID);
09372820 1421 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
7ee5d43e
JS
1422 cmpl = lpfc_cmpl_ct_cmd_da_id;
1423 break;
92d7f7b0 1424 case SLI_CTNS_RFF_ID:
7ee5d43e 1425 vport->ct_flags &= ~FC_CT_RFF_ID;
92d7f7b0 1426 CtReq->CommandResponse.bits.CmdRsp =
76b2c34a 1427 cpu_to_be16(SLI_CTNS_RFF_ID);
a419aef8 1428 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
92d7f7b0 1429 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
a0f2d3ef
JS
1430
1431 /* The driver always supports FC_TYPE_FCP. However, the
1432 * caller can specify NVME (type x28) as well. But only
1433 * these that FC4 type is supported.
1434 */
1435 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1436 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1437 (context == FC_TYPE_NVME)) {
8c258641
JS
1438 if ((vport == phba->pport) && phba->nvmet_support) {
1439 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1440 FC4_FEATURE_NVME_DISC);
d613b6a7 1441 lpfc_nvmet_update_targetport(phba);
8c258641
JS
1442 } else {
1443 lpfc_nvme_update_localport(vport);
1444 }
a0f2d3ef
JS
1445 CtReq->un.rff.type_code = context;
1446
1447 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1448 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1449 (context == FC_TYPE_FCP))
1450 CtReq->un.rff.type_code = context;
1451
1452 else
1453 goto ns_cmd_free_bmpvirt;
1454
92d7f7b0
JS
1455 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1456 break;
dea3101e 1457 }
e47c9093
JS
1458 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1459 * to hold ndlp reference for the corresponding callback function.
1460 */
858c9f6c 1461 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea3101e 1462 /* On success, The cmpl function will free the buffers */
858c9f6c
JS
1463 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1464 "Issue CT cmd: cmd:x%x did:x%x",
1465 cmdcode, ndlp->nlp_DID, 0);
dea3101e 1466 return 0;
858c9f6c 1467 }
858c9f6c 1468 rc=6;
e47c9093
JS
1469
1470 /* Decrement ndlp reference count to release ndlp reference held
1471 * for the failed command's callback function.
1472 */
51ef4c26 1473 lpfc_nlp_put(ndlp);
e47c9093 1474
a0f2d3ef 1475ns_cmd_free_bmpvirt:
dea3101e
JB
1476 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1477ns_cmd_free_bmp:
1478 kfree(bmp);
1479ns_cmd_free_mpvirt:
1480 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1481ns_cmd_free_mp:
1482 kfree(mp);
1483ns_cmd_exit:
e8b62011
JS
1484 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1485 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1486 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea3101e
JB
1487 return 1;
1488}
1489
4258e98e
JS
1490/**
1491 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1492 * @phba: Pointer to HBA context object.
1493 * @cmdiocb: Pointer to the command IOCBQ.
1494 * @rspiocb: Pointer to the response IOCBQ.
1495 *
1496 * This function to handle the completion of a driver initiated FDMI
1497 * CT command issued during discovery.
1498 */
dea3101e 1499static void
4258e98e
JS
1500lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1501 struct lpfc_iocbq *rspiocb)
dea3101e 1502{
4258e98e 1503 struct lpfc_vport *vport = cmdiocb->vport;
dea3101e
JB
1504 struct lpfc_dmabuf *inp = cmdiocb->context1;
1505 struct lpfc_dmabuf *outp = cmdiocb->context2;
dea3101e 1506 struct lpfc_sli_ct_request *CTcmd = inp->virt;
4258e98e 1507 struct lpfc_sli_ct_request *CTrsp = outp->virt;
dea3101e
JB
1508 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1509 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
858c9f6c 1510 IOCB_t *irsp = &rspiocb->iocb;
4258e98e
JS
1511 struct lpfc_nodelist *ndlp;
1512 uint32_t latt, cmd, err;
858c9f6c
JS
1513
1514 latt = lpfc_els_chk_latt(vport);
858c9f6c
JS
1515 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1516 "FDMI cmpl: status:x%x/x%x latt:%d",
1517 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1518
1519 if (latt || irsp->ulpStatus) {
4258e98e
JS
1520
1521 /* Look for a retryable error */
1522 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1523 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1524 case IOERR_SLI_ABORTED:
1525 case IOERR_ABORT_IN_PROGRESS:
1526 case IOERR_SEQUENCE_TIMEOUT:
1527 case IOERR_ILLEGAL_FRAME:
1528 case IOERR_NO_RESOURCES:
1529 case IOERR_ILLEGAL_COMMAND:
1530 cmdiocb->retry++;
1531 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1532 break;
1533
1534 /* Retry the same FDMI command */
1535 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1536 cmdiocb, 0);
1537 if (err == IOCB_ERROR)
1538 break;
1539 return;
1540 default:
1541 break;
1542 }
1543 }
1544
e8b62011
JS
1545 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1546 "0229 FDMI cmd %04x failed, latt = %d "
1547 "ulpStatus: x%x, rid x%x\n",
1548 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1549 irsp->un.ulpWord[4]);
858c9f6c 1550 }
4258e98e 1551 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e 1552
2e0fef85 1553 ndlp = lpfc_findnode_did(vport, FDMI_DID);
e47c9093 1554 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
4258e98e 1555 return;
e47c9093 1556
4258e98e
JS
1557 /* Check for a CT LS_RJT response */
1558 cmd = be16_to_cpu(fdmi_cmd);
76b2c34a 1559 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
dea3101e 1560 /* FDMI rsp failed */
e8b62011 1561 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4258e98e
JS
1562 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1563
1564 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1565 switch (cmd) {
1566 case SLI_MGMT_RHBA:
1567 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1568 /* Fallback to FDMI-1 */
1569 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1570 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1571 /* Start over */
1572 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1573 }
1574 return;
1575
1576 case SLI_MGMT_RPRT:
1577 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1578 /* Fallback to FDMI-1 */
1579 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1580 /* Start over */
1581 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1582 }
1583 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1584 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1585 /* Retry the same command */
1586 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1587 }
1588 return;
1589
1590 case SLI_MGMT_RPA:
1591 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1592 /* Fallback to FDMI-1 */
1593 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1594 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1595 /* Start over */
1596 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1597 }
1598 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1599 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1600 /* Retry the same command */
1601 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1602 }
1603 return;
1604 }
dea3101e
JB
1605 }
1606
4258e98e
JS
1607 /*
1608 * On success, need to cycle thru FDMI registration for discovery
1609 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1610 * DPRT -> RPRT (vports)
1611 */
1612 switch (cmd) {
1613 case SLI_MGMT_RHBA:
1614 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1615 break;
1616
1617 case SLI_MGMT_DHBA:
1618 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1619 break;
1620
1621 case SLI_MGMT_DPRT:
1622 if (vport->port_type == LPFC_PHYSICAL_PORT)
1623 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1624 else
1625 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1626 break;
1627 }
1628 return;
76b2c34a
JS
1629}
1630
4258e98e
JS
1631
1632/**
1633 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1634 * @vport: pointer to a host virtual N_Port data structure.
1635 *
1636 * Called from hbeat timeout routine to check if the number of discovered
1637 * ports has changed. If so, re-register thar port Attribute.
1638 */
1639void
1640lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
76b2c34a 1641{
4258e98e 1642 struct lpfc_hba *phba = vport->phba;
76b2c34a 1643 struct lpfc_nodelist *ndlp;
4258e98e 1644 uint16_t cnt;
76b2c34a 1645
4258e98e
JS
1646 if (!lpfc_is_link_up(phba))
1647 return;
1648
a03a4219
JS
1649 /* Must be connected to a Fabric */
1650 if (!(vport->fc_flag & FC_FABRIC))
1651 return;
1652
4258e98e
JS
1653 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1654 return;
1655
1656 cnt = lpfc_find_map_node(vport);
1657 if (cnt == vport->fdmi_num_disc)
1658 return;
76b2c34a
JS
1659
1660 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1661 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1662 return;
1663
4258e98e
JS
1664 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1665 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1666 LPFC_FDMI_PORT_ATTR_num_disc);
1667 } else {
1668 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1669 LPFC_FDMI_PORT_ATTR_num_disc);
1670 }
1671}
dea3101e 1672
4258e98e 1673/* Routines for all individual HBA attributes */
bd4b3e5c 1674static int
4258e98e
JS
1675lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1676{
1677 struct lpfc_fdmi_attr_entry *ae;
1678 uint32_t size;
dea3101e 1679
4258e98e
JS
1680 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1681 memset(ae, 0, sizeof(struct lpfc_name));
1682
1683 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1684 sizeof(struct lpfc_name));
1685 size = FOURBYTES + sizeof(struct lpfc_name);
1686 ad->AttrLen = cpu_to_be16(size);
1687 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1688 return size;
1689}
bd4b3e5c 1690static int
4258e98e
JS
1691lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1692 struct lpfc_fdmi_attr_def *ad)
1693{
1694 struct lpfc_fdmi_attr_entry *ae;
1695 uint32_t len, size;
1696
1697 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1698 memset(ae, 0, 256);
1699
1700 strncpy(ae->un.AttrString,
1701 "Emulex Corporation",
1702 sizeof(ae->un.AttrString));
1703 len = strnlen(ae->un.AttrString,
1704 sizeof(ae->un.AttrString));
1705 len += (len & 3) ? (4 - (len & 3)) : 4;
1706 size = FOURBYTES + len;
1707 ad->AttrLen = cpu_to_be16(size);
1708 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1709 return size;
1710}
1711
bd4b3e5c 1712static int
4258e98e
JS
1713lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1714{
1715 struct lpfc_hba *phba = vport->phba;
1716 struct lpfc_fdmi_attr_entry *ae;
1717 uint32_t len, size;
1718
1719 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1720 memset(ae, 0, 256);
1721
1722 strncpy(ae->un.AttrString, phba->SerialNumber,
1723 sizeof(ae->un.AttrString));
1724 len = strnlen(ae->un.AttrString,
1725 sizeof(ae->un.AttrString));
1726 len += (len & 3) ? (4 - (len & 3)) : 4;
1727 size = FOURBYTES + len;
1728 ad->AttrLen = cpu_to_be16(size);
1729 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1730 return size;
1731}
1732
bd4b3e5c 1733static int
4258e98e
JS
1734lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1735 struct lpfc_fdmi_attr_def *ad)
1736{
1737 struct lpfc_hba *phba = vport->phba;
1738 struct lpfc_fdmi_attr_entry *ae;
1739 uint32_t len, size;
1740
1741 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1742 memset(ae, 0, 256);
1743
1744 strncpy(ae->un.AttrString, phba->ModelName,
1745 sizeof(ae->un.AttrString));
1746 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1747 len += (len & 3) ? (4 - (len & 3)) : 4;
1748 size = FOURBYTES + len;
1749 ad->AttrLen = cpu_to_be16(size);
1750 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1751 return size;
1752}
1753
bd4b3e5c 1754static int
4258e98e
JS
1755lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1756 struct lpfc_fdmi_attr_def *ad)
1757{
1758 struct lpfc_hba *phba = vport->phba;
1759 struct lpfc_fdmi_attr_entry *ae;
1760 uint32_t len, size;
1761
1762 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1763 memset(ae, 0, 256);
1764
1765 strncpy(ae->un.AttrString, phba->ModelDesc,
1766 sizeof(ae->un.AttrString));
1767 len = strnlen(ae->un.AttrString,
1768 sizeof(ae->un.AttrString));
1769 len += (len & 3) ? (4 - (len & 3)) : 4;
1770 size = FOURBYTES + len;
1771 ad->AttrLen = cpu_to_be16(size);
1772 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1773 return size;
1774}
1775
bd4b3e5c 1776static int
4258e98e
JS
1777lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1778 struct lpfc_fdmi_attr_def *ad)
1779{
1780 struct lpfc_hba *phba = vport->phba;
1781 lpfc_vpd_t *vp = &phba->vpd;
1782 struct lpfc_fdmi_attr_entry *ae;
1783 uint32_t i, j, incr, size;
1784
1785 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1786 memset(ae, 0, 256);
1787
1788 /* Convert JEDEC ID to ascii for hardware version */
1789 incr = vp->rev.biuRev;
1790 for (i = 0; i < 8; i++) {
1791 j = (incr & 0xf);
1792 if (j <= 9)
1793 ae->un.AttrString[7 - i] =
1794 (char)((uint8_t) 0x30 +
1795 (uint8_t) j);
1796 else
1797 ae->un.AttrString[7 - i] =
1798 (char)((uint8_t) 0x61 +
1799 (uint8_t) (j - 10));
1800 incr = (incr >> 4);
1801 }
1802 size = FOURBYTES + 8;
1803 ad->AttrLen = cpu_to_be16(size);
1804 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1805 return size;
1806}
1807
bd4b3e5c 1808static int
4258e98e
JS
1809lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1810 struct lpfc_fdmi_attr_def *ad)
1811{
1812 struct lpfc_fdmi_attr_entry *ae;
1813 uint32_t len, size;
1814
1815 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1816 memset(ae, 0, 256);
1817
1818 strncpy(ae->un.AttrString, lpfc_release_version,
1819 sizeof(ae->un.AttrString));
1820 len = strnlen(ae->un.AttrString,
1821 sizeof(ae->un.AttrString));
1822 len += (len & 3) ? (4 - (len & 3)) : 4;
1823 size = FOURBYTES + len;
1824 ad->AttrLen = cpu_to_be16(size);
1825 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1826 return size;
1827}
1828
bd4b3e5c 1829static int
4258e98e
JS
1830lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1831 struct lpfc_fdmi_attr_def *ad)
1832{
1833 struct lpfc_hba *phba = vport->phba;
1834 struct lpfc_fdmi_attr_entry *ae;
1835 uint32_t len, size;
1836
1837 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1838 memset(ae, 0, 256);
1839
1840 if (phba->sli_rev == LPFC_SLI_REV4)
1841 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1842 else
1843 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1844 sizeof(ae->un.AttrString));
1845 len = strnlen(ae->un.AttrString,
1846 sizeof(ae->un.AttrString));
1847 len += (len & 3) ? (4 - (len & 3)) : 4;
1848 size = FOURBYTES + len;
1849 ad->AttrLen = cpu_to_be16(size);
1850 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1851 return size;
1852}
1853
bd4b3e5c 1854static int
4258e98e
JS
1855lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1856 struct lpfc_fdmi_attr_def *ad)
1857{
1858 struct lpfc_hba *phba = vport->phba;
1859 struct lpfc_fdmi_attr_entry *ae;
1860 uint32_t len, size;
1861
1862 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1863 memset(ae, 0, 256);
1864
1865 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1866 len = strnlen(ae->un.AttrString,
1867 sizeof(ae->un.AttrString));
1868 len += (len & 3) ? (4 - (len & 3)) : 4;
1869 size = FOURBYTES + len;
1870 ad->AttrLen = cpu_to_be16(size);
1871 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1872 return size;
1873}
1874
bd4b3e5c 1875static int
4258e98e
JS
1876lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1877 struct lpfc_fdmi_attr_def *ad)
1878{
1879 struct lpfc_fdmi_attr_entry *ae;
1880 uint32_t len, size;
1881
1882 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1883 memset(ae, 0, 256);
1884
1885 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1886 init_utsname()->sysname,
1887 init_utsname()->release,
1888 init_utsname()->version);
1889
1890 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1891 len += (len & 3) ? (4 - (len & 3)) : 4;
1892 size = FOURBYTES + len;
1893 ad->AttrLen = cpu_to_be16(size);
1894 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1895 return size;
1896}
1897
bd4b3e5c 1898static int
4258e98e
JS
1899lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1900 struct lpfc_fdmi_attr_def *ad)
1901{
1902 struct lpfc_fdmi_attr_entry *ae;
1903 uint32_t size;
1904
1905 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1906
1907 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1908 size = FOURBYTES + sizeof(uint32_t);
1909 ad->AttrLen = cpu_to_be16(size);
1910 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1911 return size;
1912}
1913
bd4b3e5c 1914static int
4258e98e
JS
1915lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1916 struct lpfc_fdmi_attr_def *ad)
1917{
1918 struct lpfc_fdmi_attr_entry *ae;
1919 uint32_t len, size;
1920
1921 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1922 memset(ae, 0, 256);
1923
1924 len = lpfc_vport_symbolic_node_name(vport,
1925 ae->un.AttrString, 256);
1926 len += (len & 3) ? (4 - (len & 3)) : 4;
1927 size = FOURBYTES + len;
1928 ad->AttrLen = cpu_to_be16(size);
1929 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1930 return size;
1931}
1932
bd4b3e5c 1933static int
4258e98e
JS
1934lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
1935 struct lpfc_fdmi_attr_def *ad)
1936{
1937 struct lpfc_fdmi_attr_entry *ae;
1938 uint32_t size;
1939
1940 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1941
1942 /* Nothing is defined for this currently */
1943 ae->un.AttrInt = cpu_to_be32(0);
1944 size = FOURBYTES + sizeof(uint32_t);
1945 ad->AttrLen = cpu_to_be16(size);
1946 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
1947 return size;
1948}
1949
bd4b3e5c 1950static int
4258e98e
JS
1951lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
1952 struct lpfc_fdmi_attr_def *ad)
1953{
1954 struct lpfc_fdmi_attr_entry *ae;
1955 uint32_t size;
1956
1957 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1958
1959 /* Each driver instance corresponds to a single port */
1960 ae->un.AttrInt = cpu_to_be32(1);
1961 size = FOURBYTES + sizeof(uint32_t);
1962 ad->AttrLen = cpu_to_be16(size);
1963 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
1964 return size;
1965}
1966
bd4b3e5c 1967static int
4258e98e
JS
1968lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
1969 struct lpfc_fdmi_attr_def *ad)
1970{
1971 struct lpfc_fdmi_attr_entry *ae;
1972 uint32_t size;
1973
1974 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1975 memset(ae, 0, sizeof(struct lpfc_name));
1976
1977 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
1978 sizeof(struct lpfc_name));
1979 size = FOURBYTES + sizeof(struct lpfc_name);
1980 ad->AttrLen = cpu_to_be16(size);
1981 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
1982 return size;
1983}
1984
bd4b3e5c 1985static int
4258e98e
JS
1986lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
1987 struct lpfc_fdmi_attr_def *ad)
1988{
1989 struct lpfc_hba *phba = vport->phba;
1990 struct lpfc_fdmi_attr_entry *ae;
1991 uint32_t len, size;
1992
1993 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1994 memset(ae, 0, 256);
1995
1996 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1997 len = strnlen(ae->un.AttrString,
1998 sizeof(ae->un.AttrString));
1999 len += (len & 3) ? (4 - (len & 3)) : 4;
2000 size = FOURBYTES + len;
2001 ad->AttrLen = cpu_to_be16(size);
2002 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2003 return size;
2004}
2005
bd4b3e5c 2006static int
4258e98e
JS
2007lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2008 struct lpfc_fdmi_attr_def *ad)
2009{
2010 struct lpfc_fdmi_attr_entry *ae;
2011 uint32_t size;
2012
2013 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2014
2015 /* Driver doesn't have access to this information */
2016 ae->un.AttrInt = cpu_to_be32(0);
2017 size = FOURBYTES + sizeof(uint32_t);
2018 ad->AttrLen = cpu_to_be16(size);
2019 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2020 return size;
2021}
2022
bd4b3e5c 2023static int
4258e98e
JS
2024lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2025 struct lpfc_fdmi_attr_def *ad)
2026{
2027 struct lpfc_fdmi_attr_entry *ae;
2028 uint32_t len, size;
2029
2030 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2031 memset(ae, 0, 256);
2032
2033 strncpy(ae->un.AttrString, "EMULEX",
2034 sizeof(ae->un.AttrString));
2035 len = strnlen(ae->un.AttrString,
2036 sizeof(ae->un.AttrString));
2037 len += (len & 3) ? (4 - (len & 3)) : 4;
2038 size = FOURBYTES + len;
2039 ad->AttrLen = cpu_to_be16(size);
2040 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2041 return size;
2042}
2043
2044/* Routines for all individual PORT attributes */
bd4b3e5c 2045static int
4258e98e
JS
2046lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2047 struct lpfc_fdmi_attr_def *ad)
2048{
2049 struct lpfc_fdmi_attr_entry *ae;
2050 uint32_t size;
2051
2052 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2053 memset(ae, 0, 32);
2054
2055 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2056 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2057 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2058 size = FOURBYTES + 32;
2059 ad->AttrLen = cpu_to_be16(size);
2060 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2061 return size;
2062}
2063
bd4b3e5c 2064static int
4258e98e
JS
2065lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2066 struct lpfc_fdmi_attr_def *ad)
2067{
2068 struct lpfc_hba *phba = vport->phba;
2069 struct lpfc_fdmi_attr_entry *ae;
2070 uint32_t size;
2071
2072 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2073
2074 ae->un.AttrInt = 0;
a085e87c
JS
2075 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2076 if (phba->lmt & LMT_32Gb)
2077 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2078 if (phba->lmt & LMT_16Gb)
2079 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2080 if (phba->lmt & LMT_10Gb)
2081 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2082 if (phba->lmt & LMT_8Gb)
2083 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2084 if (phba->lmt & LMT_4Gb)
2085 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2086 if (phba->lmt & LMT_2Gb)
2087 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2088 if (phba->lmt & LMT_1Gb)
2089 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2090 } else {
2091 /* FCoE links support only one speed */
2092 switch (phba->fc_linkspeed) {
2093 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2094 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2095 break;
2096 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2097 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2098 break;
2099 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2100 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2101 break;
2102 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2103 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2104 break;
2105 }
2106 }
4258e98e
JS
2107 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2108 size = FOURBYTES + sizeof(uint32_t);
2109 ad->AttrLen = cpu_to_be16(size);
2110 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2111 return size;
2112}
2113
bd4b3e5c 2114static int
4258e98e
JS
2115lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2116 struct lpfc_fdmi_attr_def *ad)
2117{
2118 struct lpfc_hba *phba = vport->phba;
2119 struct lpfc_fdmi_attr_entry *ae;
2120 uint32_t size;
2121
2122 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2123
a085e87c
JS
2124 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2125 switch (phba->fc_linkspeed) {
2126 case LPFC_LINK_SPEED_1GHZ:
2127 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2128 break;
2129 case LPFC_LINK_SPEED_2GHZ:
2130 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2131 break;
2132 case LPFC_LINK_SPEED_4GHZ:
2133 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2134 break;
2135 case LPFC_LINK_SPEED_8GHZ:
2136 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2137 break;
2138 case LPFC_LINK_SPEED_10GHZ:
2139 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2140 break;
2141 case LPFC_LINK_SPEED_16GHZ:
2142 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2143 break;
2144 case LPFC_LINK_SPEED_32GHZ:
2145 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2146 break;
2147 default:
2148 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2149 break;
2150 }
2151 } else {
2152 switch (phba->fc_linkspeed) {
2153 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2154 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2155 break;
2156 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2157 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2158 break;
2159 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2160 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2161 break;
2162 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2163 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2164 break;
2165 default:
2166 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2167 break;
2168 }
dea3101e 2169 }
a085e87c 2170
4258e98e
JS
2171 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2172 size = FOURBYTES + sizeof(uint32_t);
2173 ad->AttrLen = cpu_to_be16(size);
2174 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2175 return size;
2176}
2177
bd4b3e5c 2178static int
4258e98e
JS
2179lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2180 struct lpfc_fdmi_attr_def *ad)
2181{
2182 struct serv_parm *hsp;
2183 struct lpfc_fdmi_attr_entry *ae;
2184 uint32_t size;
2185
2186 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2187
2188 hsp = (struct serv_parm *)&vport->fc_sparam;
2189 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2190 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2191 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2192 size = FOURBYTES + sizeof(uint32_t);
2193 ad->AttrLen = cpu_to_be16(size);
2194 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2195 return size;
2196}
2197
bd4b3e5c 2198static int
4258e98e
JS
2199lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2200 struct lpfc_fdmi_attr_def *ad)
2201{
2202 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2203 struct lpfc_fdmi_attr_entry *ae;
2204 uint32_t len, size;
2205
2206 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2207 memset(ae, 0, 256);
2208
2209 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2210 "/sys/class/scsi_host/host%d", shost->host_no);
2211 len = strnlen((char *)ae->un.AttrString,
2212 sizeof(ae->un.AttrString));
2213 len += (len & 3) ? (4 - (len & 3)) : 4;
2214 size = FOURBYTES + len;
2215 ad->AttrLen = cpu_to_be16(size);
2216 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2217 return size;
2218}
2219
bd4b3e5c 2220static int
4258e98e
JS
2221lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2222 struct lpfc_fdmi_attr_def *ad)
2223{
2224 struct lpfc_fdmi_attr_entry *ae;
2225 uint32_t len, size;
2226
2227 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2228 memset(ae, 0, 256);
2229
2230 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2231 init_utsname()->nodename);
2232
2233 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2234 len += (len & 3) ? (4 - (len & 3)) : 4;
2235 size = FOURBYTES + len;
2236 ad->AttrLen = cpu_to_be16(size);
2237 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2238 return size;
2239}
2240
bd4b3e5c 2241static int
4258e98e
JS
2242lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2243 struct lpfc_fdmi_attr_def *ad)
2244{
2245 struct lpfc_fdmi_attr_entry *ae;
2246 uint32_t size;
2247
2248 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2249 memset(ae, 0, sizeof(struct lpfc_name));
2250
2251 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2252 sizeof(struct lpfc_name));
2253 size = FOURBYTES + sizeof(struct lpfc_name);
2254 ad->AttrLen = cpu_to_be16(size);
2255 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2256 return size;
2257}
2258
bd4b3e5c 2259static int
4258e98e
JS
2260lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2261 struct lpfc_fdmi_attr_def *ad)
2262{
2263 struct lpfc_fdmi_attr_entry *ae;
2264 uint32_t size;
2265
2266 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2267 memset(ae, 0, sizeof(struct lpfc_name));
2268
2269 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2270 sizeof(struct lpfc_name));
2271 size = FOURBYTES + sizeof(struct lpfc_name);
2272 ad->AttrLen = cpu_to_be16(size);
2273 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2274 return size;
2275}
2276
bd4b3e5c 2277static int
4258e98e
JS
2278lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2279 struct lpfc_fdmi_attr_def *ad)
2280{
2281 struct lpfc_fdmi_attr_entry *ae;
2282 uint32_t len, size;
2283
2284 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2285 memset(ae, 0, 256);
2286
2287 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2288 len += (len & 3) ? (4 - (len & 3)) : 4;
2289 size = FOURBYTES + len;
2290 ad->AttrLen = cpu_to_be16(size);
2291 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2292 return size;
2293}
2294
bd4b3e5c 2295static int
4258e98e
JS
2296lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2297 struct lpfc_fdmi_attr_def *ad)
2298{
2299 struct lpfc_hba *phba = vport->phba;
2300 struct lpfc_fdmi_attr_entry *ae;
2301 uint32_t size;
2302
2303 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2304 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2305 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2306 else
2307 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2308 size = FOURBYTES + sizeof(uint32_t);
2309 ad->AttrLen = cpu_to_be16(size);
2310 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2311 return size;
2312}
2313
bd4b3e5c 2314static int
4258e98e
JS
2315lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2316 struct lpfc_fdmi_attr_def *ad)
2317{
2318 struct lpfc_fdmi_attr_entry *ae;
2319 uint32_t size;
2320
2321 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2322 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2323 size = FOURBYTES + sizeof(uint32_t);
2324 ad->AttrLen = cpu_to_be16(size);
2325 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2326 return size;
2327}
2328
bd4b3e5c 2329static int
4258e98e
JS
2330lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2331 struct lpfc_fdmi_attr_def *ad)
2332{
2333 struct lpfc_fdmi_attr_entry *ae;
2334 uint32_t size;
2335
2336 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2337 memset(ae, 0, sizeof(struct lpfc_name));
2338
2339 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2340 sizeof(struct lpfc_name));
2341 size = FOURBYTES + sizeof(struct lpfc_name);
2342 ad->AttrLen = cpu_to_be16(size);
2343 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2344 return size;
2345}
2346
bd4b3e5c 2347static int
4258e98e
JS
2348lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2349 struct lpfc_fdmi_attr_def *ad)
2350{
2351 struct lpfc_fdmi_attr_entry *ae;
2352 uint32_t size;
2353
2354 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2355 memset(ae, 0, 32);
2356
2357 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2358 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2359 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2360 size = FOURBYTES + 32;
2361 ad->AttrLen = cpu_to_be16(size);
2362 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2363 return size;
2364}
2365
bd4b3e5c 2366static int
4258e98e
JS
2367lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2368 struct lpfc_fdmi_attr_def *ad)
2369{
2370 struct lpfc_fdmi_attr_entry *ae;
2371 uint32_t size;
2372
2373 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2374 /* Link Up - operational */
2375 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2376 size = FOURBYTES + sizeof(uint32_t);
2377 ad->AttrLen = cpu_to_be16(size);
2378 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2379 return size;
2380}
2381
bd4b3e5c 2382static int
4258e98e
JS
2383lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2384 struct lpfc_fdmi_attr_def *ad)
2385{
2386 struct lpfc_fdmi_attr_entry *ae;
2387 uint32_t size;
2388
2389 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2390 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2391 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2392 size = FOURBYTES + sizeof(uint32_t);
2393 ad->AttrLen = cpu_to_be16(size);
2394 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2395 return size;
2396}
2397
bd4b3e5c 2398static int
4258e98e
JS
2399lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2400 struct lpfc_fdmi_attr_def *ad)
2401{
2402 struct lpfc_fdmi_attr_entry *ae;
2403 uint32_t size;
2404
2405 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2406 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2407 size = FOURBYTES + sizeof(uint32_t);
2408 ad->AttrLen = cpu_to_be16(size);
2409 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2410 return size;
2411}
2412
bd4b3e5c 2413static int
4258e98e
JS
2414lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2415 struct lpfc_fdmi_attr_def *ad)
2416{
2417 struct lpfc_fdmi_attr_entry *ae;
2418 uint32_t len, size;
2419
2420 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2421 memset(ae, 0, 256);
2422
2423 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2424 sizeof(ae->un.AttrString));
2425 len = strnlen(ae->un.AttrString,
2426 sizeof(ae->un.AttrString));
2427 len += (len & 3) ? (4 - (len & 3)) : 4;
2428 size = FOURBYTES + len;
2429 ad->AttrLen = cpu_to_be16(size);
2430 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2431 return size;
2432}
2433
bd4b3e5c 2434static int
4258e98e
JS
2435lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2436 struct lpfc_fdmi_attr_def *ad)
2437{
2438 struct lpfc_fdmi_attr_entry *ae;
2439 uint32_t size;
2440
2441 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2442 memset(ae, 0, 256);
2443
2444 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2445 sizeof(struct lpfc_name));
2446 memcpy((((uint8_t *)&ae->un.AttrString) +
2447 sizeof(struct lpfc_name)),
2448 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2449 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2450 ad->AttrLen = cpu_to_be16(size);
2451 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2452 return size;
2453}
2454
bd4b3e5c 2455static int
4258e98e
JS
2456lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2457 struct lpfc_fdmi_attr_def *ad)
2458{
2459 struct lpfc_fdmi_attr_entry *ae;
2460 uint32_t len, size;
2461
2462 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2463 memset(ae, 0, 256);
2464
56204984 2465 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
4258e98e
JS
2466 sizeof(ae->un.AttrString));
2467 len = strnlen(ae->un.AttrString,
2468 sizeof(ae->un.AttrString));
2469 len += (len & 3) ? (4 - (len & 3)) : 4;
2470 size = FOURBYTES + len;
2471 ad->AttrLen = cpu_to_be16(size);
2472 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2473 return size;
2474}
2475
bd4b3e5c 2476static int
4258e98e
JS
2477lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2478 struct lpfc_fdmi_attr_def *ad)
2479{
2480 struct lpfc_hba *phba = vport->phba;
2481 struct lpfc_fdmi_attr_entry *ae;
2482 uint32_t len, size;
2483
2484 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2485 memset(ae, 0, 256);
2486
2487 strncpy(ae->un.AttrString, phba->ModelName,
2488 sizeof(ae->un.AttrString));
2489 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2490 len += (len & 3) ? (4 - (len & 3)) : 4;
2491 size = FOURBYTES + len;
2492 ad->AttrLen = cpu_to_be16(size);
2493 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2494 return size;
2495}
2496
bd4b3e5c 2497static int
4258e98e
JS
2498lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2499 struct lpfc_fdmi_attr_def *ad)
2500{
2501 struct lpfc_fdmi_attr_entry *ae;
2502 uint32_t size;
2503
2504 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2505
2506 /* SRIOV (type 3) is not supported */
2507 if (vport->vpi)
2508 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2509 else
2510 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2511 size = FOURBYTES + sizeof(uint32_t);
2512 ad->AttrLen = cpu_to_be16(size);
2513 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2514 return size;
2515}
2516
bd4b3e5c 2517static int
4258e98e
JS
2518lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2519 struct lpfc_fdmi_attr_def *ad)
2520{
2521 struct lpfc_fdmi_attr_entry *ae;
2522 uint32_t size;
2523
2524 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2525 ae->un.AttrInt = cpu_to_be32(0);
2526 size = FOURBYTES + sizeof(uint32_t);
2527 ad->AttrLen = cpu_to_be16(size);
2528 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2529 return size;
2530}
2531
bd4b3e5c 2532static int
4258e98e
JS
2533lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2534 struct lpfc_fdmi_attr_def *ad)
2535{
2536 struct lpfc_fdmi_attr_entry *ae;
2537 uint32_t size;
2538
2539 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
56204984 2540 ae->un.AttrInt = cpu_to_be32(1);
4258e98e
JS
2541 size = FOURBYTES + sizeof(uint32_t);
2542 ad->AttrLen = cpu_to_be16(size);
2543 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2544 return size;
dea3101e 2545}
2e0fef85 2546
4258e98e
JS
2547/* RHBA attribute jump table */
2548int (*lpfc_fdmi_hba_action[])
2549 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2550 /* Action routine Mask bit Attribute type */
2551 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2552 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2553 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2554 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2555 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2556 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2557 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2558 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2559 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2560 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2561 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2562 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2563 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2564 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2565 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2566 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2567 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2568 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2569};
2570
2571/* RPA / RPRT attribute jump table */
2572int (*lpfc_fdmi_port_action[])
2573 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2574 /* Action routine Mask bit Attribute type */
2575 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2576 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2577 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2578 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2579 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2580 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2581 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2582 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2583 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2584 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2585 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2586 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2587 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2588 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2589 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2590 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2591 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2592 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2593 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2594 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2595 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2596 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2597 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2598};
76b2c34a 2599
4258e98e
JS
2600/**
2601 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2602 * @vport: pointer to a host virtual N_Port data structure.
2603 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2604 * cmdcode: FDMI command to send
2605 * mask: Mask of HBA or PORT Attributes to send
2606 *
2607 * Builds and sends a FDMI command using the CT subsystem.
2608 */
dea3101e 2609int
4258e98e
JS
2610lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2611 int cmdcode, uint32_t new_mask)
dea3101e 2612{
2e0fef85 2613 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
2614 struct lpfc_dmabuf *mp, *bmp;
2615 struct lpfc_sli_ct_request *CtReq;
2616 struct ulp_bde64 *bpl;
4258e98e 2617 uint32_t bit_pos;
dea3101e 2618 uint32_t size;
76b2c34a 2619 uint32_t rsp_size;
4258e98e 2620 uint32_t mask;
76b2c34a
JS
2621 struct lpfc_fdmi_reg_hba *rh;
2622 struct lpfc_fdmi_port_entry *pe;
2623 struct lpfc_fdmi_reg_portattr *pab = NULL;
2624 struct lpfc_fdmi_attr_block *ab = NULL;
4258e98e
JS
2625 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2626 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2627 struct lpfc_iocbq *);
dea3101e 2628
4258e98e
JS
2629 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2630 return 0;
2631
2632 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
dea3101e
JB
2633
2634 /* fill in BDEs for command */
2635 /* Allocate buffer for command payload */
76b2c34a 2636 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea3101e
JB
2637 if (!mp)
2638 goto fdmi_cmd_exit;
2639
2640 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2641 if (!mp->virt)
2642 goto fdmi_cmd_free_mp;
2643
2644 /* Allocate buffer for Buffer ptr list */
76b2c34a 2645 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea3101e
JB
2646 if (!bmp)
2647 goto fdmi_cmd_free_mpvirt;
2648
2649 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2650 if (!bmp->virt)
2651 goto fdmi_cmd_free_bmp;
2652
2653 INIT_LIST_HEAD(&mp->list);
2654 INIT_LIST_HEAD(&bmp->list);
2655
2656 /* FDMI request */
e8b62011
JS
2657 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2658 "0218 FDMI Request Data: x%x x%x x%x\n",
2659 vport->fc_flag, vport->port_state, cmdcode);
76b2c34a 2660 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
dea3101e 2661
76b2c34a 2662 /* First populate the CT_IU preamble */
dea3101e
JB
2663 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2664 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2665 CtReq->RevisionId.bits.InId = 0;
2666
2667 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2668 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
76b2c34a
JS
2669
2670 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2671 rsp_size = LPFC_BPL_SIZE;
dea3101e
JB
2672 size = 0;
2673
76b2c34a 2674 /* Next fill in the specific FDMI cmd information */
dea3101e 2675 switch (cmdcode) {
76b2c34a 2676 case SLI_MGMT_RHAT:
dea3101e 2677 case SLI_MGMT_RHBA:
4258e98e
JS
2678 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2679 /* HBA Identifier */
2680 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2681 sizeof(struct lpfc_name));
dea3101e 2682
4258e98e
JS
2683 if (cmdcode == SLI_MGMT_RHBA) {
2684 /* Registered Port List */
2685 /* One entry (port) per adapter */
2686 rh->rpl.EntryCnt = cpu_to_be32(1);
2687 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
76b2c34a
JS
2688 sizeof(struct lpfc_name));
2689
4258e98e
JS
2690 /* point to the HBA attribute block */
2691 size = 2 * sizeof(struct lpfc_name) +
2692 FOURBYTES;
2693 } else {
2694 size = sizeof(struct lpfc_name);
2695 }
2696 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2697 ab->EntryCnt = 0;
2698 size += FOURBYTES;
2699 bit_pos = 0;
2700 if (new_mask)
2701 mask = new_mask;
2702 else
2703 mask = vport->fdmi_hba_mask;
2704
2705 /* Mask will dictate what attributes to build in the request */
2706 while (mask) {
2707 if (mask & 0x1) {
2708 func = lpfc_fdmi_hba_action[bit_pos];
2709 size += func(vport,
2710 (struct lpfc_fdmi_attr_def *)
2711 ((uint8_t *)rh + size));
2712 ab->EntryCnt++;
2713 if ((size + 256) >
2714 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2715 goto hba_out;
dea3101e 2716 }
4258e98e
JS
2717 mask = mask >> 1;
2718 bit_pos++;
dea3101e 2719 }
4258e98e
JS
2720hba_out:
2721 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2722 /* Total size */
2723 size = GID_REQUEST_SZ - 4 + size;
dea3101e
JB
2724 break;
2725
76b2c34a 2726 case SLI_MGMT_RPRT:
dea3101e 2727 case SLI_MGMT_RPA:
4258e98e
JS
2728 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2729 if (cmdcode == SLI_MGMT_RPRT) {
2730 rh = (struct lpfc_fdmi_reg_hba *)pab;
2731 /* HBA Identifier */
2732 memcpy(&rh->hi.PortName,
2733 &phba->pport->fc_sparam.portName,
76b2c34a 2734 sizeof(struct lpfc_name));
4258e98e
JS
2735 pab = (struct lpfc_fdmi_reg_portattr *)
2736 ((uint8_t *)pab + sizeof(struct lpfc_name));
2737 }
dea3101e 2738
4258e98e
JS
2739 memcpy((uint8_t *)&pab->PortName,
2740 (uint8_t *)&vport->fc_sparam.portName,
2741 sizeof(struct lpfc_name));
2742 size += sizeof(struct lpfc_name) + FOURBYTES;
2743 pab->ab.EntryCnt = 0;
2744 bit_pos = 0;
2745 if (new_mask)
2746 mask = new_mask;
2747 else
2748 mask = vport->fdmi_port_mask;
2749
2750 /* Mask will dictate what attributes to build in the request */
2751 while (mask) {
2752 if (mask & 0x1) {
2753 func = lpfc_fdmi_port_action[bit_pos];
2754 size += func(vport,
2755 (struct lpfc_fdmi_attr_def *)
2756 ((uint8_t *)pab + size));
2757 pab->ab.EntryCnt++;
2758 if ((size + 256) >
2759 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2760 goto port_out;
2761 }
2762 mask = mask >> 1;
2763 bit_pos++;
dea3101e 2764 }
4258e98e
JS
2765port_out:
2766 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2767 /* Total size */
2768 if (cmdcode == SLI_MGMT_RPRT)
2769 size += sizeof(struct lpfc_name);
2770 size = GID_REQUEST_SZ - 4 + size;
dea3101e
JB
2771 break;
2772
76b2c34a
JS
2773 case SLI_MGMT_GHAT:
2774 case SLI_MGMT_GRPL:
2775 rsp_size = FC_MAX_NS_RSP;
dea3101e 2776 case SLI_MGMT_DHBA:
76b2c34a
JS
2777 case SLI_MGMT_DHAT:
2778 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2779 memcpy((uint8_t *)&pe->PortName,
2780 (uint8_t *)&vport->fc_sparam.portName,
2781 sizeof(struct lpfc_name));
2782 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea3101e
JB
2783 break;
2784
76b2c34a
JS
2785 case SLI_MGMT_GPAT:
2786 case SLI_MGMT_GPAS:
2787 rsp_size = FC_MAX_NS_RSP;
dea3101e 2788 case SLI_MGMT_DPRT:
76b2c34a
JS
2789 case SLI_MGMT_DPA:
2790 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2791 memcpy((uint8_t *)&pe->PortName,
2792 (uint8_t *)&vport->fc_sparam.portName,
2793 sizeof(struct lpfc_name));
2794 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2795 break;
2796 case SLI_MGMT_GRHL:
2797 size = GID_REQUEST_SZ - 4;
dea3101e 2798 break;
76b2c34a
JS
2799 default:
2800 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2801 "0298 FDMI cmdcode x%x not supported\n",
2802 cmdcode);
2803 goto fdmi_cmd_free_bmpvirt;
dea3101e 2804 }
76b2c34a 2805 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
dea3101e 2806
76b2c34a
JS
2807 bpl = (struct ulp_bde64 *)bmp->virt;
2808 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2809 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
dea3101e
JB
2810 bpl->tus.f.bdeFlags = 0;
2811 bpl->tus.f.bdeSize = size;
dea3101e 2812
76b2c34a
JS
2813 /*
2814 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
e47c9093
JS
2815 * to hold ndlp reference for the corresponding callback function.
2816 */
76b2c34a 2817 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
dea3101e
JB
2818 return 0;
2819
76b2c34a
JS
2820 /*
2821 * Decrement ndlp reference count to release ndlp reference held
e47c9093
JS
2822 * for the failed command's callback function.
2823 */
51ef4c26 2824 lpfc_nlp_put(ndlp);
e47c9093 2825
76b2c34a 2826fdmi_cmd_free_bmpvirt:
dea3101e
JB
2827 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2828fdmi_cmd_free_bmp:
2829 kfree(bmp);
2830fdmi_cmd_free_mpvirt:
2831 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2832fdmi_cmd_free_mp:
2833 kfree(mp);
2834fdmi_cmd_exit:
2835 /* Issue FDMI request failed */
e8b62011
JS
2836 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2837 "0244 Issue FDMI request failed Data: x%x\n",
2838 cmdcode);
dea3101e
JB
2839 return 1;
2840}
2841
92494144
JS
2842/**
2843 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2844 * @ptr - Context object of the timer.
2845 *
2846 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2847 * the worker thread.
2848 **/
2849void
2850lpfc_delayed_disc_tmo(unsigned long ptr)
2851{
2852 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
2853 struct lpfc_hba *phba = vport->phba;
2854 uint32_t tmo_posted;
2855 unsigned long iflag;
2856
2857 spin_lock_irqsave(&vport->work_port_lock, iflag);
2858 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2859 if (!tmo_posted)
2860 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2861 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2862
2863 if (!tmo_posted)
2864 lpfc_worker_wake_up(phba);
2865 return;
2866}
2867
2868/**
2869 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2870 * handle delayed discovery.
2871 * @vport: pointer to a host virtual N_Port data structure.
2872 *
2873 * This function start nport discovery of the vport.
2874 **/
2875void
2876lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2877{
2878 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2879
2880 spin_lock_irq(shost->host_lock);
2881 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2882 spin_unlock_irq(shost->host_lock);
2883 return;
2884 }
2885 vport->fc_flag &= ~FC_DISC_DELAYED;
2886 spin_unlock_irq(shost->host_lock);
2887
2888 lpfc_do_scr_ns_plogi(vport->phba, vport);
2889}
2890
dea3101e 2891void
2e0fef85 2892lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea3101e
JB
2893{
2894 struct lpfc_sli *psli = &phba->sli;
2895 lpfc_vpd_t *vp = &phba->vpd;
2896 uint32_t b1, b2, b3, b4, i, rev;
2897 char c;
2898 uint32_t *ptr, str[4];
2899 uint8_t *fwname;
2900
f1126688 2901 if (phba->sli_rev == LPFC_SLI_REV4)
6b5151fd 2902 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
f1126688 2903 else if (vp->rev.rBit) {
f4b4c68f 2904 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea3101e
JB
2905 rev = vp->rev.sli2FwRev;
2906 else
2907 rev = vp->rev.sli1FwRev;
2908
2909 b1 = (rev & 0x0000f000) >> 12;
2910 b2 = (rev & 0x00000f00) >> 8;
2911 b3 = (rev & 0x000000c0) >> 6;
2912 b4 = (rev & 0x00000030) >> 4;
2913
2914 switch (b4) {
2915 case 0:
2916 c = 'N';
2917 break;
2918 case 1:
2919 c = 'A';
2920 break;
2921 case 2:
2922 c = 'B';
2923 break;
73d91e50
JS
2924 case 3:
2925 c = 'X';
2926 break;
dea3101e
JB
2927 default:
2928 c = 0;
2929 break;
2930 }
2931 b4 = (rev & 0x0000000f);
2932
f4b4c68f 2933 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea3101e
JB
2934 fwname = vp->rev.sli2FwName;
2935 else
2936 fwname = vp->rev.sli1FwName;
2937
2938 for (i = 0; i < 16; i++)
2939 if (fwname[i] == 0x20)
2940 fwname[i] = 0;
2941
2942 ptr = (uint32_t*)fwname;
2943
2944 for (i = 0; i < 3; i++)
2945 str[i] = be32_to_cpu(*ptr++);
2946
2947 if (c == 0) {
2948 if (flag)
2949 sprintf(fwrevision, "%d.%d%d (%s)",
2950 b1, b2, b3, (char *)str);
2951 else
2952 sprintf(fwrevision, "%d.%d%d", b1,
2953 b2, b3);
2954 } else {
2955 if (flag)
2956 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
2957 b1, b2, b3, c,
2958 b4, (char *)str);
2959 else
2960 sprintf(fwrevision, "%d.%d%d%c%d",
2961 b1, b2, b3, c, b4);
2962 }
2963 } else {
2964 rev = vp->rev.smFwRev;
2965
2966 b1 = (rev & 0xff000000) >> 24;
2967 b2 = (rev & 0x00f00000) >> 20;
2968 b3 = (rev & 0x000f0000) >> 16;
2969 c = (rev & 0x0000ff00) >> 8;
2970 b4 = (rev & 0x000000ff);
2971
d44a6d2b 2972 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea3101e
JB
2973 }
2974 return;
2975}