blob: 1e7889e451602f2a2651252042f25b4f2641de78 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartcf8037f2018-02-22 08:18:52 -08004 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
James Smartd080abe2017-02-12 13:52:39 -08005 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
dea31012005-04-17 16:05:31 -05009 * *
10 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011 * 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. *
dea31012005-04-17 16:05:31 -050021 *******************************************************************/
22
23/*
James Smart09372822008-01-11 01:52:54 -050024 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea31012005-04-17 16:05:31 -050025 */
26
27#include <linux/blkdev.h>
28#include <linux/pci.h>
29#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050031#include <linux/utsname.h>
32
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040036#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040037#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050038
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_hw.h"
41#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040043#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050044#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc.h"
James Smarta0f2d3e2017-02-12 13:52:31 -080046#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
50#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050051#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050052#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050053
James Smarta085e872015-12-16 18:12:02 -050054/* 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 */
dea31012005-04-17 16:05:31 -050074
75#define FOURBYTES 4
76
77
78static char *lpfc_release_version = LPFC_DRIVER_VERSION;
79
James Smarted957682007-06-17 19:56:37 -050080static void
81lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050082 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050083{
James Smarted957682007-06-17 19:56:37 -050084 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050085 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040086 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050087 "status = x%x\n",
88 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050089 }
James Smart9c2face2008-01-11 01:53:18 -050090 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);
94}
95
96static void
97lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
99{
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -0500101}
102
dea31012005-04-17 16:05:31 -0500103void
James Smart2e0fef82007-06-17 19:56:36 -0500104lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -0500106{
James Smarted957682007-06-17 19:56:37 -0500107 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -0500108 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -0500109 int i;
110 struct lpfc_iocbq *iocbq;
111 dma_addr_t paddr;
112 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -0500113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -0500115
James Smart4fede782010-01-26 23:08:55 -0500116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
117 return;
James Smartf1c3b0f2009-07-19 10:01:32 -0400118
James Smart92d7f7b2007-06-17 19:56:38 -0500119 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) &&
James Smarte3d2b802012-08-14 14:25:43 -0400122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500124 /* Not enough posted buffers; Try posting more buffers */
125 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400127 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500128 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
James Smarted957682007-06-17 19:56:37 -0500137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500141 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500142 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500143 continue;
James Smart9c2face2008-01-11 01:53:18 -0500144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500146 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500149 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500150 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);
James Smarted957682007-06-17 19:56:37 -0500156 }
dea31012005-04-17 16:05:31 -0500157 }
James Smart9c2face2008-01-11 01:53:18 -0500158 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500159 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500163 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500164 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500166 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;
James Smartd7c255b2008-08-24 21:50:00 -0400172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500173 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500174 }
James Smart495a7142008-06-14 22:52:59 -0400175 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500176 }
James Smartd7c255b2008-08-24 21:50:00 -0400177 list_del(&head);
dea31012005-04-17 16:05:31 -0500178 }
dea31012005-04-17 16:05:31 -0500179}
180
James Smart6669f9b2009-10-02 15:16:45 -0400181/**
James Smart6dd9e312013-01-03 15:43:37 -0500182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
James Smart6669f9b2009-10-02 15:16:45 -0400183 * @phba: Pointer to HBA context object.
James Smart6dd9e312013-01-03 15:43:37 -0500184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
James Smart6669f9b2009-10-02 15:16:45 -0400185 *
James Smart6dd9e312013-01-03 15:43:37 -0500186 * 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.
James Smart6669f9b2009-10-02 15:16:45 -0400190 **/
James Smart6dd9e312013-01-03 15:43:37 -0500191int
192lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
James Smart6669f9b2009-10-02 15:16:45 -0400193{
James Smart6dd9e312013-01-03 15:43:37 -0500194 int handled;
James Smart6669f9b2009-10-02 15:16:45 -0400195
James Smart6dd9e312013-01-03 15:43:37 -0500196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
James Smart6669f9b2009-10-02 15:16:45 -0400198
James Smart6dd9e312013-01-03 15:43:37 -0500199 return handled;
James Smart6669f9b2009-10-02 15:16:45 -0400200}
201
dea31012005-04-17 16:05:31 -0500202static void
James Smart2e0fef82007-06-17 19:56:36 -0500203lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500204{
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 *
James Smart2e0fef82007-06-17 19:56:36 -0500218lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500219 uint32_t size, int *entries)
220{
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
223 int cnt, i = 0;
224
James Smart09372822008-01-11 01:52:54 -0500225 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500226 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
James Smart92d7f7b2007-06-17 19:56:38 -0500239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500241 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);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700247 if (mlist)
248 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500249 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
James Smart34b02dc2008-08-24 21:49:55 -0400258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500259 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500262 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
James Smart858c9f62007-06-17 19:56:39 -0500274int
275lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
276{
277 struct lpfc_dmabuf *buf_ptr;
278
James Smart51ef4c22007-08-02 11:10:31 -0400279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
282 }
James Smart858c9f62007-06-17 19:56:39 -0500283 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);
Felipe Pena1109c942013-10-15 21:29:50 -0300298 ctiocb->context3 = NULL;
James Smart858c9f62007-06-17 19:56:39 -0500299 }
300 lpfc_sli_release_iocbq(phba, ctiocb);
301 return 0;
302}
303
James Smart4258e982015-12-16 18:11:58 -0500304/**
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 */
dea31012005-04-17 16:05:31 -0500315static int
James Smart2e0fef82007-06-17 19:56:36 -0500316lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500317 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,
James Smart92d7f7b2007-06-17 19:56:38 -0500321 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500322{
James Smart2e0fef82007-06-17 19:56:36 -0500323 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500324 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400325 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500326 int rc;
dea31012005-04-17 16:05:31 -0500327
328 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400329 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500330
331 if (geniocb == NULL)
332 return 1;
dea31012005-04-17 16:05:31 -0500333
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);
James Smart34b02dc2008-08-24 21:49:55 -0400338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart4258e982015-12-16 18:11:58 -0500339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500340
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;
James Smarte47c9092008-02-08 18:49:26 -0500349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500350
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;
James Smart6a9c52c2009-10-02 15:16:51 -0400357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -0500359
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500360 if (!tmo) {
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
363 }
dea31012005-04-17 16:05:31 -0500364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
366 icmd->ulpLe = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -0400369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea31012005-04-17 16:05:31 -0500371
James Smart92d7f7b2007-06-17 19:56:38 -0500372 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
dea31012005-04-17 16:05:31 -0500378 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400379 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);
dea31012005-04-17 16:05:31 -0500384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500386 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500387 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500389
390 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500391 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500392 return 1;
393 }
dea31012005-04-17 16:05:31 -0500394
395 return 0;
396}
397
James Smart4258e982015-12-16 18:11:58 -0500398/**
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 */
dea31012005-04-17 16:05:31 -0500408static int
James Smart2e0fef82007-06-17 19:56:36 -0500409lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500413 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500414{
James Smart2e0fef82007-06-17 19:56:36 -0500415 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500416 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;
James Smart6a9c52c2009-10-02 15:16:51 -0400428 /*
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;
James Smart2e0fef82007-06-17 19:56:36 -0500434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart6a9c52c2009-10-02 15:16:51 -0400435 cnt, 0, retry);
dea31012005-04-17 16:05:31 -0500436 if (status) {
437 lpfc_free_ct_rsp(phba, outmp);
438 return -ENOMEM;
439 }
440 return 0;
441}
442
James Smart549e55c2007-08-02 11:09:51 -0400443struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500444lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500445 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400446 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500447
James Smart549e55c2007-08-02 11:09:51 -0400448 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500452 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400453 }
James Smart92d7f7b2007-06-17 19:56:38 -0500454 }
James Smart549e55c2007-08-02 11:09:51 -0400455 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500456 return NULL;
457}
458
James Smarta0f2d3e2017-02-12 13:52:31 -0800459static 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)) {
James Smartbd2cdd52017-02-12 13:52:33 -0800470 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
James Smarta0f2d3e2017-02-12 13:52:31 -0800474 /* 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);
James Smartbd2cdd52017-02-12 13:52:33 -0800487 } 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
James Smarta0f2d3e2017-02-12 13:52:31 -0800492 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);
James Smartbd2cdd52017-02-12 13:52:33 -0800497 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800498 } else {
499 if (!(vport->fc_flag & FC_RSCN_MODE) ||
500 lpfc_rscn_payload_check(vport, Did)) {
James Smartbd2cdd52017-02-12 13:52:33 -0800501 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
James Smarta0f2d3e2017-02-12 13:52:31 -0800505 /*
James Smartb57ab7462017-06-01 21:07:08 -0700506 * This NPortID was previously a FCP/NVMe target,
James Smarta0f2d3e2017-02-12 13:52:31 -0800507 * Don't even bother to send GFF_ID.
508 */
509 ndlp = lpfc_findnode_did(vport, Did);
James Smartb57ab7462017-06-01 21:07:08 -0700510 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
511 (ndlp->nlp_type &
512 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
513 if (fc4_type == FC_TYPE_FCP)
514 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
515 if (fc4_type == FC_TYPE_NVME)
516 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
517 lpfc_setup_disc_node(vport, Did);
518 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
519 0, Did) == 0)
520 vport->num_disc_nodes++;
521 else
522 lpfc_setup_disc_node(vport, Did);
James Smartbd2cdd52017-02-12 13:52:33 -0800523 } else {
524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
525 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
526 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
527
James Smarta0f2d3e2017-02-12 13:52:31 -0800528 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
529 "0245 Skip x%06x NameServer Rsp "
530 "Data: x%x x%x\n", Did,
531 vport->fc_flag,
532 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800533 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800534 }
535}
536
James Smart1c5b12f2017-04-21 16:05:03 -0700537static void
538lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
539{
540 struct lpfc_hba *phba = vport->phba;
541 struct lpfc_nodelist *ndlp = NULL;
542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
543
544 /*
545 * To conserve rpi's, filter out addresses for other
546 * vports on the same physical HBAs.
547 */
548 if (Did != vport->fc_myDID &&
549 (!lpfc_find_vport_by_did(phba, Did) ||
550 vport->cfg_peer_port_login)) {
551 if (!phba->nvmet_support) {
552 /* FCPI/NVMEI path. Process Did */
553 lpfc_prep_node_fc4type(vport, Did, fc4_type);
554 return;
555 }
556 /* NVMET path. NVMET only cares about NVMEI nodes. */
557 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
558 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
559 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
560 continue;
561 spin_lock_irq(shost->host_lock);
562 if (ndlp->nlp_DID == Did)
563 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
564 else
565 ndlp->nlp_flag |= NLP_NVMET_RECOV;
566 spin_unlock_irq(shost->host_lock);
567 }
568 }
569}
570
dea31012005-04-17 16:05:31 -0500571static int
James Smarta0f2d3e2017-02-12 13:52:31 -0800572lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
573 uint32_t Size)
dea31012005-04-17 16:05:31 -0500574{
575 struct lpfc_sli_ct_request *Response =
576 (struct lpfc_sli_ct_request *) mp->virt;
dea31012005-04-17 16:05:31 -0500577 struct lpfc_dmabuf *mlast, *next_mp;
578 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500579 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500580 int Cnt;
581 struct list_head head;
James Smart1c5b12f2017-04-21 16:05:03 -0700582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
583 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -0500584
James Smart2e0fef82007-06-17 19:56:36 -0500585 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500586 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500587 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500588
dea31012005-04-17 16:05:31 -0500589
590 list_add_tail(&head, &mp->list);
591 list_for_each_entry_safe(mp, next_mp, &head, list) {
592 mlast = mp;
593
James Smart7054a602007-04-25 09:52:34 -0400594 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
595
dea31012005-04-17 16:05:31 -0500596 Size -= Cnt;
597
James Smart1dcb58e2007-04-25 09:51:30 -0400598 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500599 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400600 } else
dea31012005-04-17 16:05:31 -0500601 Cnt -= 16; /* subtract length of CT header */
602
603 /* Loop through entire NameServer list of DIDs */
James Smart4258e982015-12-16 18:11:58 -0500604 while (Cnt >= sizeof(uint32_t)) {
dea31012005-04-17 16:05:31 -0500605 /* Get next DID from NameServer List */
606 CTentry = *ctptr++;
607 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart1c5b12f2017-04-21 16:05:03 -0700608 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
James Smart76b2c342015-04-07 15:07:19 -0400609 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
dea31012005-04-17 16:05:31 -0500610 goto nsout1;
James Smarta0f2d3e2017-02-12 13:52:31 -0800611
James Smart4258e982015-12-16 18:11:58 -0500612 Cnt -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -0500613 }
614 ctptr = NULL;
615
616 }
617
James Smart1c5b12f2017-04-21 16:05:03 -0700618 /* All GID_FT entries processed. If the driver is running in
619 * in target mode, put impacted nodes into recovery and drop
620 * the RPI to flush outstanding IO.
621 */
622 if (vport->phba->nvmet_support) {
623 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
624 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
625 continue;
626 lpfc_disc_state_machine(vport, ndlp, NULL,
627 NLP_EVT_DEVICE_RECOVERY);
628 spin_lock_irq(shost->host_lock);
629 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
Dan Carpenter0d618cf2017-05-04 00:22:16 +0300630 spin_unlock_irq(shost->host_lock);
James Smart1c5b12f2017-04-21 16:05:03 -0700631 }
632 }
633
dea31012005-04-17 16:05:31 -0500634nsout1:
635 list_del(&head);
dea31012005-04-17 16:05:31 -0500636 return 0;
637}
638
dea31012005-04-17 16:05:31 -0500639static void
James Smart2e0fef82007-06-17 19:56:36 -0500640lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
641 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500642{
James Smart2e0fef82007-06-17 19:56:36 -0500643 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500645 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500646 struct lpfc_dmabuf *outp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800647 struct lpfc_dmabuf *inp;
dea31012005-04-17 16:05:31 -0500648 struct lpfc_sli_ct_request *CTrsp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800649 struct lpfc_sli_ct_request *CTreq;
James Smart51ef4c22007-08-02 11:10:31 -0400650 struct lpfc_nodelist *ndlp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800651 int rc, type;
dea31012005-04-17 16:05:31 -0500652
James Smart51ef4c22007-08-02 11:10:31 -0400653 /* First save ndlp, before we overwrite it */
654 ndlp = cmdiocb->context_un.ndlp;
655
dea31012005-04-17 16:05:31 -0500656 /* we pass cmdiocb to state machine which needs rspiocb as well */
657 cmdiocb->context_un.rsp_iocb = rspiocb;
James Smarta0f2d3e2017-02-12 13:52:31 -0800658 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -0500659 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
James Smart858c9f62007-06-17 19:56:39 -0500660 irsp = &rspiocb->iocb;
661
662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
663 "GID_FT cmpl: status:x%x/x%x rtry:%d",
664 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500665
James Smart92d7f7b2007-06-17 19:56:38 -0500666 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500667 if (vport->load_flag & FC_UNLOADING) {
668 if (vport->fc_flag & FC_RSCN_MODE)
669 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500670 goto out;
James Smarteada2722008-12-04 22:39:13 -0500671 }
James Smart92d7f7b2007-06-17 19:56:38 -0500672
James Smart58da1ff2008-04-07 10:15:56 -0400673 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400674 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
675 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500676 if (vport->fc_flag & FC_RSCN_MODE)
677 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500678 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
679 goto out;
680 }
James Smart58da1ff2008-04-07 10:15:56 -0400681 if (lpfc_error_lost_link(irsp)) {
682 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
683 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500684 if (vport->fc_flag & FC_RSCN_MODE)
685 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400686 goto out;
687 }
James Smart49382502017-11-20 16:00:38 -0800688
689 spin_lock_irq(shost->host_lock);
690 if (vport->fc_flag & FC_RSCN_DEFERRED) {
691 vport->fc_flag &= ~FC_RSCN_DEFERRED;
692 spin_unlock_irq(shost->host_lock);
693
James Smartb04744c2018-04-09 14:24:29 -0700694 /* This is a GID_FT completing so the gidft_inp counter was
695 * incremented before the GID_FT was issued to the wire.
696 */
697 vport->gidft_inp--;
698
James Smart49382502017-11-20 16:00:38 -0800699 /*
700 * Skip processing the NS response
701 * Re-issue the NS cmd
702 */
703 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
704 "0151 Process Deferred RSCN Data: x%x x%x\n",
705 vport->fc_flag, vport->fc_rscn_id_cnt);
706 lpfc_els_handle_rscn(vport);
707
708 goto out;
709 }
710 spin_unlock_irq(shost->host_lock);
711
James Smart858c9f62007-06-17 19:56:39 -0500712 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500713 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500714 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400715 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
James Smartedb22f02012-10-31 14:45:21 -0400716 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
James Smarte3d2b802012-08-14 14:25:43 -0400717 IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500718 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500719
James Smarta0f2d3e2017-02-12 13:52:31 -0800720 type = lpfc_get_gidft_type(vport, cmdiocb);
721 if (type == 0)
722 goto out;
723
James Smart58da1ff2008-04-07 10:15:56 -0400724 /* CT command is being retried */
James Smarta0f2d3e2017-02-12 13:52:31 -0800725 vport->gidft_inp--;
James Smart58da1ff2008-04-07 10:15:56 -0400726 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smarta0f2d3e2017-02-12 13:52:31 -0800727 vport->fc_ns_retry, type);
James Smart58da1ff2008-04-07 10:15:56 -0400728 if (rc == 0)
729 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500730 }
James Smarteada2722008-12-04 22:39:13 -0500731 if (vport->fc_flag & FC_RSCN_MODE)
732 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500733 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400734 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
735 "0257 GID_FT Query error: 0x%x 0x%x\n",
736 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500737 } else {
738 /* Good status, continue checking */
James Smarta0f2d3e2017-02-12 13:52:31 -0800739 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
dea31012005-04-17 16:05:31 -0500740 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
741 if (CTrsp->CommandResponse.bits.CmdRsp ==
James Smart76b2c342015-04-07 15:07:19 -0400742 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400743 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800744 "0208 NameServer Rsp Data: x%x x%x\n",
745 vport->fc_flag,
746 CTreq->un.gid.Fc4Type);
747
748 lpfc_ns_rsp(vport,
749 outp,
750 CTreq->un.gid.Fc4Type,
dea31012005-04-17 16:05:31 -0500751 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
752 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
753 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
754 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400755 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
756 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400757 lpfc_printf_vlog(vport, KERN_INFO,
758 LOG_DISCOVERY,
759 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400760 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400761 CTrsp->CommandResponse.bits.CmdRsp,
762 (uint32_t) CTrsp->ReasonCode,
763 (uint32_t) CTrsp->Explanation,
764 vport->fc_flag);
765
766 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
767 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
768 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
769 (uint32_t) CTrsp->ReasonCode,
770 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400771 } else {
772 lpfc_printf_vlog(vport, KERN_INFO,
773 LOG_DISCOVERY,
774 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500775 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500776 CTrsp->CommandResponse.bits.CmdRsp,
777 (uint32_t) CTrsp->ReasonCode,
778 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500779 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500780
James Smarta58cbd52007-08-02 11:09:43 -0400781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500782 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
783 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
784 (uint32_t) CTrsp->ReasonCode,
785 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400786 }
787
James Smart858c9f62007-06-17 19:56:39 -0500788
dea31012005-04-17 16:05:31 -0500789 } else {
790 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400791 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
792 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500793 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500794 CTrsp->CommandResponse.bits.CmdRsp,
795 (uint32_t) CTrsp->ReasonCode,
796 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500797 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500798
799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
800 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
801 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
802 (uint32_t) CTrsp->ReasonCode,
803 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500804 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800805 vport->gidft_inp--;
dea31012005-04-17 16:05:31 -0500806 }
807 /* Link up / RSCN discovery */
James Smarta0f2d3e2017-02-12 13:52:31 -0800808 if ((vport->num_disc_nodes == 0) &&
809 (vport->gidft_inp == 0)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500810 /*
811 * The driver has cycled through all Nports in the RSCN payload.
812 * Complete the handling by cleaning up and marking the
813 * current driver state.
814 */
815 if (vport->port_state >= LPFC_DISC_AUTH) {
816 if (vport->fc_flag & FC_RSCN_MODE) {
817 lpfc_els_flush_rscn(vport);
818 spin_lock_irq(shost->host_lock);
819 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
820 spin_unlock_irq(shost->host_lock);
821 }
822 else
823 lpfc_els_flush_rscn(vport);
824 }
825
826 lpfc_disc_start(vport);
827 }
dea31012005-04-17 16:05:31 -0500828out:
James Smart51ef4c22007-08-02 11:10:31 -0400829 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500830 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500831 return;
832}
833
James Smart311464e2007-08-02 11:10:37 -0400834static void
James Smart92d7f7b2007-06-17 19:56:38 -0500835lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
836 struct lpfc_iocbq *rspiocb)
837{
838 struct lpfc_vport *vport = cmdiocb->vport;
839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
840 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500841 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
842 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
843 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500844 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500845 uint8_t fbits;
846 struct lpfc_nodelist *ndlp;
847
848 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
849 did = be32_to_cpu(did);
850
James Smart858c9f62007-06-17 19:56:39 -0500851 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
852 "GFF_ID cmpl: status:x%x/x%x did:x%x",
853 irsp->ulpStatus, irsp->un.ulpWord[4], did);
854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
856 /* Good status, continue checking */
857 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
858 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
859
860 if (CTrsp->CommandResponse.bits.CmdRsp ==
861 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
862 if ((fbits & FC4_FEATURE_INIT) &&
863 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400864 lpfc_printf_vlog(vport, KERN_INFO,
865 LOG_DISCOVERY,
866 "0270 Skip x%x GFF "
867 "NameServer Rsp Data: (init) "
868 "x%x x%x\n", did, fbits,
869 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500870 goto out;
871 }
872 }
873 }
James Smart858c9f62007-06-17 19:56:39 -0500874 else {
James Smart0ff10d42008-01-11 01:52:36 -0500875 /* Check for retry */
876 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
877 retry = 1;
878 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
James Smarte3d2b802012-08-14 14:25:43 -0400879 switch ((irsp->un.ulpWord[4] &
880 IOERR_PARAM_MASK)) {
881
James Smart0ff10d42008-01-11 01:52:36 -0500882 case IOERR_NO_RESOURCES:
883 /* We don't increment the retry
884 * count for this case.
885 */
886 break;
887 case IOERR_LINK_DOWN:
888 case IOERR_SLI_ABORTED:
889 case IOERR_SLI_DOWN:
890 retry = 0;
891 break;
892 default:
893 cmdiocb->retry++;
894 }
895 }
896 else
897 cmdiocb->retry++;
898
899 if (retry) {
900 /* CT command is being retried */
901 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
902 cmdiocb->retry, did);
903 if (rc == 0) {
904 /* success */
905 lpfc_ct_free_iocb(phba, cmdiocb);
906 return;
907 }
908 }
909 }
James Smarte8b62012007-08-02 11:10:09 -0400910 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
911 "0267 NameServer GFF Rsp "
912 "x%x Error (%d %d) Data: x%x x%x\n",
913 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500914 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500915 }
916
James Smart92d7f7b2007-06-17 19:56:38 -0500917 /* This is a target port, unregistered port, or the GFF_ID failed */
918 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400919 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400920 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
921 "0242 Process x%x GFF "
922 "NameServer Rsp Data: x%x x%x x%x\n",
923 did, ndlp->nlp_flag, vport->fc_flag,
924 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500925 } else {
James Smarte8b62012007-08-02 11:10:09 -0400926 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
927 "0243 Skip x%x GFF "
928 "NameServer Rsp Data: x%x x%x\n", did,
929 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500930 }
931out:
932 /* Link up / RSCN discovery */
933 if (vport->num_disc_nodes)
934 vport->num_disc_nodes--;
935 if (vport->num_disc_nodes == 0) {
936 /*
937 * The driver has cycled through all Nports in the RSCN payload.
938 * Complete the handling by cleaning up and marking the
939 * current driver state.
940 */
941 if (vport->port_state >= LPFC_DISC_AUTH) {
942 if (vport->fc_flag & FC_RSCN_MODE) {
943 lpfc_els_flush_rscn(vport);
944 spin_lock_irq(shost->host_lock);
945 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
946 spin_unlock_irq(shost->host_lock);
947 }
948 else
949 lpfc_els_flush_rscn(vport);
950 }
951 lpfc_disc_start(vport);
952 }
James Smart858c9f62007-06-17 19:56:39 -0500953 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500954 return;
955}
956
James Smarta0f2d3e2017-02-12 13:52:31 -0800957static void
958lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
959 struct lpfc_iocbq *rspiocb)
960{
961 struct lpfc_vport *vport = cmdiocb->vport;
962 IOCB_t *irsp = &rspiocb->iocb;
963 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
964 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
965 struct lpfc_sli_ct_request *CTrsp;
966 int did;
967 struct lpfc_nodelist *ndlp;
968 uint32_t fc4_data_0, fc4_data_1;
969
970 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
971 did = be32_to_cpu(did);
972
James Smartbd2cdd52017-02-12 13:52:33 -0800973 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
974 "GFT_ID cmpl: status:x%x/x%x did:x%x",
975 irsp->ulpStatus, irsp->un.ulpWord[4], did);
976
James Smarta0f2d3e2017-02-12 13:52:31 -0800977 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
978 /* Good status, continue checking */
979 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
980 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
981 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700982 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800983 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
984 did, fc4_data_0, fc4_data_1);
985
986 ndlp = lpfc_findnode_did(vport, did);
987 if (ndlp) {
988 /* The bitmask value for FCP and NVME FCP types is
989 * the same because they are 32 bits distant from
990 * each other in word0 and word0.
991 */
992 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
993 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
994 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
995 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700996 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800997 "3064 Setting ndlp %p, DID x%06x with "
998 "FC4 x%08x, Data: x%08x x%08x\n",
999 ndlp, did, ndlp->nlp_fc4_type,
1000 FC_TYPE_FCP, FC_TYPE_NVME);
James Smartb5ccc7d2017-03-04 09:30:39 -08001001 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
Gustavo A. R. Silvae6ef6a72017-05-23 10:09:28 -05001002
1003 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1004 lpfc_issue_els_prli(vport, ndlp, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08001005 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001006 } else
1007 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1008 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1009
1010 lpfc_ct_free_iocb(phba, cmdiocb);
1011}
James Smart92d7f7b2007-06-17 19:56:38 -05001012
dea31012005-04-17 16:05:31 -05001013static void
James Smart7ee5d432007-10-27 13:37:17 -04001014lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1015 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001016{
James Smart92d7f7b2007-06-17 19:56:38 -05001017 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001018 struct lpfc_dmabuf *inp;
1019 struct lpfc_dmabuf *outp;
1020 IOCB_t *irsp;
1021 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -04001022 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05001023 int cmdcode, rc;
1024 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -05001025 uint32_t latt;
dea31012005-04-17 16:05:31 -05001026
James Smart51ef4c22007-08-02 11:10:31 -04001027 /* First save ndlp, before we overwrite it */
1028 ndlp = cmdiocb->context_un.ndlp;
1029
dea31012005-04-17 16:05:31 -05001030 /* we pass cmdiocb to state machine which needs rspiocb as well */
1031 cmdiocb->context_un.rsp_iocb = rspiocb;
1032
1033 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1034 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001035 irsp = &rspiocb->iocb;
1036
James Smart92d7f7b2007-06-17 19:56:38 -05001037 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1038 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -05001039 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1040
James Smart858c9f62007-06-17 19:56:39 -05001041 latt = lpfc_els_chk_latt(vport);
1042
1043 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -04001044 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -04001045 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -04001046 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1047 latt, irsp->ulpStatus,
1048 CTrsp->CommandResponse.bits.CmdRsp,
1049 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05001050
James Smart858c9f62007-06-17 19:56:39 -05001051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1052 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1053 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1054
James Smart92d7f7b2007-06-17 19:56:38 -05001055 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001056 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6e155202013-07-15 18:35:21 -04001057 "0268 NS cmd x%x Error (x%x x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04001058 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001059
James Smart92d7f7b2007-06-17 19:56:38 -05001060 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001061 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1062 IOERR_SLI_DOWN) ||
1063 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1064 IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -05001065 goto out;
1066
1067 retry = cmdiocb->retry;
1068 if (retry >= LPFC_MAX_NS_RETRY)
1069 goto out;
1070
1071 retry++;
James Smarte8b62012007-08-02 11:10:09 -04001072 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04001073 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -05001074 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1075 if (rc == 0)
1076 goto out;
1077 }
1078
1079out:
James Smart51ef4c22007-08-02 11:10:31 -04001080 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -05001081 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001082 return;
1083}
1084
1085static void
James Smart7ee5d432007-10-27 13:37:17 -04001086lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1087 struct lpfc_iocbq *rspiocb)
1088{
1089 IOCB_t *irsp = &rspiocb->iocb;
1090 struct lpfc_vport *vport = cmdiocb->vport;
1091
James Smart98c9ea52007-10-27 13:37:33 -04001092 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1093 struct lpfc_dmabuf *outp;
1094 struct lpfc_sli_ct_request *CTrsp;
1095
1096 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1097 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1098 if (CTrsp->CommandResponse.bits.CmdRsp ==
1099 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1100 vport->ct_flags |= FC_CT_RFT_ID;
1101 }
James Smart7ee5d432007-10-27 13:37:17 -04001102 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1103 return;
1104}
1105
1106static void
James Smart2e0fef82007-06-17 19:56:36 -05001107lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1108 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001109{
James Smart7ee5d432007-10-27 13:37:17 -04001110 IOCB_t *irsp = &rspiocb->iocb;
1111 struct lpfc_vport *vport = cmdiocb->vport;
1112
James Smart98c9ea52007-10-27 13:37:33 -04001113 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1114 struct lpfc_dmabuf *outp;
1115 struct lpfc_sli_ct_request *CTrsp;
1116
1117 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1118 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1119 if (CTrsp->CommandResponse.bits.CmdRsp ==
1120 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1121 vport->ct_flags |= FC_CT_RNN_ID;
1122 }
James Smart7ee5d432007-10-27 13:37:17 -04001123 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001124 return;
1125}
1126
1127static void
James Smart92d7f7b2007-06-17 19:56:38 -05001128lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1129 struct lpfc_iocbq *rspiocb)
1130{
James Smart7ee5d432007-10-27 13:37:17 -04001131 IOCB_t *irsp = &rspiocb->iocb;
1132 struct lpfc_vport *vport = cmdiocb->vport;
1133
James Smart98c9ea52007-10-27 13:37:33 -04001134 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1135 struct lpfc_dmabuf *outp;
1136 struct lpfc_sli_ct_request *CTrsp;
1137
1138 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1139 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1140 if (CTrsp->CommandResponse.bits.CmdRsp ==
1141 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1142 vport->ct_flags |= FC_CT_RSPN_ID;
1143 }
James Smart7ee5d432007-10-27 13:37:17 -04001144 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05001145 return;
1146}
1147
1148static void
James Smart2e0fef82007-06-17 19:56:36 -05001149lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1150 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001151{
James Smart7ee5d432007-10-27 13:37:17 -04001152 IOCB_t *irsp = &rspiocb->iocb;
1153 struct lpfc_vport *vport = cmdiocb->vport;
1154
James Smart98c9ea52007-10-27 13:37:33 -04001155 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1156 struct lpfc_dmabuf *outp;
1157 struct lpfc_sli_ct_request *CTrsp;
1158
1159 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1160 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1161 if (CTrsp->CommandResponse.bits.CmdRsp ==
1162 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1163 vport->ct_flags |= FC_CT_RSNN_NN;
1164 }
James Smart7ee5d432007-10-27 13:37:17 -04001165 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1166 return;
1167}
1168
1169static void
1170lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1171 struct lpfc_iocbq *rspiocb)
1172{
1173 struct lpfc_vport *vport = cmdiocb->vport;
1174
1175 /* even if it fails we will act as though it succeeded. */
1176 vport->ct_flags = 0;
1177 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001178 return;
1179}
1180
James Smart2fb9bd82006-12-02 13:33:57 -05001181static void
James Smart92d7f7b2007-06-17 19:56:38 -05001182lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1183 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001184{
James Smart92d7f7b2007-06-17 19:56:38 -05001185 IOCB_t *irsp = &rspiocb->iocb;
1186 struct lpfc_vport *vport = cmdiocb->vport;
1187
James Smart98c9ea52007-10-27 13:37:33 -04001188 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1189 struct lpfc_dmabuf *outp;
1190 struct lpfc_sli_ct_request *CTrsp;
1191
1192 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1193 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1194 if (CTrsp->CommandResponse.bits.CmdRsp ==
1195 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1196 vport->ct_flags |= FC_CT_RFF_ID;
1197 }
James Smart7ee5d432007-10-27 13:37:17 -04001198 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001199 return;
1200}
1201
James Smarta0f2d3e2017-02-12 13:52:31 -08001202/*
1203 * Although the symbolic port name is thought to be an integer
1204 * as of January 18, 2016, leave it as a string until more of
1205 * the record state becomes defined.
1206 */
James Smart495a7142008-06-14 22:52:59 -04001207int
James Smart92d7f7b2007-06-17 19:56:38 -05001208lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1209 size_t size)
1210{
1211 int n;
James Smart92d7f7b2007-06-17 19:56:38 -05001212
James Smarta0f2d3e2017-02-12 13:52:31 -08001213 /*
1214 * Use the lpfc board number as the Symbolic Port
1215 * Name object. NPIV is not in play so this integer
1216 * value is sufficient and unique per FC-ID.
1217 */
1218 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
James Smart92d7f7b2007-06-17 19:56:38 -05001219 return n;
1220}
1221
James Smarta0f2d3e2017-02-12 13:52:31 -08001222
James Smart92d7f7b2007-06-17 19:56:38 -05001223int
1224lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1225 size_t size)
dea31012005-04-17 16:05:31 -05001226{
James Smart6b5151f2012-01-18 16:24:06 -05001227 char fwrev[FW_REV_STR_SIZE];
James Smart92d7f7b2007-06-17 19:56:38 -05001228 int n;
dea31012005-04-17 16:05:31 -05001229
James Smart92d7f7b2007-06-17 19:56:38 -05001230 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001231
James Smartf0bf5f92015-04-07 15:07:18 -04001232 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
James Smartf0bf5f92015-04-07 15:07:18 -04001233 if (size < n)
1234 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001235
James Smartf0bf5f92015-04-07 15:07:18 -04001236 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
James Smartf0bf5f92015-04-07 15:07:18 -04001237 if (size < n)
1238 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001239
James Smarta0f2d3e2017-02-12 13:52:31 -08001240 n += snprintf(symbol + n, size - n, " DV%s.",
1241 lpfc_release_version);
James Smartf0bf5f92015-04-07 15:07:18 -04001242 if (size < n)
1243 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001244
1245 n += snprintf(symbol + n, size - n, " HN:%s.",
1246 init_utsname()->nodename);
1247 if (size < n)
1248 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001249
1250 /* Note :- OS name is "Linux" */
James Smarta0f2d3e2017-02-12 13:52:31 -08001251 n += snprintf(symbol + n, size - n, " OS:%s\n",
1252 init_utsname()->sysname);
James Smart92d7f7b2007-06-17 19:56:38 -05001253 return n;
dea31012005-04-17 16:05:31 -05001254}
1255
James Smart76b2c342015-04-07 15:07:19 -04001256static uint32_t
1257lpfc_find_map_node(struct lpfc_vport *vport)
1258{
1259 struct lpfc_nodelist *ndlp, *next_ndlp;
1260 struct Scsi_Host *shost;
1261 uint32_t cnt = 0;
1262
1263 shost = lpfc_shost_from_vport(vport);
1264 spin_lock_irq(shost->host_lock);
1265 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1266 if (ndlp->nlp_type & NLP_FABRIC)
1267 continue;
1268 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1269 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1270 cnt++;
1271 }
1272 spin_unlock_irq(shost->host_lock);
1273 return cnt;
1274}
1275
dea31012005-04-17 16:05:31 -05001276/*
James Smarta0f2d3e2017-02-12 13:52:31 -08001277 * This routine will return the FC4 Type associated with the CT
1278 * GID_FT command.
1279 */
1280int
1281lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1282{
1283 struct lpfc_sli_ct_request *CtReq;
1284 struct lpfc_dmabuf *mp;
1285 uint32_t type;
1286
1287 mp = cmdiocb->context1;
1288 if (mp == NULL)
1289 return 0;
1290 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1291 type = (uint32_t)CtReq->un.gid.Fc4Type;
1292 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1293 return 0;
1294 return type;
1295}
1296
1297/*
dea31012005-04-17 16:05:31 -05001298 * lpfc_ns_cmd
1299 * Description:
1300 * Issue Cmd to NameServer
1301 * SLI_CTNS_GID_FT
1302 * LI_CTNS_RFT_ID
1303 */
1304int
James Smart92d7f7b2007-06-17 19:56:38 -05001305lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1306 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001307{
James Smart92d7f7b2007-06-17 19:56:38 -05001308 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001309 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001310 struct lpfc_dmabuf *mp, *bmp;
1311 struct lpfc_sli_ct_request *CtReq;
1312 struct ulp_bde64 *bpl;
1313 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1314 struct lpfc_iocbq *) = NULL;
1315 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001316 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001317 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001318
1319 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001320 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1321 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001322 rc=1;
1323 goto ns_cmd_exit;
1324 }
dea31012005-04-17 16:05:31 -05001325
1326 /* fill in BDEs for command */
1327 /* Allocate buffer for command payload */
James Smart4258e982015-12-16 18:11:58 -05001328 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001329 if (!mp) {
1330 rc=2;
dea31012005-04-17 16:05:31 -05001331 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001332 }
dea31012005-04-17 16:05:31 -05001333
1334 INIT_LIST_HEAD(&mp->list);
1335 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001336 if (!mp->virt) {
1337 rc=3;
dea31012005-04-17 16:05:31 -05001338 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001339 }
dea31012005-04-17 16:05:31 -05001340
1341 /* Allocate buffer for Buffer ptr list */
James Smart4258e982015-12-16 18:11:58 -05001342 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001343 if (!bmp) {
1344 rc=4;
dea31012005-04-17 16:05:31 -05001345 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001346 }
dea31012005-04-17 16:05:31 -05001347
1348 INIT_LIST_HEAD(&bmp->list);
1349 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001350 if (!bmp->virt) {
1351 rc=5;
dea31012005-04-17 16:05:31 -05001352 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001353 }
dea31012005-04-17 16:05:31 -05001354
1355 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001356 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -08001357 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1358 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1359 context);
dea31012005-04-17 16:05:31 -05001360
1361 bpl = (struct ulp_bde64 *) bmp->virt;
1362 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001363 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1364 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001365 bpl->tus.f.bdeFlags = 0;
1366 if (cmdcode == SLI_CTNS_GID_FT)
1367 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001368 else if (cmdcode == SLI_CTNS_GFF_ID)
1369 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
James Smarta0f2d3e2017-02-12 13:52:31 -08001370 else if (cmdcode == SLI_CTNS_GFT_ID)
1371 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001372 else if (cmdcode == SLI_CTNS_RFT_ID)
1373 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1374 else if (cmdcode == SLI_CTNS_RNN_ID)
1375 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001376 else if (cmdcode == SLI_CTNS_RSPN_ID)
1377 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001378 else if (cmdcode == SLI_CTNS_RSNN_NN)
1379 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001380 else if (cmdcode == SLI_CTNS_DA_ID)
1381 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001382 else if (cmdcode == SLI_CTNS_RFF_ID)
1383 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001384 else
1385 bpl->tus.f.bdeSize = 0;
1386 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1387
1388 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
James Smart4258e982015-12-16 18:11:58 -05001389 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
dea31012005-04-17 16:05:31 -05001390 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1391 CtReq->RevisionId.bits.InId = 0;
1392 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1393 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1394 CtReq->CommandResponse.bits.Size = 0;
1395 switch (cmdcode) {
1396 case SLI_CTNS_GID_FT:
1397 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001398 cpu_to_be16(SLI_CTNS_GID_FT);
James Smarta0f2d3e2017-02-12 13:52:31 -08001399 CtReq->un.gid.Fc4Type = context;
1400
James Smart92d7f7b2007-06-17 19:56:38 -05001401 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001402 vport->port_state = LPFC_NS_QRY;
1403 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001404 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1405 rsp_size = FC_MAX_NS_RSP;
1406 break;
1407
James Smart92d7f7b2007-06-17 19:56:38 -05001408 case SLI_CTNS_GFF_ID:
1409 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001410 cpu_to_be16(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001411 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001412 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1413 break;
1414
James Smarta0f2d3e2017-02-12 13:52:31 -08001415 case SLI_CTNS_GFT_ID:
1416 CtReq->CommandResponse.bits.CmdRsp =
1417 cpu_to_be16(SLI_CTNS_GFT_ID);
1418 CtReq->un.gft.PortId = cpu_to_be32(context);
1419 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1420 break;
1421
dea31012005-04-17 16:05:31 -05001422 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001423 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001424 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001425 cpu_to_be16(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001426 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
James Smarta0f2d3e2017-02-12 13:52:31 -08001427
1428 /* Register FC4 FCP type if enabled. */
1429 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1430 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1431 CtReq->un.rft.fcpReg = 1;
1432
1433 /* Register NVME type if enabled. Defined LE and swapped.
1434 * rsvd[0] is used as word1 because of the hard-coded
1435 * word0 usage in the ct_request data structure.
1436 */
1437 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1438 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1439 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1440
dea31012005-04-17 16:05:31 -05001441 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1442 break;
1443
1444 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001445 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001446 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001447 cpu_to_be16(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001448 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001449 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001450 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001451 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1452 break;
1453
James Smart92d7f7b2007-06-17 19:56:38 -05001454 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001455 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001456 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001457 cpu_to_be16(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001458 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001459 size = sizeof(CtReq->un.rspn.symbname);
1460 CtReq->un.rspn.len =
1461 lpfc_vport_symbolic_port_name(vport,
1462 CtReq->un.rspn.symbname, size);
1463 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1464 break;
dea31012005-04-17 16:05:31 -05001465 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001466 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001467 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001468 cpu_to_be16(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001469 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001470 sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001471 size = sizeof(CtReq->un.rsnn.symbname);
1472 CtReq->un.rsnn.len =
1473 lpfc_vport_symbolic_node_name(vport,
1474 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001475 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1476 break;
James Smart7ee5d432007-10-27 13:37:17 -04001477 case SLI_CTNS_DA_ID:
1478 /* Implement DA_ID Nameserver request */
1479 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001480 cpu_to_be16(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001481 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001482 cmpl = lpfc_cmpl_ct_cmd_da_id;
1483 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001484 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001485 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001486 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001487 cpu_to_be16(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001488 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001489 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smarta0f2d3e2017-02-12 13:52:31 -08001490
1491 /* The driver always supports FC_TYPE_FCP. However, the
1492 * caller can specify NVME (type x28) as well. But only
1493 * these that FC4 type is supported.
1494 */
1495 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1496 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1497 (context == FC_TYPE_NVME)) {
James Smart8c258642017-02-12 13:52:36 -08001498 if ((vport == phba->pport) && phba->nvmet_support) {
1499 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1500 FC4_FEATURE_NVME_DISC);
James Smartd613b6a2017-02-12 13:52:37 -08001501 lpfc_nvmet_update_targetport(phba);
James Smart8c258642017-02-12 13:52:36 -08001502 } else {
1503 lpfc_nvme_update_localport(vport);
1504 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001505 CtReq->un.rff.type_code = context;
1506
1507 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1508 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1509 (context == FC_TYPE_FCP))
1510 CtReq->un.rff.type_code = context;
1511
1512 else
1513 goto ns_cmd_free_bmpvirt;
1514
James Smart92d7f7b2007-06-17 19:56:38 -05001515 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1516 break;
dea31012005-04-17 16:05:31 -05001517 }
James Smarte47c9092008-02-08 18:49:26 -05001518 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1519 * to hold ndlp reference for the corresponding callback function.
1520 */
James Smart858c9f62007-06-17 19:56:39 -05001521 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001522 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001523 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1524 "Issue CT cmd: cmd:x%x did:x%x",
1525 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001526 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001527 }
James Smart858c9f62007-06-17 19:56:39 -05001528 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001529
1530 /* Decrement ndlp reference count to release ndlp reference held
1531 * for the failed command's callback function.
1532 */
James Smart51ef4c22007-08-02 11:10:31 -04001533 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001534
James Smarta0f2d3e2017-02-12 13:52:31 -08001535ns_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05001536 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1537ns_cmd_free_bmp:
1538 kfree(bmp);
1539ns_cmd_free_mpvirt:
1540 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1541ns_cmd_free_mp:
1542 kfree(mp);
1543ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001544 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1545 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1546 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001547 return 1;
1548}
1549
James Smart4258e982015-12-16 18:11:58 -05001550/**
1551 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1552 * @phba: Pointer to HBA context object.
1553 * @cmdiocb: Pointer to the command IOCBQ.
1554 * @rspiocb: Pointer to the response IOCBQ.
1555 *
1556 * This function to handle the completion of a driver initiated FDMI
1557 * CT command issued during discovery.
1558 */
dea31012005-04-17 16:05:31 -05001559static void
James Smart4258e982015-12-16 18:11:58 -05001560lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1561 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001562{
James Smart4258e982015-12-16 18:11:58 -05001563 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001564 struct lpfc_dmabuf *inp = cmdiocb->context1;
1565 struct lpfc_dmabuf *outp = cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001566 struct lpfc_sli_ct_request *CTcmd = inp->virt;
James Smart4258e982015-12-16 18:11:58 -05001567 struct lpfc_sli_ct_request *CTrsp = outp->virt;
dea31012005-04-17 16:05:31 -05001568 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1569 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart858c9f62007-06-17 19:56:39 -05001570 IOCB_t *irsp = &rspiocb->iocb;
James Smart4258e982015-12-16 18:11:58 -05001571 struct lpfc_nodelist *ndlp;
1572 uint32_t latt, cmd, err;
James Smart858c9f62007-06-17 19:56:39 -05001573
1574 latt = lpfc_els_chk_latt(vport);
James Smart858c9f62007-06-17 19:56:39 -05001575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1576 "FDMI cmpl: status:x%x/x%x latt:%d",
1577 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1578
1579 if (latt || irsp->ulpStatus) {
James Smart4258e982015-12-16 18:11:58 -05001580
1581 /* Look for a retryable error */
1582 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1583 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1584 case IOERR_SLI_ABORTED:
1585 case IOERR_ABORT_IN_PROGRESS:
1586 case IOERR_SEQUENCE_TIMEOUT:
1587 case IOERR_ILLEGAL_FRAME:
1588 case IOERR_NO_RESOURCES:
1589 case IOERR_ILLEGAL_COMMAND:
1590 cmdiocb->retry++;
1591 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1592 break;
1593
1594 /* Retry the same FDMI command */
1595 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1596 cmdiocb, 0);
1597 if (err == IOCB_ERROR)
1598 break;
1599 return;
1600 default:
1601 break;
1602 }
1603 }
1604
James Smarte8b62012007-08-02 11:10:09 -04001605 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1606 "0229 FDMI cmd %04x failed, latt = %d "
1607 "ulpStatus: x%x, rid x%x\n",
1608 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1609 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001610 }
James Smart76b2c342015-04-07 15:07:19 -04001611 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart76b2c342015-04-07 15:07:19 -04001612
1613 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1614 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1615 return;
1616
James Smart4258e982015-12-16 18:11:58 -05001617 /* Check for a CT LS_RJT response */
1618 cmd = be16_to_cpu(fdmi_cmd);
1619 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1620 /* FDMI rsp failed */
1621 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1622 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1623
1624 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1625 switch (cmd) {
1626 case SLI_MGMT_RHBA:
1627 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1628 /* Fallback to FDMI-1 */
1629 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1630 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1631 /* Start over */
1632 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1633 }
1634 return;
1635
1636 case SLI_MGMT_RPRT:
1637 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1638 /* Fallback to FDMI-1 */
1639 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1640 /* Start over */
1641 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1642 }
1643 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1644 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1645 /* Retry the same command */
1646 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1647 }
1648 return;
1649
1650 case SLI_MGMT_RPA:
1651 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1652 /* Fallback to FDMI-1 */
1653 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1654 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1655 /* Start over */
1656 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1657 }
1658 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1659 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1660 /* Retry the same command */
1661 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1662 }
1663 return;
1664 }
1665 }
1666
James Smart76b2c342015-04-07 15:07:19 -04001667 /*
James Smart4258e982015-12-16 18:11:58 -05001668 * On success, need to cycle thru FDMI registration for discovery
1669 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1670 * DPRT -> RPRT (vports)
James Smart76b2c342015-04-07 15:07:19 -04001671 */
James Smart4258e982015-12-16 18:11:58 -05001672 switch (cmd) {
dea31012005-04-17 16:05:31 -05001673 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05001674 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
dea31012005-04-17 16:05:31 -05001675 break;
1676
dea31012005-04-17 16:05:31 -05001677 case SLI_MGMT_DHBA:
James Smart4258e982015-12-16 18:11:58 -05001678 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
dea31012005-04-17 16:05:31 -05001679 break;
1680
1681 case SLI_MGMT_DPRT:
James Smart4258e982015-12-16 18:11:58 -05001682 if (vport->port_type == LPFC_PHYSICAL_PORT)
1683 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1684 else
1685 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
dea31012005-04-17 16:05:31 -05001686 break;
1687 }
James Smart4258e982015-12-16 18:11:58 -05001688 return;
dea31012005-04-17 16:05:31 -05001689}
James Smart2e0fef82007-06-17 19:56:36 -05001690
James Smart76b2c342015-04-07 15:07:19 -04001691
James Smart4258e982015-12-16 18:11:58 -05001692/**
1693 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1694 * @vport: pointer to a host virtual N_Port data structure.
1695 *
1696 * Called from hbeat timeout routine to check if the number of discovered
1697 * ports has changed. If so, re-register thar port Attribute.
1698 */
1699void
1700lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1701{
1702 struct lpfc_hba *phba = vport->phba;
1703 struct lpfc_nodelist *ndlp;
1704 uint16_t cnt;
1705
1706 if (!lpfc_is_link_up(phba))
1707 return;
1708
James Smarta03a4212016-07-06 12:36:12 -07001709 /* Must be connected to a Fabric */
1710 if (!(vport->fc_flag & FC_FABRIC))
1711 return;
1712
James Smart4258e982015-12-16 18:11:58 -05001713 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1714 return;
1715
1716 cnt = lpfc_find_map_node(vport);
1717 if (cnt == vport->fdmi_num_disc)
1718 return;
1719
1720 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1721 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1722 return;
1723
1724 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1725 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1726 LPFC_FDMI_PORT_ATTR_num_disc);
1727 } else {
1728 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1729 LPFC_FDMI_PORT_ATTR_num_disc);
1730 }
1731}
1732
1733/* Routines for all individual HBA attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001734static int
James Smart4258e982015-12-16 18:11:58 -05001735lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1736{
1737 struct lpfc_fdmi_attr_entry *ae;
1738 uint32_t size;
1739
1740 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1741 memset(ae, 0, sizeof(struct lpfc_name));
1742
1743 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1744 sizeof(struct lpfc_name));
1745 size = FOURBYTES + sizeof(struct lpfc_name);
1746 ad->AttrLen = cpu_to_be16(size);
1747 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1748 return size;
1749}
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001750static int
James Smart4258e982015-12-16 18:11:58 -05001751lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1752 struct lpfc_fdmi_attr_def *ad)
1753{
1754 struct lpfc_fdmi_attr_entry *ae;
1755 uint32_t len, size;
1756
1757 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1758 memset(ae, 0, 256);
1759
1760 strncpy(ae->un.AttrString,
1761 "Emulex Corporation",
1762 sizeof(ae->un.AttrString));
1763 len = strnlen(ae->un.AttrString,
1764 sizeof(ae->un.AttrString));
1765 len += (len & 3) ? (4 - (len & 3)) : 4;
1766 size = FOURBYTES + len;
1767 ad->AttrLen = cpu_to_be16(size);
1768 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1769 return size;
1770}
1771
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001772static int
James Smart4258e982015-12-16 18:11:58 -05001773lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1774{
1775 struct lpfc_hba *phba = vport->phba;
1776 struct lpfc_fdmi_attr_entry *ae;
1777 uint32_t len, size;
1778
1779 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1780 memset(ae, 0, 256);
1781
1782 strncpy(ae->un.AttrString, phba->SerialNumber,
1783 sizeof(ae->un.AttrString));
1784 len = strnlen(ae->un.AttrString,
1785 sizeof(ae->un.AttrString));
1786 len += (len & 3) ? (4 - (len & 3)) : 4;
1787 size = FOURBYTES + len;
1788 ad->AttrLen = cpu_to_be16(size);
1789 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1790 return size;
1791}
1792
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001793static int
James Smart4258e982015-12-16 18:11:58 -05001794lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1795 struct lpfc_fdmi_attr_def *ad)
1796{
1797 struct lpfc_hba *phba = vport->phba;
1798 struct lpfc_fdmi_attr_entry *ae;
1799 uint32_t len, size;
1800
1801 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1802 memset(ae, 0, 256);
1803
1804 strncpy(ae->un.AttrString, phba->ModelName,
1805 sizeof(ae->un.AttrString));
1806 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1807 len += (len & 3) ? (4 - (len & 3)) : 4;
1808 size = FOURBYTES + len;
1809 ad->AttrLen = cpu_to_be16(size);
1810 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1811 return size;
1812}
1813
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001814static int
James Smart4258e982015-12-16 18:11:58 -05001815lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1816 struct lpfc_fdmi_attr_def *ad)
1817{
1818 struct lpfc_hba *phba = vport->phba;
1819 struct lpfc_fdmi_attr_entry *ae;
1820 uint32_t len, size;
1821
1822 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1823 memset(ae, 0, 256);
1824
1825 strncpy(ae->un.AttrString, phba->ModelDesc,
1826 sizeof(ae->un.AttrString));
1827 len = strnlen(ae->un.AttrString,
1828 sizeof(ae->un.AttrString));
1829 len += (len & 3) ? (4 - (len & 3)) : 4;
1830 size = FOURBYTES + len;
1831 ad->AttrLen = cpu_to_be16(size);
1832 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1833 return size;
1834}
1835
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001836static int
James Smart4258e982015-12-16 18:11:58 -05001837lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1838 struct lpfc_fdmi_attr_def *ad)
1839{
1840 struct lpfc_hba *phba = vport->phba;
1841 lpfc_vpd_t *vp = &phba->vpd;
1842 struct lpfc_fdmi_attr_entry *ae;
1843 uint32_t i, j, incr, size;
1844
1845 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1846 memset(ae, 0, 256);
1847
1848 /* Convert JEDEC ID to ascii for hardware version */
1849 incr = vp->rev.biuRev;
1850 for (i = 0; i < 8; i++) {
1851 j = (incr & 0xf);
1852 if (j <= 9)
1853 ae->un.AttrString[7 - i] =
1854 (char)((uint8_t) 0x30 +
1855 (uint8_t) j);
1856 else
1857 ae->un.AttrString[7 - i] =
1858 (char)((uint8_t) 0x61 +
1859 (uint8_t) (j - 10));
1860 incr = (incr >> 4);
1861 }
1862 size = FOURBYTES + 8;
1863 ad->AttrLen = cpu_to_be16(size);
1864 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1865 return size;
1866}
1867
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001868static int
James Smart4258e982015-12-16 18:11:58 -05001869lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1870 struct lpfc_fdmi_attr_def *ad)
1871{
1872 struct lpfc_fdmi_attr_entry *ae;
1873 uint32_t len, size;
1874
1875 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1876 memset(ae, 0, 256);
1877
1878 strncpy(ae->un.AttrString, lpfc_release_version,
1879 sizeof(ae->un.AttrString));
1880 len = strnlen(ae->un.AttrString,
1881 sizeof(ae->un.AttrString));
1882 len += (len & 3) ? (4 - (len & 3)) : 4;
1883 size = FOURBYTES + len;
1884 ad->AttrLen = cpu_to_be16(size);
1885 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1886 return size;
1887}
1888
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001889static int
James Smart4258e982015-12-16 18:11:58 -05001890lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1891 struct lpfc_fdmi_attr_def *ad)
1892{
1893 struct lpfc_hba *phba = vport->phba;
1894 struct lpfc_fdmi_attr_entry *ae;
1895 uint32_t len, size;
1896
1897 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1898 memset(ae, 0, 256);
1899
1900 if (phba->sli_rev == LPFC_SLI_REV4)
1901 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1902 else
1903 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1904 sizeof(ae->un.AttrString));
1905 len = strnlen(ae->un.AttrString,
1906 sizeof(ae->un.AttrString));
1907 len += (len & 3) ? (4 - (len & 3)) : 4;
1908 size = FOURBYTES + len;
1909 ad->AttrLen = cpu_to_be16(size);
1910 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1911 return size;
1912}
1913
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001914static int
James Smart4258e982015-12-16 18:11:58 -05001915lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1916 struct lpfc_fdmi_attr_def *ad)
1917{
1918 struct lpfc_hba *phba = vport->phba;
1919 struct lpfc_fdmi_attr_entry *ae;
1920 uint32_t len, size;
1921
1922 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1923 memset(ae, 0, 256);
1924
1925 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1926 len = strnlen(ae->un.AttrString,
1927 sizeof(ae->un.AttrString));
1928 len += (len & 3) ? (4 - (len & 3)) : 4;
1929 size = FOURBYTES + len;
1930 ad->AttrLen = cpu_to_be16(size);
1931 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1932 return size;
1933}
1934
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001935static int
James Smart4258e982015-12-16 18:11:58 -05001936lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1937 struct lpfc_fdmi_attr_def *ad)
1938{
1939 struct lpfc_fdmi_attr_entry *ae;
1940 uint32_t len, size;
1941
1942 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1943 memset(ae, 0, 256);
1944
1945 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1946 init_utsname()->sysname,
1947 init_utsname()->release,
1948 init_utsname()->version);
1949
1950 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1951 len += (len & 3) ? (4 - (len & 3)) : 4;
1952 size = FOURBYTES + len;
1953 ad->AttrLen = cpu_to_be16(size);
1954 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1955 return size;
1956}
1957
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001958static int
James Smart4258e982015-12-16 18:11:58 -05001959lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1960 struct lpfc_fdmi_attr_def *ad)
1961{
1962 struct lpfc_fdmi_attr_entry *ae;
1963 uint32_t size;
1964
1965 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1966
1967 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1968 size = FOURBYTES + sizeof(uint32_t);
1969 ad->AttrLen = cpu_to_be16(size);
1970 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1971 return size;
1972}
1973
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001974static int
James Smart4258e982015-12-16 18:11:58 -05001975lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1976 struct lpfc_fdmi_attr_def *ad)
1977{
1978 struct lpfc_fdmi_attr_entry *ae;
1979 uint32_t len, size;
1980
1981 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1982 memset(ae, 0, 256);
1983
1984 len = lpfc_vport_symbolic_node_name(vport,
1985 ae->un.AttrString, 256);
1986 len += (len & 3) ? (4 - (len & 3)) : 4;
1987 size = FOURBYTES + len;
1988 ad->AttrLen = cpu_to_be16(size);
1989 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1990 return size;
1991}
1992
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001993static int
James Smart4258e982015-12-16 18:11:58 -05001994lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
1995 struct lpfc_fdmi_attr_def *ad)
1996{
1997 struct lpfc_fdmi_attr_entry *ae;
1998 uint32_t size;
1999
2000 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2001
2002 /* Nothing is defined for this currently */
2003 ae->un.AttrInt = cpu_to_be32(0);
2004 size = FOURBYTES + sizeof(uint32_t);
2005 ad->AttrLen = cpu_to_be16(size);
2006 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2007 return size;
2008}
2009
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002010static int
James Smart4258e982015-12-16 18:11:58 -05002011lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2012 struct lpfc_fdmi_attr_def *ad)
2013{
2014 struct lpfc_fdmi_attr_entry *ae;
2015 uint32_t size;
2016
2017 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2018
2019 /* Each driver instance corresponds to a single port */
2020 ae->un.AttrInt = cpu_to_be32(1);
2021 size = FOURBYTES + sizeof(uint32_t);
2022 ad->AttrLen = cpu_to_be16(size);
2023 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2024 return size;
2025}
2026
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002027static int
James Smart4258e982015-12-16 18:11:58 -05002028lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2029 struct lpfc_fdmi_attr_def *ad)
2030{
2031 struct lpfc_fdmi_attr_entry *ae;
2032 uint32_t size;
2033
2034 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2035 memset(ae, 0, sizeof(struct lpfc_name));
2036
2037 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2038 sizeof(struct lpfc_name));
2039 size = FOURBYTES + sizeof(struct lpfc_name);
2040 ad->AttrLen = cpu_to_be16(size);
2041 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2042 return size;
2043}
2044
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002045static int
James Smart4258e982015-12-16 18:11:58 -05002046lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2047 struct lpfc_fdmi_attr_def *ad)
2048{
2049 struct lpfc_hba *phba = vport->phba;
2050 struct lpfc_fdmi_attr_entry *ae;
2051 uint32_t len, size;
2052
2053 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2054 memset(ae, 0, 256);
2055
2056 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2057 len = strnlen(ae->un.AttrString,
2058 sizeof(ae->un.AttrString));
2059 len += (len & 3) ? (4 - (len & 3)) : 4;
2060 size = FOURBYTES + len;
2061 ad->AttrLen = cpu_to_be16(size);
2062 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2063 return size;
2064}
2065
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002066static int
James Smart4258e982015-12-16 18:11:58 -05002067lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2068 struct lpfc_fdmi_attr_def *ad)
2069{
2070 struct lpfc_fdmi_attr_entry *ae;
2071 uint32_t size;
2072
2073 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2074
2075 /* Driver doesn't have access to this information */
2076 ae->un.AttrInt = cpu_to_be32(0);
2077 size = FOURBYTES + sizeof(uint32_t);
2078 ad->AttrLen = cpu_to_be16(size);
2079 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2080 return size;
2081}
2082
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002083static int
James Smart4258e982015-12-16 18:11:58 -05002084lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2085 struct lpfc_fdmi_attr_def *ad)
2086{
2087 struct lpfc_fdmi_attr_entry *ae;
2088 uint32_t len, size;
2089
2090 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2091 memset(ae, 0, 256);
2092
2093 strncpy(ae->un.AttrString, "EMULEX",
2094 sizeof(ae->un.AttrString));
2095 len = strnlen(ae->un.AttrString,
2096 sizeof(ae->un.AttrString));
2097 len += (len & 3) ? (4 - (len & 3)) : 4;
2098 size = FOURBYTES + len;
2099 ad->AttrLen = cpu_to_be16(size);
2100 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2101 return size;
2102}
2103
2104/* Routines for all individual PORT attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002105static int
James Smart4258e982015-12-16 18:11:58 -05002106lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2107 struct lpfc_fdmi_attr_def *ad)
2108{
2109 struct lpfc_fdmi_attr_entry *ae;
2110 uint32_t size;
2111
2112 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2113 memset(ae, 0, 32);
2114
2115 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2116 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
James Smart82820f02017-05-15 15:20:47 -07002117 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
James Smart4258e982015-12-16 18:11:58 -05002118 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2119 size = FOURBYTES + 32;
2120 ad->AttrLen = cpu_to_be16(size);
2121 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2122 return size;
2123}
2124
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002125static int
James Smart4258e982015-12-16 18:11:58 -05002126lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2127 struct lpfc_fdmi_attr_def *ad)
2128{
2129 struct lpfc_hba *phba = vport->phba;
2130 struct lpfc_fdmi_attr_entry *ae;
2131 uint32_t size;
2132
2133 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2134
2135 ae->un.AttrInt = 0;
James Smarta085e872015-12-16 18:12:02 -05002136 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smartfbd8a6b2018-02-22 08:18:45 -08002137 if (phba->lmt & LMT_64Gb)
2138 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
James Smarta085e872015-12-16 18:12:02 -05002139 if (phba->lmt & LMT_32Gb)
2140 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2141 if (phba->lmt & LMT_16Gb)
2142 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2143 if (phba->lmt & LMT_10Gb)
2144 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2145 if (phba->lmt & LMT_8Gb)
2146 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2147 if (phba->lmt & LMT_4Gb)
2148 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2149 if (phba->lmt & LMT_2Gb)
2150 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2151 if (phba->lmt & LMT_1Gb)
2152 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2153 } else {
2154 /* FCoE links support only one speed */
2155 switch (phba->fc_linkspeed) {
2156 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2157 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2158 break;
2159 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2160 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2161 break;
2162 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2163 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2164 break;
2165 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2166 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2167 break;
2168 }
2169 }
James Smart4258e982015-12-16 18:11:58 -05002170 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2171 size = FOURBYTES + sizeof(uint32_t);
2172 ad->AttrLen = cpu_to_be16(size);
2173 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2174 return size;
2175}
2176
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002177static int
James Smart4258e982015-12-16 18:11:58 -05002178lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2179 struct lpfc_fdmi_attr_def *ad)
2180{
2181 struct lpfc_hba *phba = vport->phba;
2182 struct lpfc_fdmi_attr_entry *ae;
2183 uint32_t size;
2184
2185 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2186
James Smarta085e872015-12-16 18:12:02 -05002187 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2188 switch (phba->fc_linkspeed) {
2189 case LPFC_LINK_SPEED_1GHZ:
2190 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2191 break;
2192 case LPFC_LINK_SPEED_2GHZ:
2193 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2194 break;
2195 case LPFC_LINK_SPEED_4GHZ:
2196 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2197 break;
2198 case LPFC_LINK_SPEED_8GHZ:
2199 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2200 break;
2201 case LPFC_LINK_SPEED_10GHZ:
2202 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2203 break;
2204 case LPFC_LINK_SPEED_16GHZ:
2205 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2206 break;
2207 case LPFC_LINK_SPEED_32GHZ:
2208 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2209 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08002210 case LPFC_LINK_SPEED_64GHZ:
2211 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2212 break;
James Smarta085e872015-12-16 18:12:02 -05002213 default:
2214 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2215 break;
2216 }
2217 } else {
2218 switch (phba->fc_linkspeed) {
2219 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2220 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2221 break;
2222 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2223 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2224 break;
2225 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2226 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2227 break;
2228 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2229 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2230 break;
2231 default:
2232 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2233 break;
2234 }
James Smart4258e982015-12-16 18:11:58 -05002235 }
James Smarta085e872015-12-16 18:12:02 -05002236
James Smart4258e982015-12-16 18:11:58 -05002237 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2238 size = FOURBYTES + sizeof(uint32_t);
2239 ad->AttrLen = cpu_to_be16(size);
2240 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2241 return size;
2242}
2243
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002244static int
James Smart4258e982015-12-16 18:11:58 -05002245lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2246 struct lpfc_fdmi_attr_def *ad)
2247{
2248 struct serv_parm *hsp;
2249 struct lpfc_fdmi_attr_entry *ae;
2250 uint32_t size;
2251
2252 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2253
2254 hsp = (struct serv_parm *)&vport->fc_sparam;
2255 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2256 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2257 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2258 size = FOURBYTES + sizeof(uint32_t);
2259 ad->AttrLen = cpu_to_be16(size);
2260 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2261 return size;
2262}
2263
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002264static int
James Smart4258e982015-12-16 18:11:58 -05002265lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2266 struct lpfc_fdmi_attr_def *ad)
2267{
2268 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2269 struct lpfc_fdmi_attr_entry *ae;
2270 uint32_t len, size;
2271
2272 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2273 memset(ae, 0, 256);
2274
2275 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2276 "/sys/class/scsi_host/host%d", shost->host_no);
2277 len = strnlen((char *)ae->un.AttrString,
2278 sizeof(ae->un.AttrString));
2279 len += (len & 3) ? (4 - (len & 3)) : 4;
2280 size = FOURBYTES + len;
2281 ad->AttrLen = cpu_to_be16(size);
2282 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2283 return size;
2284}
2285
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002286static int
James Smart4258e982015-12-16 18:11:58 -05002287lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2288 struct lpfc_fdmi_attr_def *ad)
2289{
2290 struct lpfc_fdmi_attr_entry *ae;
2291 uint32_t len, size;
2292
2293 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2294 memset(ae, 0, 256);
2295
2296 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2297 init_utsname()->nodename);
2298
2299 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2300 len += (len & 3) ? (4 - (len & 3)) : 4;
2301 size = FOURBYTES + len;
2302 ad->AttrLen = cpu_to_be16(size);
2303 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2304 return size;
2305}
2306
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002307static int
James Smart4258e982015-12-16 18:11:58 -05002308lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2309 struct lpfc_fdmi_attr_def *ad)
2310{
2311 struct lpfc_fdmi_attr_entry *ae;
2312 uint32_t size;
2313
2314 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2315 memset(ae, 0, sizeof(struct lpfc_name));
2316
2317 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2318 sizeof(struct lpfc_name));
2319 size = FOURBYTES + sizeof(struct lpfc_name);
2320 ad->AttrLen = cpu_to_be16(size);
2321 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2322 return size;
2323}
2324
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002325static int
James Smart4258e982015-12-16 18:11:58 -05002326lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2327 struct lpfc_fdmi_attr_def *ad)
2328{
2329 struct lpfc_fdmi_attr_entry *ae;
2330 uint32_t size;
2331
2332 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2333 memset(ae, 0, sizeof(struct lpfc_name));
2334
2335 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2336 sizeof(struct lpfc_name));
2337 size = FOURBYTES + sizeof(struct lpfc_name);
2338 ad->AttrLen = cpu_to_be16(size);
2339 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2340 return size;
2341}
2342
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002343static int
James Smart4258e982015-12-16 18:11:58 -05002344lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2345 struct lpfc_fdmi_attr_def *ad)
2346{
2347 struct lpfc_fdmi_attr_entry *ae;
2348 uint32_t len, size;
2349
2350 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2351 memset(ae, 0, 256);
2352
2353 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2354 len += (len & 3) ? (4 - (len & 3)) : 4;
2355 size = FOURBYTES + len;
2356 ad->AttrLen = cpu_to_be16(size);
2357 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2358 return size;
2359}
2360
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002361static int
James Smart4258e982015-12-16 18:11:58 -05002362lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2363 struct lpfc_fdmi_attr_def *ad)
2364{
2365 struct lpfc_hba *phba = vport->phba;
2366 struct lpfc_fdmi_attr_entry *ae;
2367 uint32_t size;
2368
2369 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2370 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2371 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2372 else
2373 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2374 size = FOURBYTES + sizeof(uint32_t);
2375 ad->AttrLen = cpu_to_be16(size);
2376 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2377 return size;
2378}
2379
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002380static int
James Smart4258e982015-12-16 18:11:58 -05002381lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2382 struct lpfc_fdmi_attr_def *ad)
2383{
2384 struct lpfc_fdmi_attr_entry *ae;
2385 uint32_t size;
2386
2387 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2388 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2389 size = FOURBYTES + sizeof(uint32_t);
2390 ad->AttrLen = cpu_to_be16(size);
2391 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2392 return size;
2393}
2394
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002395static int
James Smart4258e982015-12-16 18:11:58 -05002396lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2397 struct lpfc_fdmi_attr_def *ad)
2398{
2399 struct lpfc_fdmi_attr_entry *ae;
2400 uint32_t size;
2401
2402 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2403 memset(ae, 0, sizeof(struct lpfc_name));
2404
2405 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2406 sizeof(struct lpfc_name));
2407 size = FOURBYTES + sizeof(struct lpfc_name);
2408 ad->AttrLen = cpu_to_be16(size);
2409 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2410 return size;
2411}
2412
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002413static int
James Smart4258e982015-12-16 18:11:58 -05002414lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2415 struct lpfc_fdmi_attr_def *ad)
2416{
2417 struct lpfc_fdmi_attr_entry *ae;
2418 uint32_t size;
2419
2420 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2421 memset(ae, 0, 32);
2422
2423 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2424 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2425 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2426 size = FOURBYTES + 32;
2427 ad->AttrLen = cpu_to_be16(size);
2428 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2429 return size;
2430}
2431
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002432static int
James Smart4258e982015-12-16 18:11:58 -05002433lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2434 struct lpfc_fdmi_attr_def *ad)
2435{
2436 struct lpfc_fdmi_attr_entry *ae;
2437 uint32_t size;
2438
2439 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2440 /* Link Up - operational */
2441 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2442 size = FOURBYTES + sizeof(uint32_t);
2443 ad->AttrLen = cpu_to_be16(size);
2444 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2445 return size;
2446}
2447
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002448static int
James Smart4258e982015-12-16 18:11:58 -05002449lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2450 struct lpfc_fdmi_attr_def *ad)
2451{
2452 struct lpfc_fdmi_attr_entry *ae;
2453 uint32_t size;
2454
2455 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2456 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2457 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2458 size = FOURBYTES + sizeof(uint32_t);
2459 ad->AttrLen = cpu_to_be16(size);
2460 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2461 return size;
2462}
2463
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002464static int
James Smart4258e982015-12-16 18:11:58 -05002465lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2466 struct lpfc_fdmi_attr_def *ad)
2467{
2468 struct lpfc_fdmi_attr_entry *ae;
2469 uint32_t size;
2470
2471 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2472 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2473 size = FOURBYTES + sizeof(uint32_t);
2474 ad->AttrLen = cpu_to_be16(size);
2475 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2476 return size;
2477}
2478
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002479static int
James Smart4258e982015-12-16 18:11:58 -05002480lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2481 struct lpfc_fdmi_attr_def *ad)
2482{
2483 struct lpfc_fdmi_attr_entry *ae;
2484 uint32_t len, size;
2485
2486 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2487 memset(ae, 0, 256);
2488
2489 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2490 sizeof(ae->un.AttrString));
2491 len = strnlen(ae->un.AttrString,
2492 sizeof(ae->un.AttrString));
2493 len += (len & 3) ? (4 - (len & 3)) : 4;
2494 size = FOURBYTES + len;
2495 ad->AttrLen = cpu_to_be16(size);
2496 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2497 return size;
2498}
2499
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002500static int
James Smart4258e982015-12-16 18:11:58 -05002501lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2502 struct lpfc_fdmi_attr_def *ad)
2503{
2504 struct lpfc_fdmi_attr_entry *ae;
2505 uint32_t size;
2506
2507 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2508 memset(ae, 0, 256);
2509
2510 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2511 sizeof(struct lpfc_name));
2512 memcpy((((uint8_t *)&ae->un.AttrString) +
2513 sizeof(struct lpfc_name)),
2514 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2515 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2516 ad->AttrLen = cpu_to_be16(size);
2517 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2518 return size;
2519}
2520
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002521static int
James Smart4258e982015-12-16 18:11:58 -05002522lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2523 struct lpfc_fdmi_attr_def *ad)
2524{
2525 struct lpfc_fdmi_attr_entry *ae;
2526 uint32_t len, size;
2527
2528 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2529 memset(ae, 0, 256);
2530
James Smart56204982016-03-31 14:12:32 -07002531 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
James Smart4258e982015-12-16 18:11:58 -05002532 sizeof(ae->un.AttrString));
2533 len = strnlen(ae->un.AttrString,
2534 sizeof(ae->un.AttrString));
2535 len += (len & 3) ? (4 - (len & 3)) : 4;
2536 size = FOURBYTES + len;
2537 ad->AttrLen = cpu_to_be16(size);
2538 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2539 return size;
2540}
2541
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002542static int
James Smart4258e982015-12-16 18:11:58 -05002543lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2544 struct lpfc_fdmi_attr_def *ad)
2545{
2546 struct lpfc_hba *phba = vport->phba;
2547 struct lpfc_fdmi_attr_entry *ae;
2548 uint32_t len, size;
2549
2550 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2551 memset(ae, 0, 256);
2552
2553 strncpy(ae->un.AttrString, phba->ModelName,
2554 sizeof(ae->un.AttrString));
2555 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2556 len += (len & 3) ? (4 - (len & 3)) : 4;
2557 size = FOURBYTES + len;
2558 ad->AttrLen = cpu_to_be16(size);
2559 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2560 return size;
2561}
2562
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002563static int
James Smart4258e982015-12-16 18:11:58 -05002564lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2565 struct lpfc_fdmi_attr_def *ad)
2566{
2567 struct lpfc_fdmi_attr_entry *ae;
2568 uint32_t size;
2569
2570 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2571
2572 /* SRIOV (type 3) is not supported */
2573 if (vport->vpi)
2574 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2575 else
2576 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2577 size = FOURBYTES + sizeof(uint32_t);
2578 ad->AttrLen = cpu_to_be16(size);
2579 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2580 return size;
2581}
2582
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002583static int
James Smart4258e982015-12-16 18:11:58 -05002584lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2585 struct lpfc_fdmi_attr_def *ad)
2586{
2587 struct lpfc_fdmi_attr_entry *ae;
2588 uint32_t size;
2589
2590 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2591 ae->un.AttrInt = cpu_to_be32(0);
2592 size = FOURBYTES + sizeof(uint32_t);
2593 ad->AttrLen = cpu_to_be16(size);
2594 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2595 return size;
2596}
2597
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002598static int
James Smart4258e982015-12-16 18:11:58 -05002599lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2600 struct lpfc_fdmi_attr_def *ad)
2601{
2602 struct lpfc_fdmi_attr_entry *ae;
2603 uint32_t size;
2604
2605 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
James Smart56204982016-03-31 14:12:32 -07002606 ae->un.AttrInt = cpu_to_be32(1);
James Smart4258e982015-12-16 18:11:58 -05002607 size = FOURBYTES + sizeof(uint32_t);
2608 ad->AttrLen = cpu_to_be16(size);
2609 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2610 return size;
2611}
2612
2613/* RHBA attribute jump table */
2614int (*lpfc_fdmi_hba_action[])
2615 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2616 /* Action routine Mask bit Attribute type */
2617 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2618 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2619 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2620 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2621 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2622 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2623 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2624 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2625 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2626 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2627 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2628 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2629 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2630 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2631 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2632 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2633 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2634 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2635};
2636
2637/* RPA / RPRT attribute jump table */
2638int (*lpfc_fdmi_port_action[])
2639 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2640 /* Action routine Mask bit Attribute type */
2641 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2642 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2643 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2644 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2645 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2646 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2647 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2648 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2649 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2650 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2651 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2652 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2653 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2654 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2655 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2656 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2657 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2658 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2659 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2660 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2661 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2662 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2663 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2664};
2665
2666/**
2667 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2668 * @vport: pointer to a host virtual N_Port data structure.
2669 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2670 * cmdcode: FDMI command to send
2671 * mask: Mask of HBA or PORT Attributes to send
2672 *
2673 * Builds and sends a FDMI command using the CT subsystem.
2674 */
2675int
2676lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2677 int cmdcode, uint32_t new_mask)
dea31012005-04-17 16:05:31 -05002678{
James Smart2e0fef82007-06-17 19:56:36 -05002679 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002680 struct lpfc_dmabuf *mp, *bmp;
2681 struct lpfc_sli_ct_request *CtReq;
2682 struct ulp_bde64 *bpl;
James Smart4258e982015-12-16 18:11:58 -05002683 uint32_t bit_pos;
dea31012005-04-17 16:05:31 -05002684 uint32_t size;
James Smart76b2c342015-04-07 15:07:19 -04002685 uint32_t rsp_size;
James Smart4258e982015-12-16 18:11:58 -05002686 uint32_t mask;
James Smart76b2c342015-04-07 15:07:19 -04002687 struct lpfc_fdmi_reg_hba *rh;
2688 struct lpfc_fdmi_port_entry *pe;
2689 struct lpfc_fdmi_reg_portattr *pab = NULL;
2690 struct lpfc_fdmi_attr_block *ab = NULL;
James Smart4258e982015-12-16 18:11:58 -05002691 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2692 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2693 struct lpfc_iocbq *);
dea31012005-04-17 16:05:31 -05002694
James Smart4258e982015-12-16 18:11:58 -05002695 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2696 return 0;
2697
2698 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
dea31012005-04-17 16:05:31 -05002699
2700 /* fill in BDEs for command */
2701 /* Allocate buffer for command payload */
James Smart76b2c342015-04-07 15:07:19 -04002702 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002703 if (!mp)
2704 goto fdmi_cmd_exit;
2705
2706 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2707 if (!mp->virt)
2708 goto fdmi_cmd_free_mp;
2709
2710 /* Allocate buffer for Buffer ptr list */
James Smart76b2c342015-04-07 15:07:19 -04002711 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002712 if (!bmp)
2713 goto fdmi_cmd_free_mpvirt;
2714
2715 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2716 if (!bmp->virt)
2717 goto fdmi_cmd_free_bmp;
2718
2719 INIT_LIST_HEAD(&mp->list);
2720 INIT_LIST_HEAD(&bmp->list);
2721
2722 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04002723 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2724 "0218 FDMI Request Data: x%x x%x x%x\n",
2725 vport->fc_flag, vport->port_state, cmdcode);
James Smart76b2c342015-04-07 15:07:19 -04002726 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
dea31012005-04-17 16:05:31 -05002727
James Smart76b2c342015-04-07 15:07:19 -04002728 /* First populate the CT_IU preamble */
dea31012005-04-17 16:05:31 -05002729 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2730 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2731 CtReq->RevisionId.bits.InId = 0;
2732
2733 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2734 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
James Smart76b2c342015-04-07 15:07:19 -04002735
2736 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2737 rsp_size = LPFC_BPL_SIZE;
dea31012005-04-17 16:05:31 -05002738 size = 0;
2739
James Smart76b2c342015-04-07 15:07:19 -04002740 /* Next fill in the specific FDMI cmd information */
dea31012005-04-17 16:05:31 -05002741 switch (cmdcode) {
James Smart76b2c342015-04-07 15:07:19 -04002742 case SLI_MGMT_RHAT:
dea31012005-04-17 16:05:31 -05002743 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05002744 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2745 /* HBA Identifier */
2746 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2747 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002748
James Smart4258e982015-12-16 18:11:58 -05002749 if (cmdcode == SLI_MGMT_RHBA) {
2750 /* Registered Port List */
2751 /* One entry (port) per adapter */
2752 rh->rpl.EntryCnt = cpu_to_be32(1);
2753 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002754 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002755
James Smart4258e982015-12-16 18:11:58 -05002756 /* point to the HBA attribute block */
2757 size = 2 * sizeof(struct lpfc_name) +
2758 FOURBYTES;
2759 } else {
2760 size = sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002761 }
James Smart4258e982015-12-16 18:11:58 -05002762 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2763 ab->EntryCnt = 0;
2764 size += FOURBYTES;
2765 bit_pos = 0;
2766 if (new_mask)
2767 mask = new_mask;
2768 else
2769 mask = vport->fdmi_hba_mask;
2770
2771 /* Mask will dictate what attributes to build in the request */
2772 while (mask) {
2773 if (mask & 0x1) {
2774 func = lpfc_fdmi_hba_action[bit_pos];
2775 size += func(vport,
2776 (struct lpfc_fdmi_attr_def *)
2777 ((uint8_t *)rh + size));
2778 ab->EntryCnt++;
2779 if ((size + 256) >
2780 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2781 goto hba_out;
2782 }
2783 mask = mask >> 1;
2784 bit_pos++;
2785 }
2786hba_out:
2787 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2788 /* Total size */
2789 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002790 break;
2791
James Smart76b2c342015-04-07 15:07:19 -04002792 case SLI_MGMT_RPRT:
dea31012005-04-17 16:05:31 -05002793 case SLI_MGMT_RPA:
James Smart4258e982015-12-16 18:11:58 -05002794 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2795 if (cmdcode == SLI_MGMT_RPRT) {
2796 rh = (struct lpfc_fdmi_reg_hba *)pab;
2797 /* HBA Identifier */
2798 memcpy(&rh->hi.PortName,
2799 &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002800 sizeof(struct lpfc_name));
James Smart4258e982015-12-16 18:11:58 -05002801 pab = (struct lpfc_fdmi_reg_portattr *)
2802 ((uint8_t *)pab + sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002803 }
James Smart4258e982015-12-16 18:11:58 -05002804
2805 memcpy((uint8_t *)&pab->PortName,
2806 (uint8_t *)&vport->fc_sparam.portName,
2807 sizeof(struct lpfc_name));
2808 size += sizeof(struct lpfc_name) + FOURBYTES;
2809 pab->ab.EntryCnt = 0;
2810 bit_pos = 0;
2811 if (new_mask)
2812 mask = new_mask;
2813 else
2814 mask = vport->fdmi_port_mask;
2815
2816 /* Mask will dictate what attributes to build in the request */
2817 while (mask) {
2818 if (mask & 0x1) {
2819 func = lpfc_fdmi_port_action[bit_pos];
2820 size += func(vport,
2821 (struct lpfc_fdmi_attr_def *)
2822 ((uint8_t *)pab + size));
2823 pab->ab.EntryCnt++;
2824 if ((size + 256) >
2825 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2826 goto port_out;
2827 }
2828 mask = mask >> 1;
2829 bit_pos++;
2830 }
2831port_out:
2832 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2833 /* Total size */
2834 if (cmdcode == SLI_MGMT_RPRT)
2835 size += sizeof(struct lpfc_name);
2836 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002837 break;
2838
James Smart76b2c342015-04-07 15:07:19 -04002839 case SLI_MGMT_GHAT:
2840 case SLI_MGMT_GRPL:
2841 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002842 case SLI_MGMT_DHBA:
James Smart76b2c342015-04-07 15:07:19 -04002843 case SLI_MGMT_DHAT:
2844 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2845 memcpy((uint8_t *)&pe->PortName,
2846 (uint8_t *)&vport->fc_sparam.portName,
2847 sizeof(struct lpfc_name));
2848 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002849 break;
2850
James Smart76b2c342015-04-07 15:07:19 -04002851 case SLI_MGMT_GPAT:
2852 case SLI_MGMT_GPAS:
2853 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002854 case SLI_MGMT_DPRT:
James Smart76b2c342015-04-07 15:07:19 -04002855 case SLI_MGMT_DPA:
2856 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2857 memcpy((uint8_t *)&pe->PortName,
2858 (uint8_t *)&vport->fc_sparam.portName,
2859 sizeof(struct lpfc_name));
2860 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002861 break;
James Smart76b2c342015-04-07 15:07:19 -04002862 case SLI_MGMT_GRHL:
2863 size = GID_REQUEST_SZ - 4;
2864 break;
2865 default:
2866 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2867 "0298 FDMI cmdcode x%x not supported\n",
2868 cmdcode);
2869 goto fdmi_cmd_free_bmpvirt;
dea31012005-04-17 16:05:31 -05002870 }
James Smart76b2c342015-04-07 15:07:19 -04002871 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
dea31012005-04-17 16:05:31 -05002872
James Smart76b2c342015-04-07 15:07:19 -04002873 bpl = (struct ulp_bde64 *)bmp->virt;
2874 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2875 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
dea31012005-04-17 16:05:31 -05002876 bpl->tus.f.bdeFlags = 0;
2877 bpl->tus.f.bdeSize = size;
dea31012005-04-17 16:05:31 -05002878
James Smart76b2c342015-04-07 15:07:19 -04002879 /*
2880 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
James Smarte47c9092008-02-08 18:49:26 -05002881 * to hold ndlp reference for the corresponding callback function.
2882 */
James Smart76b2c342015-04-07 15:07:19 -04002883 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
dea31012005-04-17 16:05:31 -05002884 return 0;
2885
James Smart76b2c342015-04-07 15:07:19 -04002886 /*
2887 * Decrement ndlp reference count to release ndlp reference held
James Smarte47c9092008-02-08 18:49:26 -05002888 * for the failed command's callback function.
2889 */
James Smart51ef4c22007-08-02 11:10:31 -04002890 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002891
James Smart76b2c342015-04-07 15:07:19 -04002892fdmi_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05002893 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2894fdmi_cmd_free_bmp:
2895 kfree(bmp);
2896fdmi_cmd_free_mpvirt:
2897 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2898fdmi_cmd_free_mp:
2899 kfree(mp);
2900fdmi_cmd_exit:
2901 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04002902 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2903 "0244 Issue FDMI request failed Data: x%x\n",
2904 cmdcode);
dea31012005-04-17 16:05:31 -05002905 return 1;
2906}
2907
James Smart92494142011-02-16 12:39:44 -05002908/**
2909 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2910 * @ptr - Context object of the timer.
2911 *
2912 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2913 * the worker thread.
2914 **/
2915void
Kees Cookf22eb4d2017-09-06 20:24:26 -07002916lpfc_delayed_disc_tmo(struct timer_list *t)
James Smart92494142011-02-16 12:39:44 -05002917{
Kees Cookf22eb4d2017-09-06 20:24:26 -07002918 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
James Smart92494142011-02-16 12:39:44 -05002919 struct lpfc_hba *phba = vport->phba;
2920 uint32_t tmo_posted;
2921 unsigned long iflag;
2922
2923 spin_lock_irqsave(&vport->work_port_lock, iflag);
2924 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2925 if (!tmo_posted)
2926 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2927 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2928
2929 if (!tmo_posted)
2930 lpfc_worker_wake_up(phba);
2931 return;
2932}
2933
2934/**
2935 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2936 * handle delayed discovery.
2937 * @vport: pointer to a host virtual N_Port data structure.
2938 *
2939 * This function start nport discovery of the vport.
2940 **/
2941void
2942lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2943{
2944 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2945
2946 spin_lock_irq(shost->host_lock);
2947 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2948 spin_unlock_irq(shost->host_lock);
2949 return;
2950 }
2951 vport->fc_flag &= ~FC_DISC_DELAYED;
2952 spin_unlock_irq(shost->host_lock);
2953
2954 lpfc_do_scr_ns_plogi(vport->phba, vport);
2955}
2956
dea31012005-04-17 16:05:31 -05002957void
James Smart2e0fef82007-06-17 19:56:36 -05002958lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05002959{
2960 struct lpfc_sli *psli = &phba->sli;
2961 lpfc_vpd_t *vp = &phba->vpd;
2962 uint32_t b1, b2, b3, b4, i, rev;
2963 char c;
2964 uint32_t *ptr, str[4];
2965 uint8_t *fwname;
2966
James Smartf1126682009-06-10 17:22:44 -04002967 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart6b5151f2012-01-18 16:24:06 -05002968 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
James Smartf1126682009-06-10 17:22:44 -04002969 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04002970 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002971 rev = vp->rev.sli2FwRev;
2972 else
2973 rev = vp->rev.sli1FwRev;
2974
2975 b1 = (rev & 0x0000f000) >> 12;
2976 b2 = (rev & 0x00000f00) >> 8;
2977 b3 = (rev & 0x000000c0) >> 6;
2978 b4 = (rev & 0x00000030) >> 4;
2979
2980 switch (b4) {
2981 case 0:
2982 c = 'N';
2983 break;
2984 case 1:
2985 c = 'A';
2986 break;
2987 case 2:
2988 c = 'B';
2989 break;
James Smart73d91e52011-10-10 21:32:10 -04002990 case 3:
2991 c = 'X';
2992 break;
dea31012005-04-17 16:05:31 -05002993 default:
2994 c = 0;
2995 break;
2996 }
2997 b4 = (rev & 0x0000000f);
2998
James Smartf4b4c682009-05-22 14:53:12 -04002999 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05003000 fwname = vp->rev.sli2FwName;
3001 else
3002 fwname = vp->rev.sli1FwName;
3003
3004 for (i = 0; i < 16; i++)
3005 if (fwname[i] == 0x20)
3006 fwname[i] = 0;
3007
3008 ptr = (uint32_t*)fwname;
3009
3010 for (i = 0; i < 3; i++)
3011 str[i] = be32_to_cpu(*ptr++);
3012
3013 if (c == 0) {
3014 if (flag)
3015 sprintf(fwrevision, "%d.%d%d (%s)",
3016 b1, b2, b3, (char *)str);
3017 else
3018 sprintf(fwrevision, "%d.%d%d", b1,
3019 b2, b3);
3020 } else {
3021 if (flag)
3022 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3023 b1, b2, b3, c,
3024 b4, (char *)str);
3025 else
3026 sprintf(fwrevision, "%d.%d%d%c%d",
3027 b1, b2, b3, c, b4);
3028 }
3029 } else {
3030 rev = vp->rev.smFwRev;
3031
3032 b1 = (rev & 0xff000000) >> 24;
3033 b2 = (rev & 0x00f00000) >> 20;
3034 b3 = (rev & 0x000f0000) >> 16;
3035 c = (rev & 0x0000ff00) >> 8;
3036 b4 = (rev & 0x000000ff);
3037
Roel Kluind44a6d22010-01-17 16:15:57 +01003038 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05003039 }
3040 return;
3041}