blob: 2c1fe5ab3128236d9ade620c69b123a92957e607 [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 Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “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
694 /*
695 * Skip processing the NS response
696 * Re-issue the NS cmd
697 */
698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
699 "0151 Process Deferred RSCN Data: x%x x%x\n",
700 vport->fc_flag, vport->fc_rscn_id_cnt);
701 lpfc_els_handle_rscn(vport);
702
703 goto out;
704 }
705 spin_unlock_irq(shost->host_lock);
706
James Smart858c9f62007-06-17 19:56:39 -0500707 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500708 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500709 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400710 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
James Smartedb22f02012-10-31 14:45:21 -0400711 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
James Smarte3d2b802012-08-14 14:25:43 -0400712 IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500713 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500714
James Smarta0f2d3e2017-02-12 13:52:31 -0800715 type = lpfc_get_gidft_type(vport, cmdiocb);
716 if (type == 0)
717 goto out;
718
James Smart58da1ff2008-04-07 10:15:56 -0400719 /* CT command is being retried */
James Smarta0f2d3e2017-02-12 13:52:31 -0800720 vport->gidft_inp--;
James Smart58da1ff2008-04-07 10:15:56 -0400721 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smarta0f2d3e2017-02-12 13:52:31 -0800722 vport->fc_ns_retry, type);
James Smart58da1ff2008-04-07 10:15:56 -0400723 if (rc == 0)
724 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500725 }
James Smarteada2722008-12-04 22:39:13 -0500726 if (vport->fc_flag & FC_RSCN_MODE)
727 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500728 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400729 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
730 "0257 GID_FT Query error: 0x%x 0x%x\n",
731 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500732 } else {
733 /* Good status, continue checking */
James Smarta0f2d3e2017-02-12 13:52:31 -0800734 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
dea31012005-04-17 16:05:31 -0500735 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
736 if (CTrsp->CommandResponse.bits.CmdRsp ==
James Smart76b2c342015-04-07 15:07:19 -0400737 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400738 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800739 "0208 NameServer Rsp Data: x%x x%x\n",
740 vport->fc_flag,
741 CTreq->un.gid.Fc4Type);
742
743 lpfc_ns_rsp(vport,
744 outp,
745 CTreq->un.gid.Fc4Type,
dea31012005-04-17 16:05:31 -0500746 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
747 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
748 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
749 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400750 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
751 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400752 lpfc_printf_vlog(vport, KERN_INFO,
753 LOG_DISCOVERY,
754 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400755 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400756 CTrsp->CommandResponse.bits.CmdRsp,
757 (uint32_t) CTrsp->ReasonCode,
758 (uint32_t) CTrsp->Explanation,
759 vport->fc_flag);
760
761 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
762 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
763 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
764 (uint32_t) CTrsp->ReasonCode,
765 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400766 } else {
767 lpfc_printf_vlog(vport, KERN_INFO,
768 LOG_DISCOVERY,
769 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500770 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500771 CTrsp->CommandResponse.bits.CmdRsp,
772 (uint32_t) CTrsp->ReasonCode,
773 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500774 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500775
James Smarta58cbd52007-08-02 11:09:43 -0400776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500777 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
778 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
779 (uint32_t) CTrsp->ReasonCode,
780 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400781 }
782
James Smart858c9f62007-06-17 19:56:39 -0500783
dea31012005-04-17 16:05:31 -0500784 } else {
785 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400786 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
787 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500788 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500789 CTrsp->CommandResponse.bits.CmdRsp,
790 (uint32_t) CTrsp->ReasonCode,
791 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500792 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500793
794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
795 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
796 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
797 (uint32_t) CTrsp->ReasonCode,
798 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500799 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800800 vport->gidft_inp--;
dea31012005-04-17 16:05:31 -0500801 }
802 /* Link up / RSCN discovery */
James Smarta0f2d3e2017-02-12 13:52:31 -0800803 if ((vport->num_disc_nodes == 0) &&
804 (vport->gidft_inp == 0)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500805 /*
806 * The driver has cycled through all Nports in the RSCN payload.
807 * Complete the handling by cleaning up and marking the
808 * current driver state.
809 */
810 if (vport->port_state >= LPFC_DISC_AUTH) {
811 if (vport->fc_flag & FC_RSCN_MODE) {
812 lpfc_els_flush_rscn(vport);
813 spin_lock_irq(shost->host_lock);
814 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
815 spin_unlock_irq(shost->host_lock);
816 }
817 else
818 lpfc_els_flush_rscn(vport);
819 }
820
821 lpfc_disc_start(vport);
822 }
dea31012005-04-17 16:05:31 -0500823out:
James Smart51ef4c22007-08-02 11:10:31 -0400824 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500825 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500826 return;
827}
828
James Smart311464e2007-08-02 11:10:37 -0400829static void
James Smart92d7f7b2007-06-17 19:56:38 -0500830lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
831 struct lpfc_iocbq *rspiocb)
832{
833 struct lpfc_vport *vport = cmdiocb->vport;
834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
835 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500836 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
837 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
838 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500839 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500840 uint8_t fbits;
841 struct lpfc_nodelist *ndlp;
842
843 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
844 did = be32_to_cpu(did);
845
James Smart858c9f62007-06-17 19:56:39 -0500846 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
847 "GFF_ID cmpl: status:x%x/x%x did:x%x",
848 irsp->ulpStatus, irsp->un.ulpWord[4], did);
849
James Smart92d7f7b2007-06-17 19:56:38 -0500850 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
851 /* Good status, continue checking */
852 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
853 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
854
855 if (CTrsp->CommandResponse.bits.CmdRsp ==
856 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
857 if ((fbits & FC4_FEATURE_INIT) &&
858 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400859 lpfc_printf_vlog(vport, KERN_INFO,
860 LOG_DISCOVERY,
861 "0270 Skip x%x GFF "
862 "NameServer Rsp Data: (init) "
863 "x%x x%x\n", did, fbits,
864 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500865 goto out;
866 }
867 }
868 }
James Smart858c9f62007-06-17 19:56:39 -0500869 else {
James Smart0ff10d42008-01-11 01:52:36 -0500870 /* Check for retry */
871 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
872 retry = 1;
873 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
James Smarte3d2b802012-08-14 14:25:43 -0400874 switch ((irsp->un.ulpWord[4] &
875 IOERR_PARAM_MASK)) {
876
James Smart0ff10d42008-01-11 01:52:36 -0500877 case IOERR_NO_RESOURCES:
878 /* We don't increment the retry
879 * count for this case.
880 */
881 break;
882 case IOERR_LINK_DOWN:
883 case IOERR_SLI_ABORTED:
884 case IOERR_SLI_DOWN:
885 retry = 0;
886 break;
887 default:
888 cmdiocb->retry++;
889 }
890 }
891 else
892 cmdiocb->retry++;
893
894 if (retry) {
895 /* CT command is being retried */
896 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
897 cmdiocb->retry, did);
898 if (rc == 0) {
899 /* success */
900 lpfc_ct_free_iocb(phba, cmdiocb);
901 return;
902 }
903 }
904 }
James Smarte8b62012007-08-02 11:10:09 -0400905 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
906 "0267 NameServer GFF Rsp "
907 "x%x Error (%d %d) Data: x%x x%x\n",
908 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500909 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500910 }
911
James Smart92d7f7b2007-06-17 19:56:38 -0500912 /* This is a target port, unregistered port, or the GFF_ID failed */
913 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400914 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400915 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
916 "0242 Process x%x GFF "
917 "NameServer Rsp Data: x%x x%x x%x\n",
918 did, ndlp->nlp_flag, vport->fc_flag,
919 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500920 } else {
James Smarte8b62012007-08-02 11:10:09 -0400921 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
922 "0243 Skip x%x GFF "
923 "NameServer Rsp Data: x%x x%x\n", did,
924 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500925 }
926out:
927 /* Link up / RSCN discovery */
928 if (vport->num_disc_nodes)
929 vport->num_disc_nodes--;
930 if (vport->num_disc_nodes == 0) {
931 /*
932 * The driver has cycled through all Nports in the RSCN payload.
933 * Complete the handling by cleaning up and marking the
934 * current driver state.
935 */
936 if (vport->port_state >= LPFC_DISC_AUTH) {
937 if (vport->fc_flag & FC_RSCN_MODE) {
938 lpfc_els_flush_rscn(vport);
939 spin_lock_irq(shost->host_lock);
940 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
941 spin_unlock_irq(shost->host_lock);
942 }
943 else
944 lpfc_els_flush_rscn(vport);
945 }
946 lpfc_disc_start(vport);
947 }
James Smart858c9f62007-06-17 19:56:39 -0500948 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500949 return;
950}
951
James Smarta0f2d3e2017-02-12 13:52:31 -0800952static void
953lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
954 struct lpfc_iocbq *rspiocb)
955{
956 struct lpfc_vport *vport = cmdiocb->vport;
957 IOCB_t *irsp = &rspiocb->iocb;
958 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
959 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
960 struct lpfc_sli_ct_request *CTrsp;
961 int did;
962 struct lpfc_nodelist *ndlp;
963 uint32_t fc4_data_0, fc4_data_1;
964
965 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
966 did = be32_to_cpu(did);
967
James Smartbd2cdd52017-02-12 13:52:33 -0800968 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
969 "GFT_ID cmpl: status:x%x/x%x did:x%x",
970 irsp->ulpStatus, irsp->un.ulpWord[4], did);
971
James Smarta0f2d3e2017-02-12 13:52:31 -0800972 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
973 /* Good status, continue checking */
974 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
975 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
976 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700977 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800978 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
979 did, fc4_data_0, fc4_data_1);
980
981 ndlp = lpfc_findnode_did(vport, did);
982 if (ndlp) {
983 /* The bitmask value for FCP and NVME FCP types is
984 * the same because they are 32 bits distant from
985 * each other in word0 and word0.
986 */
987 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
988 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
989 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
990 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700991 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800992 "3064 Setting ndlp %p, DID x%06x with "
993 "FC4 x%08x, Data: x%08x x%08x\n",
994 ndlp, did, ndlp->nlp_fc4_type,
995 FC_TYPE_FCP, FC_TYPE_NVME);
James Smartb5ccc7d2017-03-04 09:30:39 -0800996 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
Gustavo A. R. Silvae6ef6a72017-05-23 10:09:28 -0500997
998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
999 lpfc_issue_els_prli(vport, ndlp, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08001000 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001001 } else
1002 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1003 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1004
1005 lpfc_ct_free_iocb(phba, cmdiocb);
1006}
James Smart92d7f7b2007-06-17 19:56:38 -05001007
dea31012005-04-17 16:05:31 -05001008static void
James Smart7ee5d432007-10-27 13:37:17 -04001009lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1010 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001011{
James Smart92d7f7b2007-06-17 19:56:38 -05001012 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001013 struct lpfc_dmabuf *inp;
1014 struct lpfc_dmabuf *outp;
1015 IOCB_t *irsp;
1016 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -04001017 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05001018 int cmdcode, rc;
1019 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -05001020 uint32_t latt;
dea31012005-04-17 16:05:31 -05001021
James Smart51ef4c22007-08-02 11:10:31 -04001022 /* First save ndlp, before we overwrite it */
1023 ndlp = cmdiocb->context_un.ndlp;
1024
dea31012005-04-17 16:05:31 -05001025 /* we pass cmdiocb to state machine which needs rspiocb as well */
1026 cmdiocb->context_un.rsp_iocb = rspiocb;
1027
1028 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1029 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001030 irsp = &rspiocb->iocb;
1031
James Smart92d7f7b2007-06-17 19:56:38 -05001032 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1033 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -05001034 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1035
James Smart858c9f62007-06-17 19:56:39 -05001036 latt = lpfc_els_chk_latt(vport);
1037
1038 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -04001039 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -04001040 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -04001041 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1042 latt, irsp->ulpStatus,
1043 CTrsp->CommandResponse.bits.CmdRsp,
1044 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05001045
James Smart858c9f62007-06-17 19:56:39 -05001046 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1047 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1048 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1049
James Smart92d7f7b2007-06-17 19:56:38 -05001050 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001051 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6e155202013-07-15 18:35:21 -04001052 "0268 NS cmd x%x Error (x%x x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04001053 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001054
James Smart92d7f7b2007-06-17 19:56:38 -05001055 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001056 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1057 IOERR_SLI_DOWN) ||
1058 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1059 IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -05001060 goto out;
1061
1062 retry = cmdiocb->retry;
1063 if (retry >= LPFC_MAX_NS_RETRY)
1064 goto out;
1065
1066 retry++;
James Smarte8b62012007-08-02 11:10:09 -04001067 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04001068 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -05001069 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1070 if (rc == 0)
1071 goto out;
1072 }
1073
1074out:
James Smart51ef4c22007-08-02 11:10:31 -04001075 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -05001076 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001077 return;
1078}
1079
1080static void
James Smart7ee5d432007-10-27 13:37:17 -04001081lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1082 struct lpfc_iocbq *rspiocb)
1083{
1084 IOCB_t *irsp = &rspiocb->iocb;
1085 struct lpfc_vport *vport = cmdiocb->vport;
1086
James Smart98c9ea52007-10-27 13:37:33 -04001087 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1088 struct lpfc_dmabuf *outp;
1089 struct lpfc_sli_ct_request *CTrsp;
1090
1091 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1092 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1093 if (CTrsp->CommandResponse.bits.CmdRsp ==
1094 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1095 vport->ct_flags |= FC_CT_RFT_ID;
1096 }
James Smart7ee5d432007-10-27 13:37:17 -04001097 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1098 return;
1099}
1100
1101static void
James Smart2e0fef82007-06-17 19:56:36 -05001102lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1103 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001104{
James Smart7ee5d432007-10-27 13:37:17 -04001105 IOCB_t *irsp = &rspiocb->iocb;
1106 struct lpfc_vport *vport = cmdiocb->vport;
1107
James Smart98c9ea52007-10-27 13:37:33 -04001108 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1109 struct lpfc_dmabuf *outp;
1110 struct lpfc_sli_ct_request *CTrsp;
1111
1112 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1113 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1114 if (CTrsp->CommandResponse.bits.CmdRsp ==
1115 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1116 vport->ct_flags |= FC_CT_RNN_ID;
1117 }
James Smart7ee5d432007-10-27 13:37:17 -04001118 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001119 return;
1120}
1121
1122static void
James Smart92d7f7b2007-06-17 19:56:38 -05001123lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1124 struct lpfc_iocbq *rspiocb)
1125{
James Smart7ee5d432007-10-27 13:37:17 -04001126 IOCB_t *irsp = &rspiocb->iocb;
1127 struct lpfc_vport *vport = cmdiocb->vport;
1128
James Smart98c9ea52007-10-27 13:37:33 -04001129 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1130 struct lpfc_dmabuf *outp;
1131 struct lpfc_sli_ct_request *CTrsp;
1132
1133 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1134 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1135 if (CTrsp->CommandResponse.bits.CmdRsp ==
1136 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1137 vport->ct_flags |= FC_CT_RSPN_ID;
1138 }
James Smart7ee5d432007-10-27 13:37:17 -04001139 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05001140 return;
1141}
1142
1143static void
James Smart2e0fef82007-06-17 19:56:36 -05001144lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1145 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001146{
James Smart7ee5d432007-10-27 13:37:17 -04001147 IOCB_t *irsp = &rspiocb->iocb;
1148 struct lpfc_vport *vport = cmdiocb->vport;
1149
James Smart98c9ea52007-10-27 13:37:33 -04001150 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1151 struct lpfc_dmabuf *outp;
1152 struct lpfc_sli_ct_request *CTrsp;
1153
1154 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1155 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1156 if (CTrsp->CommandResponse.bits.CmdRsp ==
1157 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1158 vport->ct_flags |= FC_CT_RSNN_NN;
1159 }
James Smart7ee5d432007-10-27 13:37:17 -04001160 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1161 return;
1162}
1163
1164static void
1165lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1166 struct lpfc_iocbq *rspiocb)
1167{
1168 struct lpfc_vport *vport = cmdiocb->vport;
1169
1170 /* even if it fails we will act as though it succeeded. */
1171 vport->ct_flags = 0;
1172 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001173 return;
1174}
1175
James Smart2fb9bd82006-12-02 13:33:57 -05001176static void
James Smart92d7f7b2007-06-17 19:56:38 -05001177lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1178 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001179{
James Smart92d7f7b2007-06-17 19:56:38 -05001180 IOCB_t *irsp = &rspiocb->iocb;
1181 struct lpfc_vport *vport = cmdiocb->vport;
1182
James Smart98c9ea52007-10-27 13:37:33 -04001183 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1184 struct lpfc_dmabuf *outp;
1185 struct lpfc_sli_ct_request *CTrsp;
1186
1187 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1188 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1189 if (CTrsp->CommandResponse.bits.CmdRsp ==
1190 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1191 vport->ct_flags |= FC_CT_RFF_ID;
1192 }
James Smart7ee5d432007-10-27 13:37:17 -04001193 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001194 return;
1195}
1196
James Smarta0f2d3e2017-02-12 13:52:31 -08001197/*
1198 * Although the symbolic port name is thought to be an integer
1199 * as of January 18, 2016, leave it as a string until more of
1200 * the record state becomes defined.
1201 */
James Smart495a7142008-06-14 22:52:59 -04001202int
James Smart92d7f7b2007-06-17 19:56:38 -05001203lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1204 size_t size)
1205{
1206 int n;
James Smart92d7f7b2007-06-17 19:56:38 -05001207
James Smarta0f2d3e2017-02-12 13:52:31 -08001208 /*
1209 * Use the lpfc board number as the Symbolic Port
1210 * Name object. NPIV is not in play so this integer
1211 * value is sufficient and unique per FC-ID.
1212 */
1213 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
James Smart92d7f7b2007-06-17 19:56:38 -05001214 return n;
1215}
1216
James Smarta0f2d3e2017-02-12 13:52:31 -08001217
James Smart92d7f7b2007-06-17 19:56:38 -05001218int
1219lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1220 size_t size)
dea31012005-04-17 16:05:31 -05001221{
James Smart6b5151f2012-01-18 16:24:06 -05001222 char fwrev[FW_REV_STR_SIZE];
James Smart92d7f7b2007-06-17 19:56:38 -05001223 int n;
dea31012005-04-17 16:05:31 -05001224
James Smart92d7f7b2007-06-17 19:56:38 -05001225 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001226
James Smartf0bf5f92015-04-07 15:07:18 -04001227 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
James Smartf0bf5f92015-04-07 15:07:18 -04001228 if (size < n)
1229 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001230
James Smartf0bf5f92015-04-07 15:07:18 -04001231 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
James Smartf0bf5f92015-04-07 15:07:18 -04001232 if (size < n)
1233 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001234
James Smarta0f2d3e2017-02-12 13:52:31 -08001235 n += snprintf(symbol + n, size - n, " DV%s.",
1236 lpfc_release_version);
James Smartf0bf5f92015-04-07 15:07:18 -04001237 if (size < n)
1238 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001239
1240 n += snprintf(symbol + n, size - n, " HN:%s.",
1241 init_utsname()->nodename);
1242 if (size < n)
1243 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001244
1245 /* Note :- OS name is "Linux" */
James Smarta0f2d3e2017-02-12 13:52:31 -08001246 n += snprintf(symbol + n, size - n, " OS:%s\n",
1247 init_utsname()->sysname);
James Smart92d7f7b2007-06-17 19:56:38 -05001248 return n;
dea31012005-04-17 16:05:31 -05001249}
1250
James Smart76b2c342015-04-07 15:07:19 -04001251static uint32_t
1252lpfc_find_map_node(struct lpfc_vport *vport)
1253{
1254 struct lpfc_nodelist *ndlp, *next_ndlp;
1255 struct Scsi_Host *shost;
1256 uint32_t cnt = 0;
1257
1258 shost = lpfc_shost_from_vport(vport);
1259 spin_lock_irq(shost->host_lock);
1260 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1261 if (ndlp->nlp_type & NLP_FABRIC)
1262 continue;
1263 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1264 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1265 cnt++;
1266 }
1267 spin_unlock_irq(shost->host_lock);
1268 return cnt;
1269}
1270
dea31012005-04-17 16:05:31 -05001271/*
James Smarta0f2d3e2017-02-12 13:52:31 -08001272 * This routine will return the FC4 Type associated with the CT
1273 * GID_FT command.
1274 */
1275int
1276lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1277{
1278 struct lpfc_sli_ct_request *CtReq;
1279 struct lpfc_dmabuf *mp;
1280 uint32_t type;
1281
1282 mp = cmdiocb->context1;
1283 if (mp == NULL)
1284 return 0;
1285 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1286 type = (uint32_t)CtReq->un.gid.Fc4Type;
1287 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1288 return 0;
1289 return type;
1290}
1291
1292/*
dea31012005-04-17 16:05:31 -05001293 * lpfc_ns_cmd
1294 * Description:
1295 * Issue Cmd to NameServer
1296 * SLI_CTNS_GID_FT
1297 * LI_CTNS_RFT_ID
1298 */
1299int
James Smart92d7f7b2007-06-17 19:56:38 -05001300lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1301 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001302{
James Smart92d7f7b2007-06-17 19:56:38 -05001303 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001304 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001305 struct lpfc_dmabuf *mp, *bmp;
1306 struct lpfc_sli_ct_request *CtReq;
1307 struct ulp_bde64 *bpl;
1308 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1309 struct lpfc_iocbq *) = NULL;
1310 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001311 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001312 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001313
1314 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001315 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1316 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001317 rc=1;
1318 goto ns_cmd_exit;
1319 }
dea31012005-04-17 16:05:31 -05001320
1321 /* fill in BDEs for command */
1322 /* Allocate buffer for command payload */
James Smart4258e982015-12-16 18:11:58 -05001323 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001324 if (!mp) {
1325 rc=2;
dea31012005-04-17 16:05:31 -05001326 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001327 }
dea31012005-04-17 16:05:31 -05001328
1329 INIT_LIST_HEAD(&mp->list);
1330 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001331 if (!mp->virt) {
1332 rc=3;
dea31012005-04-17 16:05:31 -05001333 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001334 }
dea31012005-04-17 16:05:31 -05001335
1336 /* Allocate buffer for Buffer ptr list */
James Smart4258e982015-12-16 18:11:58 -05001337 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001338 if (!bmp) {
1339 rc=4;
dea31012005-04-17 16:05:31 -05001340 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001341 }
dea31012005-04-17 16:05:31 -05001342
1343 INIT_LIST_HEAD(&bmp->list);
1344 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001345 if (!bmp->virt) {
1346 rc=5;
dea31012005-04-17 16:05:31 -05001347 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001348 }
dea31012005-04-17 16:05:31 -05001349
1350 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001351 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -08001352 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1353 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1354 context);
dea31012005-04-17 16:05:31 -05001355
1356 bpl = (struct ulp_bde64 *) bmp->virt;
1357 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001358 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1359 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001360 bpl->tus.f.bdeFlags = 0;
1361 if (cmdcode == SLI_CTNS_GID_FT)
1362 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001363 else if (cmdcode == SLI_CTNS_GFF_ID)
1364 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
James Smarta0f2d3e2017-02-12 13:52:31 -08001365 else if (cmdcode == SLI_CTNS_GFT_ID)
1366 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001367 else if (cmdcode == SLI_CTNS_RFT_ID)
1368 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1369 else if (cmdcode == SLI_CTNS_RNN_ID)
1370 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001371 else if (cmdcode == SLI_CTNS_RSPN_ID)
1372 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001373 else if (cmdcode == SLI_CTNS_RSNN_NN)
1374 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001375 else if (cmdcode == SLI_CTNS_DA_ID)
1376 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001377 else if (cmdcode == SLI_CTNS_RFF_ID)
1378 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001379 else
1380 bpl->tus.f.bdeSize = 0;
1381 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1382
1383 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
James Smart4258e982015-12-16 18:11:58 -05001384 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
dea31012005-04-17 16:05:31 -05001385 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1386 CtReq->RevisionId.bits.InId = 0;
1387 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1388 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1389 CtReq->CommandResponse.bits.Size = 0;
1390 switch (cmdcode) {
1391 case SLI_CTNS_GID_FT:
1392 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001393 cpu_to_be16(SLI_CTNS_GID_FT);
James Smarta0f2d3e2017-02-12 13:52:31 -08001394 CtReq->un.gid.Fc4Type = context;
1395
James Smart92d7f7b2007-06-17 19:56:38 -05001396 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001397 vport->port_state = LPFC_NS_QRY;
1398 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001399 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1400 rsp_size = FC_MAX_NS_RSP;
1401 break;
1402
James Smart92d7f7b2007-06-17 19:56:38 -05001403 case SLI_CTNS_GFF_ID:
1404 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001405 cpu_to_be16(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001406 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001407 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1408 break;
1409
James Smarta0f2d3e2017-02-12 13:52:31 -08001410 case SLI_CTNS_GFT_ID:
1411 CtReq->CommandResponse.bits.CmdRsp =
1412 cpu_to_be16(SLI_CTNS_GFT_ID);
1413 CtReq->un.gft.PortId = cpu_to_be32(context);
1414 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1415 break;
1416
dea31012005-04-17 16:05:31 -05001417 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001418 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001419 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001420 cpu_to_be16(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001421 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
James Smarta0f2d3e2017-02-12 13:52:31 -08001422
1423 /* Register FC4 FCP type if enabled. */
1424 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1425 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1426 CtReq->un.rft.fcpReg = 1;
1427
1428 /* Register NVME type if enabled. Defined LE and swapped.
1429 * rsvd[0] is used as word1 because of the hard-coded
1430 * word0 usage in the ct_request data structure.
1431 */
1432 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1433 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1434 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1435
dea31012005-04-17 16:05:31 -05001436 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1437 break;
1438
1439 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001440 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001441 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001442 cpu_to_be16(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001443 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001444 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001445 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001446 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1447 break;
1448
James Smart92d7f7b2007-06-17 19:56:38 -05001449 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001450 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001451 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001452 cpu_to_be16(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001453 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001454 size = sizeof(CtReq->un.rspn.symbname);
1455 CtReq->un.rspn.len =
1456 lpfc_vport_symbolic_port_name(vport,
1457 CtReq->un.rspn.symbname, size);
1458 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1459 break;
dea31012005-04-17 16:05:31 -05001460 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001461 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001462 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001463 cpu_to_be16(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001464 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001465 sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001466 size = sizeof(CtReq->un.rsnn.symbname);
1467 CtReq->un.rsnn.len =
1468 lpfc_vport_symbolic_node_name(vport,
1469 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001470 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1471 break;
James Smart7ee5d432007-10-27 13:37:17 -04001472 case SLI_CTNS_DA_ID:
1473 /* Implement DA_ID Nameserver request */
1474 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001475 cpu_to_be16(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001476 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001477 cmpl = lpfc_cmpl_ct_cmd_da_id;
1478 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001479 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001480 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001481 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001482 cpu_to_be16(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001483 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001484 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smarta0f2d3e2017-02-12 13:52:31 -08001485
1486 /* The driver always supports FC_TYPE_FCP. However, the
1487 * caller can specify NVME (type x28) as well. But only
1488 * these that FC4 type is supported.
1489 */
1490 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1491 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1492 (context == FC_TYPE_NVME)) {
James Smart8c258642017-02-12 13:52:36 -08001493 if ((vport == phba->pport) && phba->nvmet_support) {
1494 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1495 FC4_FEATURE_NVME_DISC);
James Smartd613b6a2017-02-12 13:52:37 -08001496 lpfc_nvmet_update_targetport(phba);
James Smart8c258642017-02-12 13:52:36 -08001497 } else {
1498 lpfc_nvme_update_localport(vport);
1499 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001500 CtReq->un.rff.type_code = context;
1501
1502 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1503 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1504 (context == FC_TYPE_FCP))
1505 CtReq->un.rff.type_code = context;
1506
1507 else
1508 goto ns_cmd_free_bmpvirt;
1509
James Smart92d7f7b2007-06-17 19:56:38 -05001510 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1511 break;
dea31012005-04-17 16:05:31 -05001512 }
James Smarte47c9092008-02-08 18:49:26 -05001513 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1514 * to hold ndlp reference for the corresponding callback function.
1515 */
James Smart858c9f62007-06-17 19:56:39 -05001516 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001517 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001518 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1519 "Issue CT cmd: cmd:x%x did:x%x",
1520 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001521 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001522 }
James Smart858c9f62007-06-17 19:56:39 -05001523 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001524
1525 /* Decrement ndlp reference count to release ndlp reference held
1526 * for the failed command's callback function.
1527 */
James Smart51ef4c22007-08-02 11:10:31 -04001528 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001529
James Smarta0f2d3e2017-02-12 13:52:31 -08001530ns_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05001531 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1532ns_cmd_free_bmp:
1533 kfree(bmp);
1534ns_cmd_free_mpvirt:
1535 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1536ns_cmd_free_mp:
1537 kfree(mp);
1538ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001539 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1540 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1541 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001542 return 1;
1543}
1544
James Smart4258e982015-12-16 18:11:58 -05001545/**
1546 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1547 * @phba: Pointer to HBA context object.
1548 * @cmdiocb: Pointer to the command IOCBQ.
1549 * @rspiocb: Pointer to the response IOCBQ.
1550 *
1551 * This function to handle the completion of a driver initiated FDMI
1552 * CT command issued during discovery.
1553 */
dea31012005-04-17 16:05:31 -05001554static void
James Smart4258e982015-12-16 18:11:58 -05001555lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1556 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001557{
James Smart4258e982015-12-16 18:11:58 -05001558 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001559 struct lpfc_dmabuf *inp = cmdiocb->context1;
1560 struct lpfc_dmabuf *outp = cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001561 struct lpfc_sli_ct_request *CTcmd = inp->virt;
James Smart4258e982015-12-16 18:11:58 -05001562 struct lpfc_sli_ct_request *CTrsp = outp->virt;
dea31012005-04-17 16:05:31 -05001563 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1564 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart858c9f62007-06-17 19:56:39 -05001565 IOCB_t *irsp = &rspiocb->iocb;
James Smart4258e982015-12-16 18:11:58 -05001566 struct lpfc_nodelist *ndlp;
1567 uint32_t latt, cmd, err;
James Smart858c9f62007-06-17 19:56:39 -05001568
1569 latt = lpfc_els_chk_latt(vport);
James Smart858c9f62007-06-17 19:56:39 -05001570 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1571 "FDMI cmpl: status:x%x/x%x latt:%d",
1572 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1573
1574 if (latt || irsp->ulpStatus) {
James Smart4258e982015-12-16 18:11:58 -05001575
1576 /* Look for a retryable error */
1577 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1578 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1579 case IOERR_SLI_ABORTED:
1580 case IOERR_ABORT_IN_PROGRESS:
1581 case IOERR_SEQUENCE_TIMEOUT:
1582 case IOERR_ILLEGAL_FRAME:
1583 case IOERR_NO_RESOURCES:
1584 case IOERR_ILLEGAL_COMMAND:
1585 cmdiocb->retry++;
1586 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1587 break;
1588
1589 /* Retry the same FDMI command */
1590 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1591 cmdiocb, 0);
1592 if (err == IOCB_ERROR)
1593 break;
1594 return;
1595 default:
1596 break;
1597 }
1598 }
1599
James Smarte8b62012007-08-02 11:10:09 -04001600 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1601 "0229 FDMI cmd %04x failed, latt = %d "
1602 "ulpStatus: x%x, rid x%x\n",
1603 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1604 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001605 }
James Smart76b2c342015-04-07 15:07:19 -04001606 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart76b2c342015-04-07 15:07:19 -04001607
1608 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1609 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1610 return;
1611
James Smart4258e982015-12-16 18:11:58 -05001612 /* Check for a CT LS_RJT response */
1613 cmd = be16_to_cpu(fdmi_cmd);
1614 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1615 /* FDMI rsp failed */
1616 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1617 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1618
1619 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1620 switch (cmd) {
1621 case SLI_MGMT_RHBA:
1622 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1623 /* Fallback to FDMI-1 */
1624 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1625 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1626 /* Start over */
1627 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1628 }
1629 return;
1630
1631 case SLI_MGMT_RPRT:
1632 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1633 /* Fallback to FDMI-1 */
1634 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1635 /* Start over */
1636 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1637 }
1638 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1639 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1640 /* Retry the same command */
1641 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1642 }
1643 return;
1644
1645 case SLI_MGMT_RPA:
1646 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1647 /* Fallback to FDMI-1 */
1648 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1649 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1650 /* Start over */
1651 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1652 }
1653 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1654 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1655 /* Retry the same command */
1656 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1657 }
1658 return;
1659 }
1660 }
1661
James Smart76b2c342015-04-07 15:07:19 -04001662 /*
James Smart4258e982015-12-16 18:11:58 -05001663 * On success, need to cycle thru FDMI registration for discovery
1664 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1665 * DPRT -> RPRT (vports)
James Smart76b2c342015-04-07 15:07:19 -04001666 */
James Smart4258e982015-12-16 18:11:58 -05001667 switch (cmd) {
dea31012005-04-17 16:05:31 -05001668 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05001669 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
dea31012005-04-17 16:05:31 -05001670 break;
1671
dea31012005-04-17 16:05:31 -05001672 case SLI_MGMT_DHBA:
James Smart4258e982015-12-16 18:11:58 -05001673 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
dea31012005-04-17 16:05:31 -05001674 break;
1675
1676 case SLI_MGMT_DPRT:
James Smart4258e982015-12-16 18:11:58 -05001677 if (vport->port_type == LPFC_PHYSICAL_PORT)
1678 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1679 else
1680 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
dea31012005-04-17 16:05:31 -05001681 break;
1682 }
James Smart4258e982015-12-16 18:11:58 -05001683 return;
dea31012005-04-17 16:05:31 -05001684}
James Smart2e0fef82007-06-17 19:56:36 -05001685
James Smart76b2c342015-04-07 15:07:19 -04001686
James Smart4258e982015-12-16 18:11:58 -05001687/**
1688 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1689 * @vport: pointer to a host virtual N_Port data structure.
1690 *
1691 * Called from hbeat timeout routine to check if the number of discovered
1692 * ports has changed. If so, re-register thar port Attribute.
1693 */
1694void
1695lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1696{
1697 struct lpfc_hba *phba = vport->phba;
1698 struct lpfc_nodelist *ndlp;
1699 uint16_t cnt;
1700
1701 if (!lpfc_is_link_up(phba))
1702 return;
1703
James Smarta03a4212016-07-06 12:36:12 -07001704 /* Must be connected to a Fabric */
1705 if (!(vport->fc_flag & FC_FABRIC))
1706 return;
1707
James Smart4258e982015-12-16 18:11:58 -05001708 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1709 return;
1710
1711 cnt = lpfc_find_map_node(vport);
1712 if (cnt == vport->fdmi_num_disc)
1713 return;
1714
1715 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1716 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1717 return;
1718
1719 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1720 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1721 LPFC_FDMI_PORT_ATTR_num_disc);
1722 } else {
1723 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1724 LPFC_FDMI_PORT_ATTR_num_disc);
1725 }
1726}
1727
1728/* Routines for all individual HBA attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001729static int
James Smart4258e982015-12-16 18:11:58 -05001730lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1731{
1732 struct lpfc_fdmi_attr_entry *ae;
1733 uint32_t size;
1734
1735 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1736 memset(ae, 0, sizeof(struct lpfc_name));
1737
1738 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1739 sizeof(struct lpfc_name));
1740 size = FOURBYTES + sizeof(struct lpfc_name);
1741 ad->AttrLen = cpu_to_be16(size);
1742 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1743 return size;
1744}
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001745static int
James Smart4258e982015-12-16 18:11:58 -05001746lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1747 struct lpfc_fdmi_attr_def *ad)
1748{
1749 struct lpfc_fdmi_attr_entry *ae;
1750 uint32_t len, size;
1751
1752 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1753 memset(ae, 0, 256);
1754
1755 strncpy(ae->un.AttrString,
1756 "Emulex Corporation",
1757 sizeof(ae->un.AttrString));
1758 len = strnlen(ae->un.AttrString,
1759 sizeof(ae->un.AttrString));
1760 len += (len & 3) ? (4 - (len & 3)) : 4;
1761 size = FOURBYTES + len;
1762 ad->AttrLen = cpu_to_be16(size);
1763 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1764 return size;
1765}
1766
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001767static int
James Smart4258e982015-12-16 18:11:58 -05001768lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1769{
1770 struct lpfc_hba *phba = vport->phba;
1771 struct lpfc_fdmi_attr_entry *ae;
1772 uint32_t len, size;
1773
1774 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1775 memset(ae, 0, 256);
1776
1777 strncpy(ae->un.AttrString, phba->SerialNumber,
1778 sizeof(ae->un.AttrString));
1779 len = strnlen(ae->un.AttrString,
1780 sizeof(ae->un.AttrString));
1781 len += (len & 3) ? (4 - (len & 3)) : 4;
1782 size = FOURBYTES + len;
1783 ad->AttrLen = cpu_to_be16(size);
1784 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1785 return size;
1786}
1787
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001788static int
James Smart4258e982015-12-16 18:11:58 -05001789lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1790 struct lpfc_fdmi_attr_def *ad)
1791{
1792 struct lpfc_hba *phba = vport->phba;
1793 struct lpfc_fdmi_attr_entry *ae;
1794 uint32_t len, size;
1795
1796 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1797 memset(ae, 0, 256);
1798
1799 strncpy(ae->un.AttrString, phba->ModelName,
1800 sizeof(ae->un.AttrString));
1801 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1802 len += (len & 3) ? (4 - (len & 3)) : 4;
1803 size = FOURBYTES + len;
1804 ad->AttrLen = cpu_to_be16(size);
1805 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1806 return size;
1807}
1808
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001809static int
James Smart4258e982015-12-16 18:11:58 -05001810lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1811 struct lpfc_fdmi_attr_def *ad)
1812{
1813 struct lpfc_hba *phba = vport->phba;
1814 struct lpfc_fdmi_attr_entry *ae;
1815 uint32_t len, size;
1816
1817 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1818 memset(ae, 0, 256);
1819
1820 strncpy(ae->un.AttrString, phba->ModelDesc,
1821 sizeof(ae->un.AttrString));
1822 len = strnlen(ae->un.AttrString,
1823 sizeof(ae->un.AttrString));
1824 len += (len & 3) ? (4 - (len & 3)) : 4;
1825 size = FOURBYTES + len;
1826 ad->AttrLen = cpu_to_be16(size);
1827 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1828 return size;
1829}
1830
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001831static int
James Smart4258e982015-12-16 18:11:58 -05001832lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1833 struct lpfc_fdmi_attr_def *ad)
1834{
1835 struct lpfc_hba *phba = vport->phba;
1836 lpfc_vpd_t *vp = &phba->vpd;
1837 struct lpfc_fdmi_attr_entry *ae;
1838 uint32_t i, j, incr, size;
1839
1840 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1841 memset(ae, 0, 256);
1842
1843 /* Convert JEDEC ID to ascii for hardware version */
1844 incr = vp->rev.biuRev;
1845 for (i = 0; i < 8; i++) {
1846 j = (incr & 0xf);
1847 if (j <= 9)
1848 ae->un.AttrString[7 - i] =
1849 (char)((uint8_t) 0x30 +
1850 (uint8_t) j);
1851 else
1852 ae->un.AttrString[7 - i] =
1853 (char)((uint8_t) 0x61 +
1854 (uint8_t) (j - 10));
1855 incr = (incr >> 4);
1856 }
1857 size = FOURBYTES + 8;
1858 ad->AttrLen = cpu_to_be16(size);
1859 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1860 return size;
1861}
1862
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001863static int
James Smart4258e982015-12-16 18:11:58 -05001864lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1865 struct lpfc_fdmi_attr_def *ad)
1866{
1867 struct lpfc_fdmi_attr_entry *ae;
1868 uint32_t len, size;
1869
1870 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1871 memset(ae, 0, 256);
1872
1873 strncpy(ae->un.AttrString, lpfc_release_version,
1874 sizeof(ae->un.AttrString));
1875 len = strnlen(ae->un.AttrString,
1876 sizeof(ae->un.AttrString));
1877 len += (len & 3) ? (4 - (len & 3)) : 4;
1878 size = FOURBYTES + len;
1879 ad->AttrLen = cpu_to_be16(size);
1880 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1881 return size;
1882}
1883
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001884static int
James Smart4258e982015-12-16 18:11:58 -05001885lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1886 struct lpfc_fdmi_attr_def *ad)
1887{
1888 struct lpfc_hba *phba = vport->phba;
1889 struct lpfc_fdmi_attr_entry *ae;
1890 uint32_t len, size;
1891
1892 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1893 memset(ae, 0, 256);
1894
1895 if (phba->sli_rev == LPFC_SLI_REV4)
1896 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1897 else
1898 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1899 sizeof(ae->un.AttrString));
1900 len = strnlen(ae->un.AttrString,
1901 sizeof(ae->un.AttrString));
1902 len += (len & 3) ? (4 - (len & 3)) : 4;
1903 size = FOURBYTES + len;
1904 ad->AttrLen = cpu_to_be16(size);
1905 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1906 return size;
1907}
1908
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001909static int
James Smart4258e982015-12-16 18:11:58 -05001910lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1911 struct lpfc_fdmi_attr_def *ad)
1912{
1913 struct lpfc_hba *phba = vport->phba;
1914 struct lpfc_fdmi_attr_entry *ae;
1915 uint32_t len, size;
1916
1917 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1918 memset(ae, 0, 256);
1919
1920 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1921 len = strnlen(ae->un.AttrString,
1922 sizeof(ae->un.AttrString));
1923 len += (len & 3) ? (4 - (len & 3)) : 4;
1924 size = FOURBYTES + len;
1925 ad->AttrLen = cpu_to_be16(size);
1926 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1927 return size;
1928}
1929
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001930static int
James Smart4258e982015-12-16 18:11:58 -05001931lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1932 struct lpfc_fdmi_attr_def *ad)
1933{
1934 struct lpfc_fdmi_attr_entry *ae;
1935 uint32_t len, size;
1936
1937 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1938 memset(ae, 0, 256);
1939
1940 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1941 init_utsname()->sysname,
1942 init_utsname()->release,
1943 init_utsname()->version);
1944
1945 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1946 len += (len & 3) ? (4 - (len & 3)) : 4;
1947 size = FOURBYTES + len;
1948 ad->AttrLen = cpu_to_be16(size);
1949 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1950 return size;
1951}
1952
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001953static int
James Smart4258e982015-12-16 18:11:58 -05001954lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1955 struct lpfc_fdmi_attr_def *ad)
1956{
1957 struct lpfc_fdmi_attr_entry *ae;
1958 uint32_t size;
1959
1960 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1961
1962 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1963 size = FOURBYTES + sizeof(uint32_t);
1964 ad->AttrLen = cpu_to_be16(size);
1965 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1966 return size;
1967}
1968
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001969static int
James Smart4258e982015-12-16 18:11:58 -05001970lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1971 struct lpfc_fdmi_attr_def *ad)
1972{
1973 struct lpfc_fdmi_attr_entry *ae;
1974 uint32_t len, size;
1975
1976 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1977 memset(ae, 0, 256);
1978
1979 len = lpfc_vport_symbolic_node_name(vport,
1980 ae->un.AttrString, 256);
1981 len += (len & 3) ? (4 - (len & 3)) : 4;
1982 size = FOURBYTES + len;
1983 ad->AttrLen = cpu_to_be16(size);
1984 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1985 return size;
1986}
1987
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001988static int
James Smart4258e982015-12-16 18:11:58 -05001989lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
1990 struct lpfc_fdmi_attr_def *ad)
1991{
1992 struct lpfc_fdmi_attr_entry *ae;
1993 uint32_t size;
1994
1995 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1996
1997 /* Nothing is defined for this currently */
1998 ae->un.AttrInt = cpu_to_be32(0);
1999 size = FOURBYTES + sizeof(uint32_t);
2000 ad->AttrLen = cpu_to_be16(size);
2001 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2002 return size;
2003}
2004
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002005static int
James Smart4258e982015-12-16 18:11:58 -05002006lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2007 struct lpfc_fdmi_attr_def *ad)
2008{
2009 struct lpfc_fdmi_attr_entry *ae;
2010 uint32_t size;
2011
2012 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2013
2014 /* Each driver instance corresponds to a single port */
2015 ae->un.AttrInt = cpu_to_be32(1);
2016 size = FOURBYTES + sizeof(uint32_t);
2017 ad->AttrLen = cpu_to_be16(size);
2018 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2019 return size;
2020}
2021
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002022static int
James Smart4258e982015-12-16 18:11:58 -05002023lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2024 struct lpfc_fdmi_attr_def *ad)
2025{
2026 struct lpfc_fdmi_attr_entry *ae;
2027 uint32_t size;
2028
2029 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2030 memset(ae, 0, sizeof(struct lpfc_name));
2031
2032 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2033 sizeof(struct lpfc_name));
2034 size = FOURBYTES + sizeof(struct lpfc_name);
2035 ad->AttrLen = cpu_to_be16(size);
2036 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2037 return size;
2038}
2039
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002040static int
James Smart4258e982015-12-16 18:11:58 -05002041lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2042 struct lpfc_fdmi_attr_def *ad)
2043{
2044 struct lpfc_hba *phba = vport->phba;
2045 struct lpfc_fdmi_attr_entry *ae;
2046 uint32_t len, size;
2047
2048 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2049 memset(ae, 0, 256);
2050
2051 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2052 len = strnlen(ae->un.AttrString,
2053 sizeof(ae->un.AttrString));
2054 len += (len & 3) ? (4 - (len & 3)) : 4;
2055 size = FOURBYTES + len;
2056 ad->AttrLen = cpu_to_be16(size);
2057 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2058 return size;
2059}
2060
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002061static int
James Smart4258e982015-12-16 18:11:58 -05002062lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2063 struct lpfc_fdmi_attr_def *ad)
2064{
2065 struct lpfc_fdmi_attr_entry *ae;
2066 uint32_t size;
2067
2068 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2069
2070 /* Driver doesn't have access to this information */
2071 ae->un.AttrInt = cpu_to_be32(0);
2072 size = FOURBYTES + sizeof(uint32_t);
2073 ad->AttrLen = cpu_to_be16(size);
2074 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2075 return size;
2076}
2077
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002078static int
James Smart4258e982015-12-16 18:11:58 -05002079lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2080 struct lpfc_fdmi_attr_def *ad)
2081{
2082 struct lpfc_fdmi_attr_entry *ae;
2083 uint32_t len, size;
2084
2085 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2086 memset(ae, 0, 256);
2087
2088 strncpy(ae->un.AttrString, "EMULEX",
2089 sizeof(ae->un.AttrString));
2090 len = strnlen(ae->un.AttrString,
2091 sizeof(ae->un.AttrString));
2092 len += (len & 3) ? (4 - (len & 3)) : 4;
2093 size = FOURBYTES + len;
2094 ad->AttrLen = cpu_to_be16(size);
2095 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2096 return size;
2097}
2098
2099/* Routines for all individual PORT attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002100static int
James Smart4258e982015-12-16 18:11:58 -05002101lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2102 struct lpfc_fdmi_attr_def *ad)
2103{
2104 struct lpfc_fdmi_attr_entry *ae;
2105 uint32_t size;
2106
2107 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2108 memset(ae, 0, 32);
2109
2110 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2111 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
James Smart82820f02017-05-15 15:20:47 -07002112 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
James Smart4258e982015-12-16 18:11:58 -05002113 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2114 size = FOURBYTES + 32;
2115 ad->AttrLen = cpu_to_be16(size);
2116 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2117 return size;
2118}
2119
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002120static int
James Smart4258e982015-12-16 18:11:58 -05002121lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2122 struct lpfc_fdmi_attr_def *ad)
2123{
2124 struct lpfc_hba *phba = vport->phba;
2125 struct lpfc_fdmi_attr_entry *ae;
2126 uint32_t size;
2127
2128 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2129
2130 ae->un.AttrInt = 0;
James Smarta085e872015-12-16 18:12:02 -05002131 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2132 if (phba->lmt & LMT_32Gb)
2133 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2134 if (phba->lmt & LMT_16Gb)
2135 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2136 if (phba->lmt & LMT_10Gb)
2137 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2138 if (phba->lmt & LMT_8Gb)
2139 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2140 if (phba->lmt & LMT_4Gb)
2141 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2142 if (phba->lmt & LMT_2Gb)
2143 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2144 if (phba->lmt & LMT_1Gb)
2145 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2146 } else {
2147 /* FCoE links support only one speed */
2148 switch (phba->fc_linkspeed) {
2149 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2150 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2151 break;
2152 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2153 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2154 break;
2155 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2156 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2157 break;
2158 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2159 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2160 break;
2161 }
2162 }
James Smart4258e982015-12-16 18:11:58 -05002163 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2164 size = FOURBYTES + sizeof(uint32_t);
2165 ad->AttrLen = cpu_to_be16(size);
2166 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2167 return size;
2168}
2169
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002170static int
James Smart4258e982015-12-16 18:11:58 -05002171lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2172 struct lpfc_fdmi_attr_def *ad)
2173{
2174 struct lpfc_hba *phba = vport->phba;
2175 struct lpfc_fdmi_attr_entry *ae;
2176 uint32_t size;
2177
2178 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2179
James Smarta085e872015-12-16 18:12:02 -05002180 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2181 switch (phba->fc_linkspeed) {
2182 case LPFC_LINK_SPEED_1GHZ:
2183 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2184 break;
2185 case LPFC_LINK_SPEED_2GHZ:
2186 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2187 break;
2188 case LPFC_LINK_SPEED_4GHZ:
2189 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2190 break;
2191 case LPFC_LINK_SPEED_8GHZ:
2192 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2193 break;
2194 case LPFC_LINK_SPEED_10GHZ:
2195 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2196 break;
2197 case LPFC_LINK_SPEED_16GHZ:
2198 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2199 break;
2200 case LPFC_LINK_SPEED_32GHZ:
2201 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2202 break;
2203 default:
2204 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2205 break;
2206 }
2207 } else {
2208 switch (phba->fc_linkspeed) {
2209 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2210 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2211 break;
2212 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2213 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2214 break;
2215 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2216 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2217 break;
2218 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2219 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2220 break;
2221 default:
2222 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2223 break;
2224 }
James Smart4258e982015-12-16 18:11:58 -05002225 }
James Smarta085e872015-12-16 18:12:02 -05002226
James Smart4258e982015-12-16 18:11:58 -05002227 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2228 size = FOURBYTES + sizeof(uint32_t);
2229 ad->AttrLen = cpu_to_be16(size);
2230 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2231 return size;
2232}
2233
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002234static int
James Smart4258e982015-12-16 18:11:58 -05002235lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2236 struct lpfc_fdmi_attr_def *ad)
2237{
2238 struct serv_parm *hsp;
2239 struct lpfc_fdmi_attr_entry *ae;
2240 uint32_t size;
2241
2242 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2243
2244 hsp = (struct serv_parm *)&vport->fc_sparam;
2245 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2246 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2247 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2248 size = FOURBYTES + sizeof(uint32_t);
2249 ad->AttrLen = cpu_to_be16(size);
2250 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2251 return size;
2252}
2253
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002254static int
James Smart4258e982015-12-16 18:11:58 -05002255lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2256 struct lpfc_fdmi_attr_def *ad)
2257{
2258 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2259 struct lpfc_fdmi_attr_entry *ae;
2260 uint32_t len, size;
2261
2262 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2263 memset(ae, 0, 256);
2264
2265 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2266 "/sys/class/scsi_host/host%d", shost->host_no);
2267 len = strnlen((char *)ae->un.AttrString,
2268 sizeof(ae->un.AttrString));
2269 len += (len & 3) ? (4 - (len & 3)) : 4;
2270 size = FOURBYTES + len;
2271 ad->AttrLen = cpu_to_be16(size);
2272 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2273 return size;
2274}
2275
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002276static int
James Smart4258e982015-12-16 18:11:58 -05002277lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2278 struct lpfc_fdmi_attr_def *ad)
2279{
2280 struct lpfc_fdmi_attr_entry *ae;
2281 uint32_t len, size;
2282
2283 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2284 memset(ae, 0, 256);
2285
2286 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2287 init_utsname()->nodename);
2288
2289 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2290 len += (len & 3) ? (4 - (len & 3)) : 4;
2291 size = FOURBYTES + len;
2292 ad->AttrLen = cpu_to_be16(size);
2293 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2294 return size;
2295}
2296
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002297static int
James Smart4258e982015-12-16 18:11:58 -05002298lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2299 struct lpfc_fdmi_attr_def *ad)
2300{
2301 struct lpfc_fdmi_attr_entry *ae;
2302 uint32_t size;
2303
2304 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2305 memset(ae, 0, sizeof(struct lpfc_name));
2306
2307 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2308 sizeof(struct lpfc_name));
2309 size = FOURBYTES + sizeof(struct lpfc_name);
2310 ad->AttrLen = cpu_to_be16(size);
2311 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2312 return size;
2313}
2314
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002315static int
James Smart4258e982015-12-16 18:11:58 -05002316lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2317 struct lpfc_fdmi_attr_def *ad)
2318{
2319 struct lpfc_fdmi_attr_entry *ae;
2320 uint32_t size;
2321
2322 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2323 memset(ae, 0, sizeof(struct lpfc_name));
2324
2325 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2326 sizeof(struct lpfc_name));
2327 size = FOURBYTES + sizeof(struct lpfc_name);
2328 ad->AttrLen = cpu_to_be16(size);
2329 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2330 return size;
2331}
2332
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002333static int
James Smart4258e982015-12-16 18:11:58 -05002334lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2335 struct lpfc_fdmi_attr_def *ad)
2336{
2337 struct lpfc_fdmi_attr_entry *ae;
2338 uint32_t len, size;
2339
2340 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2341 memset(ae, 0, 256);
2342
2343 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2344 len += (len & 3) ? (4 - (len & 3)) : 4;
2345 size = FOURBYTES + len;
2346 ad->AttrLen = cpu_to_be16(size);
2347 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2348 return size;
2349}
2350
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002351static int
James Smart4258e982015-12-16 18:11:58 -05002352lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2353 struct lpfc_fdmi_attr_def *ad)
2354{
2355 struct lpfc_hba *phba = vport->phba;
2356 struct lpfc_fdmi_attr_entry *ae;
2357 uint32_t size;
2358
2359 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2360 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2361 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2362 else
2363 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2364 size = FOURBYTES + sizeof(uint32_t);
2365 ad->AttrLen = cpu_to_be16(size);
2366 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2367 return size;
2368}
2369
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002370static int
James Smart4258e982015-12-16 18:11:58 -05002371lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2372 struct lpfc_fdmi_attr_def *ad)
2373{
2374 struct lpfc_fdmi_attr_entry *ae;
2375 uint32_t size;
2376
2377 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2378 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2379 size = FOURBYTES + sizeof(uint32_t);
2380 ad->AttrLen = cpu_to_be16(size);
2381 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2382 return size;
2383}
2384
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002385static int
James Smart4258e982015-12-16 18:11:58 -05002386lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2387 struct lpfc_fdmi_attr_def *ad)
2388{
2389 struct lpfc_fdmi_attr_entry *ae;
2390 uint32_t size;
2391
2392 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2393 memset(ae, 0, sizeof(struct lpfc_name));
2394
2395 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2396 sizeof(struct lpfc_name));
2397 size = FOURBYTES + sizeof(struct lpfc_name);
2398 ad->AttrLen = cpu_to_be16(size);
2399 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2400 return size;
2401}
2402
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002403static int
James Smart4258e982015-12-16 18:11:58 -05002404lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2405 struct lpfc_fdmi_attr_def *ad)
2406{
2407 struct lpfc_fdmi_attr_entry *ae;
2408 uint32_t size;
2409
2410 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2411 memset(ae, 0, 32);
2412
2413 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2414 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2415 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2416 size = FOURBYTES + 32;
2417 ad->AttrLen = cpu_to_be16(size);
2418 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2419 return size;
2420}
2421
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002422static int
James Smart4258e982015-12-16 18:11:58 -05002423lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2424 struct lpfc_fdmi_attr_def *ad)
2425{
2426 struct lpfc_fdmi_attr_entry *ae;
2427 uint32_t size;
2428
2429 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2430 /* Link Up - operational */
2431 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2432 size = FOURBYTES + sizeof(uint32_t);
2433 ad->AttrLen = cpu_to_be16(size);
2434 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2435 return size;
2436}
2437
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002438static int
James Smart4258e982015-12-16 18:11:58 -05002439lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2440 struct lpfc_fdmi_attr_def *ad)
2441{
2442 struct lpfc_fdmi_attr_entry *ae;
2443 uint32_t size;
2444
2445 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2446 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2447 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2448 size = FOURBYTES + sizeof(uint32_t);
2449 ad->AttrLen = cpu_to_be16(size);
2450 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2451 return size;
2452}
2453
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002454static int
James Smart4258e982015-12-16 18:11:58 -05002455lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2456 struct lpfc_fdmi_attr_def *ad)
2457{
2458 struct lpfc_fdmi_attr_entry *ae;
2459 uint32_t size;
2460
2461 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2462 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2463 size = FOURBYTES + sizeof(uint32_t);
2464 ad->AttrLen = cpu_to_be16(size);
2465 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2466 return size;
2467}
2468
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002469static int
James Smart4258e982015-12-16 18:11:58 -05002470lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2471 struct lpfc_fdmi_attr_def *ad)
2472{
2473 struct lpfc_fdmi_attr_entry *ae;
2474 uint32_t len, size;
2475
2476 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2477 memset(ae, 0, 256);
2478
2479 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2480 sizeof(ae->un.AttrString));
2481 len = strnlen(ae->un.AttrString,
2482 sizeof(ae->un.AttrString));
2483 len += (len & 3) ? (4 - (len & 3)) : 4;
2484 size = FOURBYTES + len;
2485 ad->AttrLen = cpu_to_be16(size);
2486 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2487 return size;
2488}
2489
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002490static int
James Smart4258e982015-12-16 18:11:58 -05002491lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2492 struct lpfc_fdmi_attr_def *ad)
2493{
2494 struct lpfc_fdmi_attr_entry *ae;
2495 uint32_t size;
2496
2497 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2498 memset(ae, 0, 256);
2499
2500 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2501 sizeof(struct lpfc_name));
2502 memcpy((((uint8_t *)&ae->un.AttrString) +
2503 sizeof(struct lpfc_name)),
2504 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2505 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2506 ad->AttrLen = cpu_to_be16(size);
2507 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2508 return size;
2509}
2510
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002511static int
James Smart4258e982015-12-16 18:11:58 -05002512lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2513 struct lpfc_fdmi_attr_def *ad)
2514{
2515 struct lpfc_fdmi_attr_entry *ae;
2516 uint32_t len, size;
2517
2518 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2519 memset(ae, 0, 256);
2520
James Smart56204982016-03-31 14:12:32 -07002521 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
James Smart4258e982015-12-16 18:11:58 -05002522 sizeof(ae->un.AttrString));
2523 len = strnlen(ae->un.AttrString,
2524 sizeof(ae->un.AttrString));
2525 len += (len & 3) ? (4 - (len & 3)) : 4;
2526 size = FOURBYTES + len;
2527 ad->AttrLen = cpu_to_be16(size);
2528 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2529 return size;
2530}
2531
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002532static int
James Smart4258e982015-12-16 18:11:58 -05002533lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2534 struct lpfc_fdmi_attr_def *ad)
2535{
2536 struct lpfc_hba *phba = vport->phba;
2537 struct lpfc_fdmi_attr_entry *ae;
2538 uint32_t len, size;
2539
2540 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2541 memset(ae, 0, 256);
2542
2543 strncpy(ae->un.AttrString, phba->ModelName,
2544 sizeof(ae->un.AttrString));
2545 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2546 len += (len & 3) ? (4 - (len & 3)) : 4;
2547 size = FOURBYTES + len;
2548 ad->AttrLen = cpu_to_be16(size);
2549 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2550 return size;
2551}
2552
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002553static int
James Smart4258e982015-12-16 18:11:58 -05002554lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2555 struct lpfc_fdmi_attr_def *ad)
2556{
2557 struct lpfc_fdmi_attr_entry *ae;
2558 uint32_t size;
2559
2560 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2561
2562 /* SRIOV (type 3) is not supported */
2563 if (vport->vpi)
2564 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2565 else
2566 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2567 size = FOURBYTES + sizeof(uint32_t);
2568 ad->AttrLen = cpu_to_be16(size);
2569 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2570 return size;
2571}
2572
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002573static int
James Smart4258e982015-12-16 18:11:58 -05002574lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2575 struct lpfc_fdmi_attr_def *ad)
2576{
2577 struct lpfc_fdmi_attr_entry *ae;
2578 uint32_t size;
2579
2580 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2581 ae->un.AttrInt = cpu_to_be32(0);
2582 size = FOURBYTES + sizeof(uint32_t);
2583 ad->AttrLen = cpu_to_be16(size);
2584 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2585 return size;
2586}
2587
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002588static int
James Smart4258e982015-12-16 18:11:58 -05002589lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2590 struct lpfc_fdmi_attr_def *ad)
2591{
2592 struct lpfc_fdmi_attr_entry *ae;
2593 uint32_t size;
2594
2595 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
James Smart56204982016-03-31 14:12:32 -07002596 ae->un.AttrInt = cpu_to_be32(1);
James Smart4258e982015-12-16 18:11:58 -05002597 size = FOURBYTES + sizeof(uint32_t);
2598 ad->AttrLen = cpu_to_be16(size);
2599 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2600 return size;
2601}
2602
2603/* RHBA attribute jump table */
2604int (*lpfc_fdmi_hba_action[])
2605 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2606 /* Action routine Mask bit Attribute type */
2607 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2608 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2609 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2610 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2611 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2612 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2613 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2614 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2615 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2616 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2617 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2618 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2619 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2620 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2621 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2622 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2623 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2624 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2625};
2626
2627/* RPA / RPRT attribute jump table */
2628int (*lpfc_fdmi_port_action[])
2629 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2630 /* Action routine Mask bit Attribute type */
2631 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2632 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2633 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2634 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2635 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2636 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2637 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2638 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2639 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2640 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2641 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2642 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2643 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2644 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2645 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2646 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2647 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2648 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2649 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2650 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2651 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2652 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2653 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2654};
2655
2656/**
2657 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2658 * @vport: pointer to a host virtual N_Port data structure.
2659 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2660 * cmdcode: FDMI command to send
2661 * mask: Mask of HBA or PORT Attributes to send
2662 *
2663 * Builds and sends a FDMI command using the CT subsystem.
2664 */
2665int
2666lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2667 int cmdcode, uint32_t new_mask)
dea31012005-04-17 16:05:31 -05002668{
James Smart2e0fef82007-06-17 19:56:36 -05002669 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002670 struct lpfc_dmabuf *mp, *bmp;
2671 struct lpfc_sli_ct_request *CtReq;
2672 struct ulp_bde64 *bpl;
James Smart4258e982015-12-16 18:11:58 -05002673 uint32_t bit_pos;
dea31012005-04-17 16:05:31 -05002674 uint32_t size;
James Smart76b2c342015-04-07 15:07:19 -04002675 uint32_t rsp_size;
James Smart4258e982015-12-16 18:11:58 -05002676 uint32_t mask;
James Smart76b2c342015-04-07 15:07:19 -04002677 struct lpfc_fdmi_reg_hba *rh;
2678 struct lpfc_fdmi_port_entry *pe;
2679 struct lpfc_fdmi_reg_portattr *pab = NULL;
2680 struct lpfc_fdmi_attr_block *ab = NULL;
James Smart4258e982015-12-16 18:11:58 -05002681 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2682 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2683 struct lpfc_iocbq *);
dea31012005-04-17 16:05:31 -05002684
James Smart4258e982015-12-16 18:11:58 -05002685 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2686 return 0;
2687
2688 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
dea31012005-04-17 16:05:31 -05002689
2690 /* fill in BDEs for command */
2691 /* Allocate buffer for command payload */
James Smart76b2c342015-04-07 15:07:19 -04002692 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002693 if (!mp)
2694 goto fdmi_cmd_exit;
2695
2696 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2697 if (!mp->virt)
2698 goto fdmi_cmd_free_mp;
2699
2700 /* Allocate buffer for Buffer ptr list */
James Smart76b2c342015-04-07 15:07:19 -04002701 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002702 if (!bmp)
2703 goto fdmi_cmd_free_mpvirt;
2704
2705 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2706 if (!bmp->virt)
2707 goto fdmi_cmd_free_bmp;
2708
2709 INIT_LIST_HEAD(&mp->list);
2710 INIT_LIST_HEAD(&bmp->list);
2711
2712 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04002713 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2714 "0218 FDMI Request Data: x%x x%x x%x\n",
2715 vport->fc_flag, vport->port_state, cmdcode);
James Smart76b2c342015-04-07 15:07:19 -04002716 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
dea31012005-04-17 16:05:31 -05002717
James Smart76b2c342015-04-07 15:07:19 -04002718 /* First populate the CT_IU preamble */
dea31012005-04-17 16:05:31 -05002719 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2720 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2721 CtReq->RevisionId.bits.InId = 0;
2722
2723 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2724 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
James Smart76b2c342015-04-07 15:07:19 -04002725
2726 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2727 rsp_size = LPFC_BPL_SIZE;
dea31012005-04-17 16:05:31 -05002728 size = 0;
2729
James Smart76b2c342015-04-07 15:07:19 -04002730 /* Next fill in the specific FDMI cmd information */
dea31012005-04-17 16:05:31 -05002731 switch (cmdcode) {
James Smart76b2c342015-04-07 15:07:19 -04002732 case SLI_MGMT_RHAT:
dea31012005-04-17 16:05:31 -05002733 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05002734 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2735 /* HBA Identifier */
2736 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2737 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002738
James Smart4258e982015-12-16 18:11:58 -05002739 if (cmdcode == SLI_MGMT_RHBA) {
2740 /* Registered Port List */
2741 /* One entry (port) per adapter */
2742 rh->rpl.EntryCnt = cpu_to_be32(1);
2743 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002744 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002745
James Smart4258e982015-12-16 18:11:58 -05002746 /* point to the HBA attribute block */
2747 size = 2 * sizeof(struct lpfc_name) +
2748 FOURBYTES;
2749 } else {
2750 size = sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002751 }
James Smart4258e982015-12-16 18:11:58 -05002752 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2753 ab->EntryCnt = 0;
2754 size += FOURBYTES;
2755 bit_pos = 0;
2756 if (new_mask)
2757 mask = new_mask;
2758 else
2759 mask = vport->fdmi_hba_mask;
2760
2761 /* Mask will dictate what attributes to build in the request */
2762 while (mask) {
2763 if (mask & 0x1) {
2764 func = lpfc_fdmi_hba_action[bit_pos];
2765 size += func(vport,
2766 (struct lpfc_fdmi_attr_def *)
2767 ((uint8_t *)rh + size));
2768 ab->EntryCnt++;
2769 if ((size + 256) >
2770 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2771 goto hba_out;
2772 }
2773 mask = mask >> 1;
2774 bit_pos++;
2775 }
2776hba_out:
2777 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2778 /* Total size */
2779 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002780 break;
2781
James Smart76b2c342015-04-07 15:07:19 -04002782 case SLI_MGMT_RPRT:
dea31012005-04-17 16:05:31 -05002783 case SLI_MGMT_RPA:
James Smart4258e982015-12-16 18:11:58 -05002784 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2785 if (cmdcode == SLI_MGMT_RPRT) {
2786 rh = (struct lpfc_fdmi_reg_hba *)pab;
2787 /* HBA Identifier */
2788 memcpy(&rh->hi.PortName,
2789 &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002790 sizeof(struct lpfc_name));
James Smart4258e982015-12-16 18:11:58 -05002791 pab = (struct lpfc_fdmi_reg_portattr *)
2792 ((uint8_t *)pab + sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002793 }
James Smart4258e982015-12-16 18:11:58 -05002794
2795 memcpy((uint8_t *)&pab->PortName,
2796 (uint8_t *)&vport->fc_sparam.portName,
2797 sizeof(struct lpfc_name));
2798 size += sizeof(struct lpfc_name) + FOURBYTES;
2799 pab->ab.EntryCnt = 0;
2800 bit_pos = 0;
2801 if (new_mask)
2802 mask = new_mask;
2803 else
2804 mask = vport->fdmi_port_mask;
2805
2806 /* Mask will dictate what attributes to build in the request */
2807 while (mask) {
2808 if (mask & 0x1) {
2809 func = lpfc_fdmi_port_action[bit_pos];
2810 size += func(vport,
2811 (struct lpfc_fdmi_attr_def *)
2812 ((uint8_t *)pab + size));
2813 pab->ab.EntryCnt++;
2814 if ((size + 256) >
2815 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2816 goto port_out;
2817 }
2818 mask = mask >> 1;
2819 bit_pos++;
2820 }
2821port_out:
2822 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2823 /* Total size */
2824 if (cmdcode == SLI_MGMT_RPRT)
2825 size += sizeof(struct lpfc_name);
2826 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002827 break;
2828
James Smart76b2c342015-04-07 15:07:19 -04002829 case SLI_MGMT_GHAT:
2830 case SLI_MGMT_GRPL:
2831 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002832 case SLI_MGMT_DHBA:
James Smart76b2c342015-04-07 15:07:19 -04002833 case SLI_MGMT_DHAT:
2834 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2835 memcpy((uint8_t *)&pe->PortName,
2836 (uint8_t *)&vport->fc_sparam.portName,
2837 sizeof(struct lpfc_name));
2838 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002839 break;
2840
James Smart76b2c342015-04-07 15:07:19 -04002841 case SLI_MGMT_GPAT:
2842 case SLI_MGMT_GPAS:
2843 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002844 case SLI_MGMT_DPRT:
James Smart76b2c342015-04-07 15:07:19 -04002845 case SLI_MGMT_DPA:
2846 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2847 memcpy((uint8_t *)&pe->PortName,
2848 (uint8_t *)&vport->fc_sparam.portName,
2849 sizeof(struct lpfc_name));
2850 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002851 break;
James Smart76b2c342015-04-07 15:07:19 -04002852 case SLI_MGMT_GRHL:
2853 size = GID_REQUEST_SZ - 4;
2854 break;
2855 default:
2856 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2857 "0298 FDMI cmdcode x%x not supported\n",
2858 cmdcode);
2859 goto fdmi_cmd_free_bmpvirt;
dea31012005-04-17 16:05:31 -05002860 }
James Smart76b2c342015-04-07 15:07:19 -04002861 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
dea31012005-04-17 16:05:31 -05002862
James Smart76b2c342015-04-07 15:07:19 -04002863 bpl = (struct ulp_bde64 *)bmp->virt;
2864 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2865 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
dea31012005-04-17 16:05:31 -05002866 bpl->tus.f.bdeFlags = 0;
2867 bpl->tus.f.bdeSize = size;
dea31012005-04-17 16:05:31 -05002868
James Smart76b2c342015-04-07 15:07:19 -04002869 /*
2870 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
James Smarte47c9092008-02-08 18:49:26 -05002871 * to hold ndlp reference for the corresponding callback function.
2872 */
James Smart76b2c342015-04-07 15:07:19 -04002873 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
dea31012005-04-17 16:05:31 -05002874 return 0;
2875
James Smart76b2c342015-04-07 15:07:19 -04002876 /*
2877 * Decrement ndlp reference count to release ndlp reference held
James Smarte47c9092008-02-08 18:49:26 -05002878 * for the failed command's callback function.
2879 */
James Smart51ef4c22007-08-02 11:10:31 -04002880 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002881
James Smart76b2c342015-04-07 15:07:19 -04002882fdmi_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05002883 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2884fdmi_cmd_free_bmp:
2885 kfree(bmp);
2886fdmi_cmd_free_mpvirt:
2887 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2888fdmi_cmd_free_mp:
2889 kfree(mp);
2890fdmi_cmd_exit:
2891 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04002892 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2893 "0244 Issue FDMI request failed Data: x%x\n",
2894 cmdcode);
dea31012005-04-17 16:05:31 -05002895 return 1;
2896}
2897
James Smart92494142011-02-16 12:39:44 -05002898/**
2899 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2900 * @ptr - Context object of the timer.
2901 *
2902 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2903 * the worker thread.
2904 **/
2905void
Kees Cookf22eb4d2017-09-06 20:24:26 -07002906lpfc_delayed_disc_tmo(struct timer_list *t)
James Smart92494142011-02-16 12:39:44 -05002907{
Kees Cookf22eb4d2017-09-06 20:24:26 -07002908 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
James Smart92494142011-02-16 12:39:44 -05002909 struct lpfc_hba *phba = vport->phba;
2910 uint32_t tmo_posted;
2911 unsigned long iflag;
2912
2913 spin_lock_irqsave(&vport->work_port_lock, iflag);
2914 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2915 if (!tmo_posted)
2916 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2917 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2918
2919 if (!tmo_posted)
2920 lpfc_worker_wake_up(phba);
2921 return;
2922}
2923
2924/**
2925 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2926 * handle delayed discovery.
2927 * @vport: pointer to a host virtual N_Port data structure.
2928 *
2929 * This function start nport discovery of the vport.
2930 **/
2931void
2932lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2933{
2934 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2935
2936 spin_lock_irq(shost->host_lock);
2937 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2938 spin_unlock_irq(shost->host_lock);
2939 return;
2940 }
2941 vport->fc_flag &= ~FC_DISC_DELAYED;
2942 spin_unlock_irq(shost->host_lock);
2943
2944 lpfc_do_scr_ns_plogi(vport->phba, vport);
2945}
2946
dea31012005-04-17 16:05:31 -05002947void
James Smart2e0fef82007-06-17 19:56:36 -05002948lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05002949{
2950 struct lpfc_sli *psli = &phba->sli;
2951 lpfc_vpd_t *vp = &phba->vpd;
2952 uint32_t b1, b2, b3, b4, i, rev;
2953 char c;
2954 uint32_t *ptr, str[4];
2955 uint8_t *fwname;
2956
James Smartf1126682009-06-10 17:22:44 -04002957 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart6b5151f2012-01-18 16:24:06 -05002958 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
James Smartf1126682009-06-10 17:22:44 -04002959 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04002960 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002961 rev = vp->rev.sli2FwRev;
2962 else
2963 rev = vp->rev.sli1FwRev;
2964
2965 b1 = (rev & 0x0000f000) >> 12;
2966 b2 = (rev & 0x00000f00) >> 8;
2967 b3 = (rev & 0x000000c0) >> 6;
2968 b4 = (rev & 0x00000030) >> 4;
2969
2970 switch (b4) {
2971 case 0:
2972 c = 'N';
2973 break;
2974 case 1:
2975 c = 'A';
2976 break;
2977 case 2:
2978 c = 'B';
2979 break;
James Smart73d91e52011-10-10 21:32:10 -04002980 case 3:
2981 c = 'X';
2982 break;
dea31012005-04-17 16:05:31 -05002983 default:
2984 c = 0;
2985 break;
2986 }
2987 b4 = (rev & 0x0000000f);
2988
James Smartf4b4c682009-05-22 14:53:12 -04002989 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002990 fwname = vp->rev.sli2FwName;
2991 else
2992 fwname = vp->rev.sli1FwName;
2993
2994 for (i = 0; i < 16; i++)
2995 if (fwname[i] == 0x20)
2996 fwname[i] = 0;
2997
2998 ptr = (uint32_t*)fwname;
2999
3000 for (i = 0; i < 3; i++)
3001 str[i] = be32_to_cpu(*ptr++);
3002
3003 if (c == 0) {
3004 if (flag)
3005 sprintf(fwrevision, "%d.%d%d (%s)",
3006 b1, b2, b3, (char *)str);
3007 else
3008 sprintf(fwrevision, "%d.%d%d", b1,
3009 b2, b3);
3010 } else {
3011 if (flag)
3012 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3013 b1, b2, b3, c,
3014 b4, (char *)str);
3015 else
3016 sprintf(fwrevision, "%d.%d%d%c%d",
3017 b1, b2, b3, c, b4);
3018 }
3019 } else {
3020 rev = vp->rev.smFwRev;
3021
3022 b1 = (rev & 0xff000000) >> 24;
3023 b2 = (rev & 0x00f00000) >> 20;
3024 b3 = (rev & 0x000f0000) >> 16;
3025 c = (rev & 0x0000ff00) >> 8;
3026 b4 = (rev & 0x000000ff);
3027
Roel Kluind44a6d22010-01-17 16:15:57 +01003028 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05003029 }
3030 return;
3031}