blob: 03a7e13a049d4478af9267e2b45e04c0b9b323d9 [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 Smart9de416a2017-12-08 17:18:07 -0800474 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
James Smarta0f2d3e2017-02-12 13:52:31 -0800475 /* By default, the driver expects to support FCP FC4 */
476 if (fc4_type == FC_TYPE_FCP)
477 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
478
479 if (fc4_type == FC_TYPE_NVME)
480 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
481
482 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
483 "0238 Process x%06x NameServer Rsp "
484 "Data: x%x x%x x%x x%x\n", Did,
485 ndlp->nlp_flag, ndlp->nlp_fc4_type,
486 vport->fc_flag,
487 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800488 } else {
489 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
490 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
491 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
492
James Smarta0f2d3e2017-02-12 13:52:31 -0800493 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
494 "0239 Skip x%06x NameServer Rsp "
495 "Data: x%x x%x\n", Did,
496 vport->fc_flag,
497 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800498 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800499 } else {
500 if (!(vport->fc_flag & FC_RSCN_MODE) ||
501 lpfc_rscn_payload_check(vport, Did)) {
James Smartbd2cdd52017-02-12 13:52:33 -0800502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
503 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
504 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
505
James Smarta0f2d3e2017-02-12 13:52:31 -0800506 /*
James Smartb57ab7462017-06-01 21:07:08 -0700507 * This NPortID was previously a FCP/NVMe target,
James Smarta0f2d3e2017-02-12 13:52:31 -0800508 * Don't even bother to send GFF_ID.
509 */
510 ndlp = lpfc_findnode_did(vport, Did);
James Smartb57ab7462017-06-01 21:07:08 -0700511 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
512 (ndlp->nlp_type &
513 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
514 if (fc4_type == FC_TYPE_FCP)
515 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
516 if (fc4_type == FC_TYPE_NVME)
517 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
518 lpfc_setup_disc_node(vport, Did);
519 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
520 0, Did) == 0)
521 vport->num_disc_nodes++;
522 else
523 lpfc_setup_disc_node(vport, Did);
James Smartbd2cdd52017-02-12 13:52:33 -0800524 } else {
525 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
526 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
527 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
528
James Smarta0f2d3e2017-02-12 13:52:31 -0800529 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
530 "0245 Skip x%06x NameServer Rsp "
531 "Data: x%x x%x\n", Did,
532 vport->fc_flag,
533 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800534 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800535 }
536}
537
James Smart1c5b12f2017-04-21 16:05:03 -0700538static void
539lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
540{
541 struct lpfc_hba *phba = vport->phba;
542 struct lpfc_nodelist *ndlp = NULL;
543 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
544
545 /*
546 * To conserve rpi's, filter out addresses for other
547 * vports on the same physical HBAs.
548 */
549 if (Did != vport->fc_myDID &&
550 (!lpfc_find_vport_by_did(phba, Did) ||
551 vport->cfg_peer_port_login)) {
552 if (!phba->nvmet_support) {
553 /* FCPI/NVMEI path. Process Did */
554 lpfc_prep_node_fc4type(vport, Did, fc4_type);
555 return;
556 }
557 /* NVMET path. NVMET only cares about NVMEI nodes. */
558 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
559 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
560 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
561 continue;
562 spin_lock_irq(shost->host_lock);
563 if (ndlp->nlp_DID == Did)
564 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
565 else
566 ndlp->nlp_flag |= NLP_NVMET_RECOV;
567 spin_unlock_irq(shost->host_lock);
568 }
569 }
570}
571
dea31012005-04-17 16:05:31 -0500572static int
James Smarta0f2d3e2017-02-12 13:52:31 -0800573lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
574 uint32_t Size)
dea31012005-04-17 16:05:31 -0500575{
576 struct lpfc_sli_ct_request *Response =
577 (struct lpfc_sli_ct_request *) mp->virt;
dea31012005-04-17 16:05:31 -0500578 struct lpfc_dmabuf *mlast, *next_mp;
579 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500580 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500581 int Cnt;
582 struct list_head head;
James Smart1c5b12f2017-04-21 16:05:03 -0700583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
584 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -0500585
James Smart2e0fef82007-06-17 19:56:36 -0500586 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500587 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500588 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500589
dea31012005-04-17 16:05:31 -0500590
591 list_add_tail(&head, &mp->list);
592 list_for_each_entry_safe(mp, next_mp, &head, list) {
593 mlast = mp;
594
James Smart7054a602007-04-25 09:52:34 -0400595 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
596
dea31012005-04-17 16:05:31 -0500597 Size -= Cnt;
598
James Smart1dcb58e2007-04-25 09:51:30 -0400599 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500600 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400601 } else
dea31012005-04-17 16:05:31 -0500602 Cnt -= 16; /* subtract length of CT header */
603
604 /* Loop through entire NameServer list of DIDs */
James Smart4258e982015-12-16 18:11:58 -0500605 while (Cnt >= sizeof(uint32_t)) {
dea31012005-04-17 16:05:31 -0500606 /* Get next DID from NameServer List */
607 CTentry = *ctptr++;
608 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart1c5b12f2017-04-21 16:05:03 -0700609 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
James Smart76b2c342015-04-07 15:07:19 -0400610 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
dea31012005-04-17 16:05:31 -0500611 goto nsout1;
James Smarta0f2d3e2017-02-12 13:52:31 -0800612
James Smart4258e982015-12-16 18:11:58 -0500613 Cnt -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -0500614 }
615 ctptr = NULL;
616
617 }
618
James Smart1c5b12f2017-04-21 16:05:03 -0700619 /* All GID_FT entries processed. If the driver is running in
620 * in target mode, put impacted nodes into recovery and drop
621 * the RPI to flush outstanding IO.
622 */
623 if (vport->phba->nvmet_support) {
624 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
625 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
626 continue;
627 lpfc_disc_state_machine(vport, ndlp, NULL,
628 NLP_EVT_DEVICE_RECOVERY);
629 spin_lock_irq(shost->host_lock);
630 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
Dan Carpenter0d618cf2017-05-04 00:22:16 +0300631 spin_unlock_irq(shost->host_lock);
James Smart1c5b12f2017-04-21 16:05:03 -0700632 }
633 }
634
dea31012005-04-17 16:05:31 -0500635nsout1:
636 list_del(&head);
dea31012005-04-17 16:05:31 -0500637 return 0;
638}
639
dea31012005-04-17 16:05:31 -0500640static void
James Smart2e0fef82007-06-17 19:56:36 -0500641lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
642 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500643{
James Smart2e0fef82007-06-17 19:56:36 -0500644 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500645 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500646 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500647 struct lpfc_dmabuf *outp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800648 struct lpfc_dmabuf *inp;
dea31012005-04-17 16:05:31 -0500649 struct lpfc_sli_ct_request *CTrsp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800650 struct lpfc_sli_ct_request *CTreq;
James Smart51ef4c22007-08-02 11:10:31 -0400651 struct lpfc_nodelist *ndlp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800652 int rc, type;
dea31012005-04-17 16:05:31 -0500653
James Smart51ef4c22007-08-02 11:10:31 -0400654 /* First save ndlp, before we overwrite it */
655 ndlp = cmdiocb->context_un.ndlp;
656
dea31012005-04-17 16:05:31 -0500657 /* we pass cmdiocb to state machine which needs rspiocb as well */
658 cmdiocb->context_un.rsp_iocb = rspiocb;
James Smarta0f2d3e2017-02-12 13:52:31 -0800659 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -0500660 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
James Smart858c9f62007-06-17 19:56:39 -0500661 irsp = &rspiocb->iocb;
662
663 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
664 "GID_FT cmpl: status:x%x/x%x rtry:%d",
665 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500666
James Smart92d7f7b2007-06-17 19:56:38 -0500667 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500668 if (vport->load_flag & FC_UNLOADING) {
669 if (vport->fc_flag & FC_RSCN_MODE)
670 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500671 goto out;
James Smarteada2722008-12-04 22:39:13 -0500672 }
James Smart92d7f7b2007-06-17 19:56:38 -0500673
James Smart58da1ff2008-04-07 10:15:56 -0400674 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400675 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
676 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500677 if (vport->fc_flag & FC_RSCN_MODE)
678 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500679 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
680 goto out;
681 }
James Smart58da1ff2008-04-07 10:15:56 -0400682 if (lpfc_error_lost_link(irsp)) {
683 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
684 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500685 if (vport->fc_flag & FC_RSCN_MODE)
686 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400687 goto out;
688 }
James Smart49382502017-11-20 16:00:38 -0800689
690 spin_lock_irq(shost->host_lock);
691 if (vport->fc_flag & FC_RSCN_DEFERRED) {
692 vport->fc_flag &= ~FC_RSCN_DEFERRED;
693 spin_unlock_irq(shost->host_lock);
694
695 /*
696 * Skip processing the NS response
697 * Re-issue the NS cmd
698 */
699 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
700 "0151 Process Deferred RSCN Data: x%x x%x\n",
701 vport->fc_flag, vport->fc_rscn_id_cnt);
702 lpfc_els_handle_rscn(vport);
703
704 goto out;
705 }
706 spin_unlock_irq(shost->host_lock);
707
James Smart858c9f62007-06-17 19:56:39 -0500708 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500709 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500710 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400711 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
James Smartedb22f02012-10-31 14:45:21 -0400712 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
James Smarte3d2b802012-08-14 14:25:43 -0400713 IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500714 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500715
James Smarta0f2d3e2017-02-12 13:52:31 -0800716 type = lpfc_get_gidft_type(vport, cmdiocb);
717 if (type == 0)
718 goto out;
719
James Smart58da1ff2008-04-07 10:15:56 -0400720 /* CT command is being retried */
James Smarta0f2d3e2017-02-12 13:52:31 -0800721 vport->gidft_inp--;
James Smart58da1ff2008-04-07 10:15:56 -0400722 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smarta0f2d3e2017-02-12 13:52:31 -0800723 vport->fc_ns_retry, type);
James Smart58da1ff2008-04-07 10:15:56 -0400724 if (rc == 0)
725 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500726 }
James Smarteada2722008-12-04 22:39:13 -0500727 if (vport->fc_flag & FC_RSCN_MODE)
728 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500729 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400730 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
731 "0257 GID_FT Query error: 0x%x 0x%x\n",
732 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500733 } else {
734 /* Good status, continue checking */
James Smarta0f2d3e2017-02-12 13:52:31 -0800735 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
dea31012005-04-17 16:05:31 -0500736 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
737 if (CTrsp->CommandResponse.bits.CmdRsp ==
James Smart76b2c342015-04-07 15:07:19 -0400738 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400739 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800740 "0208 NameServer Rsp Data: x%x x%x\n",
741 vport->fc_flag,
742 CTreq->un.gid.Fc4Type);
743
744 lpfc_ns_rsp(vport,
745 outp,
746 CTreq->un.gid.Fc4Type,
dea31012005-04-17 16:05:31 -0500747 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
748 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
749 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
750 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400751 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
752 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400753 lpfc_printf_vlog(vport, KERN_INFO,
754 LOG_DISCOVERY,
755 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400756 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400757 CTrsp->CommandResponse.bits.CmdRsp,
758 (uint32_t) CTrsp->ReasonCode,
759 (uint32_t) CTrsp->Explanation,
760 vport->fc_flag);
761
762 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
763 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
764 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
765 (uint32_t) CTrsp->ReasonCode,
766 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400767 } else {
768 lpfc_printf_vlog(vport, KERN_INFO,
769 LOG_DISCOVERY,
770 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500771 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500772 CTrsp->CommandResponse.bits.CmdRsp,
773 (uint32_t) CTrsp->ReasonCode,
774 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500775 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500776
James Smarta58cbd52007-08-02 11:09:43 -0400777 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500778 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
779 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
780 (uint32_t) CTrsp->ReasonCode,
781 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400782 }
783
James Smart858c9f62007-06-17 19:56:39 -0500784
dea31012005-04-17 16:05:31 -0500785 } else {
786 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400787 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
788 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500789 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500790 CTrsp->CommandResponse.bits.CmdRsp,
791 (uint32_t) CTrsp->ReasonCode,
792 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500793 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500794
795 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
796 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
797 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
798 (uint32_t) CTrsp->ReasonCode,
799 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500800 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800801 vport->gidft_inp--;
dea31012005-04-17 16:05:31 -0500802 }
803 /* Link up / RSCN discovery */
James Smarta0f2d3e2017-02-12 13:52:31 -0800804 if ((vport->num_disc_nodes == 0) &&
805 (vport->gidft_inp == 0)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500806 /*
807 * The driver has cycled through all Nports in the RSCN payload.
808 * Complete the handling by cleaning up and marking the
809 * current driver state.
810 */
811 if (vport->port_state >= LPFC_DISC_AUTH) {
812 if (vport->fc_flag & FC_RSCN_MODE) {
813 lpfc_els_flush_rscn(vport);
814 spin_lock_irq(shost->host_lock);
815 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
816 spin_unlock_irq(shost->host_lock);
817 }
818 else
819 lpfc_els_flush_rscn(vport);
820 }
821
822 lpfc_disc_start(vport);
823 }
dea31012005-04-17 16:05:31 -0500824out:
James Smart51ef4c22007-08-02 11:10:31 -0400825 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500826 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500827 return;
828}
829
James Smart311464e2007-08-02 11:10:37 -0400830static void
James Smart92d7f7b2007-06-17 19:56:38 -0500831lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
832 struct lpfc_iocbq *rspiocb)
833{
834 struct lpfc_vport *vport = cmdiocb->vport;
835 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
836 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500837 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
838 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
839 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500840 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500841 uint8_t fbits;
842 struct lpfc_nodelist *ndlp;
843
844 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
845 did = be32_to_cpu(did);
846
James Smart858c9f62007-06-17 19:56:39 -0500847 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
848 "GFF_ID cmpl: status:x%x/x%x did:x%x",
849 irsp->ulpStatus, irsp->un.ulpWord[4], did);
850
James Smart92d7f7b2007-06-17 19:56:38 -0500851 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
852 /* Good status, continue checking */
853 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
854 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
855
856 if (CTrsp->CommandResponse.bits.CmdRsp ==
857 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
858 if ((fbits & FC4_FEATURE_INIT) &&
859 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400860 lpfc_printf_vlog(vport, KERN_INFO,
861 LOG_DISCOVERY,
862 "0270 Skip x%x GFF "
863 "NameServer Rsp Data: (init) "
864 "x%x x%x\n", did, fbits,
865 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500866 goto out;
867 }
868 }
869 }
James Smart858c9f62007-06-17 19:56:39 -0500870 else {
James Smart0ff10d42008-01-11 01:52:36 -0500871 /* Check for retry */
872 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
873 retry = 1;
874 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
James Smarte3d2b802012-08-14 14:25:43 -0400875 switch ((irsp->un.ulpWord[4] &
876 IOERR_PARAM_MASK)) {
877
James Smart0ff10d42008-01-11 01:52:36 -0500878 case IOERR_NO_RESOURCES:
879 /* We don't increment the retry
880 * count for this case.
881 */
882 break;
883 case IOERR_LINK_DOWN:
884 case IOERR_SLI_ABORTED:
885 case IOERR_SLI_DOWN:
886 retry = 0;
887 break;
888 default:
889 cmdiocb->retry++;
890 }
891 }
892 else
893 cmdiocb->retry++;
894
895 if (retry) {
896 /* CT command is being retried */
897 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
898 cmdiocb->retry, did);
899 if (rc == 0) {
900 /* success */
901 lpfc_ct_free_iocb(phba, cmdiocb);
902 return;
903 }
904 }
905 }
James Smarte8b62012007-08-02 11:10:09 -0400906 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
907 "0267 NameServer GFF Rsp "
908 "x%x Error (%d %d) Data: x%x x%x\n",
909 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500910 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500911 }
912
James Smart92d7f7b2007-06-17 19:56:38 -0500913 /* This is a target port, unregistered port, or the GFF_ID failed */
914 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400915 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400916 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
917 "0242 Process x%x GFF "
918 "NameServer Rsp Data: x%x x%x x%x\n",
919 did, ndlp->nlp_flag, vport->fc_flag,
920 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500921 } else {
James Smarte8b62012007-08-02 11:10:09 -0400922 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
923 "0243 Skip x%x GFF "
924 "NameServer Rsp Data: x%x x%x\n", did,
925 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500926 }
927out:
928 /* Link up / RSCN discovery */
929 if (vport->num_disc_nodes)
930 vport->num_disc_nodes--;
931 if (vport->num_disc_nodes == 0) {
932 /*
933 * The driver has cycled through all Nports in the RSCN payload.
934 * Complete the handling by cleaning up and marking the
935 * current driver state.
936 */
937 if (vport->port_state >= LPFC_DISC_AUTH) {
938 if (vport->fc_flag & FC_RSCN_MODE) {
939 lpfc_els_flush_rscn(vport);
940 spin_lock_irq(shost->host_lock);
941 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
942 spin_unlock_irq(shost->host_lock);
943 }
944 else
945 lpfc_els_flush_rscn(vport);
946 }
947 lpfc_disc_start(vport);
948 }
James Smart858c9f62007-06-17 19:56:39 -0500949 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500950 return;
951}
952
James Smarta0f2d3e2017-02-12 13:52:31 -0800953static void
954lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
955 struct lpfc_iocbq *rspiocb)
956{
957 struct lpfc_vport *vport = cmdiocb->vport;
958 IOCB_t *irsp = &rspiocb->iocb;
959 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
960 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
961 struct lpfc_sli_ct_request *CTrsp;
962 int did;
963 struct lpfc_nodelist *ndlp;
964 uint32_t fc4_data_0, fc4_data_1;
965
966 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
967 did = be32_to_cpu(did);
968
James Smartbd2cdd52017-02-12 13:52:33 -0800969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
970 "GFT_ID cmpl: status:x%x/x%x did:x%x",
971 irsp->ulpStatus, irsp->un.ulpWord[4], did);
972
James Smarta0f2d3e2017-02-12 13:52:31 -0800973 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
974 /* Good status, continue checking */
975 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
976 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
977 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700978 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800979 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
980 did, fc4_data_0, fc4_data_1);
981
982 ndlp = lpfc_findnode_did(vport, did);
983 if (ndlp) {
984 /* The bitmask value for FCP and NVME FCP types is
985 * the same because they are 32 bits distant from
986 * each other in word0 and word0.
987 */
988 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
989 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
990 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
991 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700992 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800993 "3064 Setting ndlp %p, DID x%06x with "
994 "FC4 x%08x, Data: x%08x x%08x\n",
995 ndlp, did, ndlp->nlp_fc4_type,
996 FC_TYPE_FCP, FC_TYPE_NVME);
James Smartb5ccc7d2017-03-04 09:30:39 -0800997 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
Gustavo A. R. Silvae6ef6a72017-05-23 10:09:28 -0500998
999 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1000 lpfc_issue_els_prli(vport, ndlp, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08001001 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001002 } else
1003 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1004 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1005
1006 lpfc_ct_free_iocb(phba, cmdiocb);
1007}
James Smart92d7f7b2007-06-17 19:56:38 -05001008
dea31012005-04-17 16:05:31 -05001009static void
James Smart7ee5d432007-10-27 13:37:17 -04001010lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1011 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001012{
James Smart92d7f7b2007-06-17 19:56:38 -05001013 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001014 struct lpfc_dmabuf *inp;
1015 struct lpfc_dmabuf *outp;
1016 IOCB_t *irsp;
1017 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -04001018 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05001019 int cmdcode, rc;
1020 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -05001021 uint32_t latt;
dea31012005-04-17 16:05:31 -05001022
James Smart51ef4c22007-08-02 11:10:31 -04001023 /* First save ndlp, before we overwrite it */
1024 ndlp = cmdiocb->context_un.ndlp;
1025
dea31012005-04-17 16:05:31 -05001026 /* we pass cmdiocb to state machine which needs rspiocb as well */
1027 cmdiocb->context_un.rsp_iocb = rspiocb;
1028
1029 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1030 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001031 irsp = &rspiocb->iocb;
1032
James Smart92d7f7b2007-06-17 19:56:38 -05001033 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1034 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -05001035 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1036
James Smart858c9f62007-06-17 19:56:39 -05001037 latt = lpfc_els_chk_latt(vport);
1038
1039 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -04001040 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -04001041 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -04001042 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1043 latt, irsp->ulpStatus,
1044 CTrsp->CommandResponse.bits.CmdRsp,
1045 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05001046
James Smart858c9f62007-06-17 19:56:39 -05001047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1048 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1049 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1050
James Smart92d7f7b2007-06-17 19:56:38 -05001051 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001052 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6e155202013-07-15 18:35:21 -04001053 "0268 NS cmd x%x Error (x%x x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04001054 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001055
James Smart92d7f7b2007-06-17 19:56:38 -05001056 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001057 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1058 IOERR_SLI_DOWN) ||
1059 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1060 IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -05001061 goto out;
1062
1063 retry = cmdiocb->retry;
1064 if (retry >= LPFC_MAX_NS_RETRY)
1065 goto out;
1066
1067 retry++;
James Smarte8b62012007-08-02 11:10:09 -04001068 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04001069 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -05001070 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1071 if (rc == 0)
1072 goto out;
1073 }
1074
1075out:
James Smart51ef4c22007-08-02 11:10:31 -04001076 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -05001077 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001078 return;
1079}
1080
1081static void
James Smart7ee5d432007-10-27 13:37:17 -04001082lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1083 struct lpfc_iocbq *rspiocb)
1084{
1085 IOCB_t *irsp = &rspiocb->iocb;
1086 struct lpfc_vport *vport = cmdiocb->vport;
1087
James Smart98c9ea52007-10-27 13:37:33 -04001088 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1089 struct lpfc_dmabuf *outp;
1090 struct lpfc_sli_ct_request *CTrsp;
1091
1092 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1093 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1094 if (CTrsp->CommandResponse.bits.CmdRsp ==
1095 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1096 vport->ct_flags |= FC_CT_RFT_ID;
1097 }
James Smart7ee5d432007-10-27 13:37:17 -04001098 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1099 return;
1100}
1101
1102static void
James Smart2e0fef82007-06-17 19:56:36 -05001103lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1104 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001105{
James Smart7ee5d432007-10-27 13:37:17 -04001106 IOCB_t *irsp = &rspiocb->iocb;
1107 struct lpfc_vport *vport = cmdiocb->vport;
1108
James Smart98c9ea52007-10-27 13:37:33 -04001109 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1110 struct lpfc_dmabuf *outp;
1111 struct lpfc_sli_ct_request *CTrsp;
1112
1113 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1114 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1115 if (CTrsp->CommandResponse.bits.CmdRsp ==
1116 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1117 vport->ct_flags |= FC_CT_RNN_ID;
1118 }
James Smart7ee5d432007-10-27 13:37:17 -04001119 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001120 return;
1121}
1122
1123static void
James Smart92d7f7b2007-06-17 19:56:38 -05001124lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1125 struct lpfc_iocbq *rspiocb)
1126{
James Smart7ee5d432007-10-27 13:37:17 -04001127 IOCB_t *irsp = &rspiocb->iocb;
1128 struct lpfc_vport *vport = cmdiocb->vport;
1129
James Smart98c9ea52007-10-27 13:37:33 -04001130 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1131 struct lpfc_dmabuf *outp;
1132 struct lpfc_sli_ct_request *CTrsp;
1133
1134 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1135 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1136 if (CTrsp->CommandResponse.bits.CmdRsp ==
1137 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1138 vport->ct_flags |= FC_CT_RSPN_ID;
1139 }
James Smart7ee5d432007-10-27 13:37:17 -04001140 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05001141 return;
1142}
1143
1144static void
James Smart2e0fef82007-06-17 19:56:36 -05001145lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1146 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001147{
James Smart7ee5d432007-10-27 13:37:17 -04001148 IOCB_t *irsp = &rspiocb->iocb;
1149 struct lpfc_vport *vport = cmdiocb->vport;
1150
James Smart98c9ea52007-10-27 13:37:33 -04001151 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1152 struct lpfc_dmabuf *outp;
1153 struct lpfc_sli_ct_request *CTrsp;
1154
1155 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1156 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1157 if (CTrsp->CommandResponse.bits.CmdRsp ==
1158 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1159 vport->ct_flags |= FC_CT_RSNN_NN;
1160 }
James Smart7ee5d432007-10-27 13:37:17 -04001161 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1162 return;
1163}
1164
1165static void
1166lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1167 struct lpfc_iocbq *rspiocb)
1168{
1169 struct lpfc_vport *vport = cmdiocb->vport;
1170
1171 /* even if it fails we will act as though it succeeded. */
1172 vport->ct_flags = 0;
1173 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001174 return;
1175}
1176
James Smart2fb9bd82006-12-02 13:33:57 -05001177static void
James Smart92d7f7b2007-06-17 19:56:38 -05001178lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1179 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001180{
James Smart92d7f7b2007-06-17 19:56:38 -05001181 IOCB_t *irsp = &rspiocb->iocb;
1182 struct lpfc_vport *vport = cmdiocb->vport;
1183
James Smart98c9ea52007-10-27 13:37:33 -04001184 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1185 struct lpfc_dmabuf *outp;
1186 struct lpfc_sli_ct_request *CTrsp;
1187
1188 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1189 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1190 if (CTrsp->CommandResponse.bits.CmdRsp ==
1191 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1192 vport->ct_flags |= FC_CT_RFF_ID;
1193 }
James Smart7ee5d432007-10-27 13:37:17 -04001194 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001195 return;
1196}
1197
James Smarta0f2d3e2017-02-12 13:52:31 -08001198/*
1199 * Although the symbolic port name is thought to be an integer
1200 * as of January 18, 2016, leave it as a string until more of
1201 * the record state becomes defined.
1202 */
James Smart495a7142008-06-14 22:52:59 -04001203int
James Smart92d7f7b2007-06-17 19:56:38 -05001204lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1205 size_t size)
1206{
1207 int n;
James Smart92d7f7b2007-06-17 19:56:38 -05001208
James Smarta0f2d3e2017-02-12 13:52:31 -08001209 /*
1210 * Use the lpfc board number as the Symbolic Port
1211 * Name object. NPIV is not in play so this integer
1212 * value is sufficient and unique per FC-ID.
1213 */
1214 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
James Smart92d7f7b2007-06-17 19:56:38 -05001215 return n;
1216}
1217
James Smarta0f2d3e2017-02-12 13:52:31 -08001218
James Smart92d7f7b2007-06-17 19:56:38 -05001219int
1220lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1221 size_t size)
dea31012005-04-17 16:05:31 -05001222{
James Smart6b5151f2012-01-18 16:24:06 -05001223 char fwrev[FW_REV_STR_SIZE];
James Smart92d7f7b2007-06-17 19:56:38 -05001224 int n;
dea31012005-04-17 16:05:31 -05001225
James Smart92d7f7b2007-06-17 19:56:38 -05001226 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001227
James Smartf0bf5f92015-04-07 15:07:18 -04001228 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
James Smartf0bf5f92015-04-07 15:07:18 -04001229 if (size < n)
1230 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001231
James Smartf0bf5f92015-04-07 15:07:18 -04001232 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
James Smartf0bf5f92015-04-07 15:07:18 -04001233 if (size < n)
1234 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001235
James Smarta0f2d3e2017-02-12 13:52:31 -08001236 n += snprintf(symbol + n, size - n, " DV%s.",
1237 lpfc_release_version);
James Smartf0bf5f92015-04-07 15:07:18 -04001238 if (size < n)
1239 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001240
1241 n += snprintf(symbol + n, size - n, " HN:%s.",
1242 init_utsname()->nodename);
1243 if (size < n)
1244 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001245
1246 /* Note :- OS name is "Linux" */
James Smarta0f2d3e2017-02-12 13:52:31 -08001247 n += snprintf(symbol + n, size - n, " OS:%s\n",
1248 init_utsname()->sysname);
James Smart92d7f7b2007-06-17 19:56:38 -05001249 return n;
dea31012005-04-17 16:05:31 -05001250}
1251
James Smart76b2c342015-04-07 15:07:19 -04001252static uint32_t
1253lpfc_find_map_node(struct lpfc_vport *vport)
1254{
1255 struct lpfc_nodelist *ndlp, *next_ndlp;
1256 struct Scsi_Host *shost;
1257 uint32_t cnt = 0;
1258
1259 shost = lpfc_shost_from_vport(vport);
1260 spin_lock_irq(shost->host_lock);
1261 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1262 if (ndlp->nlp_type & NLP_FABRIC)
1263 continue;
1264 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1265 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1266 cnt++;
1267 }
1268 spin_unlock_irq(shost->host_lock);
1269 return cnt;
1270}
1271
dea31012005-04-17 16:05:31 -05001272/*
James Smarta0f2d3e2017-02-12 13:52:31 -08001273 * This routine will return the FC4 Type associated with the CT
1274 * GID_FT command.
1275 */
1276int
1277lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1278{
1279 struct lpfc_sli_ct_request *CtReq;
1280 struct lpfc_dmabuf *mp;
1281 uint32_t type;
1282
1283 mp = cmdiocb->context1;
1284 if (mp == NULL)
1285 return 0;
1286 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1287 type = (uint32_t)CtReq->un.gid.Fc4Type;
1288 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1289 return 0;
1290 return type;
1291}
1292
1293/*
dea31012005-04-17 16:05:31 -05001294 * lpfc_ns_cmd
1295 * Description:
1296 * Issue Cmd to NameServer
1297 * SLI_CTNS_GID_FT
1298 * LI_CTNS_RFT_ID
1299 */
1300int
James Smart92d7f7b2007-06-17 19:56:38 -05001301lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1302 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001303{
James Smart92d7f7b2007-06-17 19:56:38 -05001304 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001305 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001306 struct lpfc_dmabuf *mp, *bmp;
1307 struct lpfc_sli_ct_request *CtReq;
1308 struct ulp_bde64 *bpl;
1309 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1310 struct lpfc_iocbq *) = NULL;
1311 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001312 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001313 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001314
1315 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001316 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1317 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001318 rc=1;
1319 goto ns_cmd_exit;
1320 }
dea31012005-04-17 16:05:31 -05001321
1322 /* fill in BDEs for command */
1323 /* Allocate buffer for command payload */
James Smart4258e982015-12-16 18:11:58 -05001324 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001325 if (!mp) {
1326 rc=2;
dea31012005-04-17 16:05:31 -05001327 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001328 }
dea31012005-04-17 16:05:31 -05001329
1330 INIT_LIST_HEAD(&mp->list);
1331 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001332 if (!mp->virt) {
1333 rc=3;
dea31012005-04-17 16:05:31 -05001334 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001335 }
dea31012005-04-17 16:05:31 -05001336
1337 /* Allocate buffer for Buffer ptr list */
James Smart4258e982015-12-16 18:11:58 -05001338 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001339 if (!bmp) {
1340 rc=4;
dea31012005-04-17 16:05:31 -05001341 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001342 }
dea31012005-04-17 16:05:31 -05001343
1344 INIT_LIST_HEAD(&bmp->list);
1345 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001346 if (!bmp->virt) {
1347 rc=5;
dea31012005-04-17 16:05:31 -05001348 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001349 }
dea31012005-04-17 16:05:31 -05001350
1351 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001352 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -08001353 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1354 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1355 context);
dea31012005-04-17 16:05:31 -05001356
1357 bpl = (struct ulp_bde64 *) bmp->virt;
1358 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001359 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1360 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001361 bpl->tus.f.bdeFlags = 0;
1362 if (cmdcode == SLI_CTNS_GID_FT)
1363 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001364 else if (cmdcode == SLI_CTNS_GFF_ID)
1365 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
James Smarta0f2d3e2017-02-12 13:52:31 -08001366 else if (cmdcode == SLI_CTNS_GFT_ID)
1367 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001368 else if (cmdcode == SLI_CTNS_RFT_ID)
1369 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1370 else if (cmdcode == SLI_CTNS_RNN_ID)
1371 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001372 else if (cmdcode == SLI_CTNS_RSPN_ID)
1373 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001374 else if (cmdcode == SLI_CTNS_RSNN_NN)
1375 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001376 else if (cmdcode == SLI_CTNS_DA_ID)
1377 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001378 else if (cmdcode == SLI_CTNS_RFF_ID)
1379 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001380 else
1381 bpl->tus.f.bdeSize = 0;
1382 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1383
1384 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
James Smart4258e982015-12-16 18:11:58 -05001385 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
dea31012005-04-17 16:05:31 -05001386 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1387 CtReq->RevisionId.bits.InId = 0;
1388 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1389 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1390 CtReq->CommandResponse.bits.Size = 0;
1391 switch (cmdcode) {
1392 case SLI_CTNS_GID_FT:
1393 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001394 cpu_to_be16(SLI_CTNS_GID_FT);
James Smarta0f2d3e2017-02-12 13:52:31 -08001395 CtReq->un.gid.Fc4Type = context;
1396
James Smart92d7f7b2007-06-17 19:56:38 -05001397 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001398 vport->port_state = LPFC_NS_QRY;
1399 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001400 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1401 rsp_size = FC_MAX_NS_RSP;
1402 break;
1403
James Smart92d7f7b2007-06-17 19:56:38 -05001404 case SLI_CTNS_GFF_ID:
1405 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001406 cpu_to_be16(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001407 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001408 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1409 break;
1410
James Smarta0f2d3e2017-02-12 13:52:31 -08001411 case SLI_CTNS_GFT_ID:
1412 CtReq->CommandResponse.bits.CmdRsp =
1413 cpu_to_be16(SLI_CTNS_GFT_ID);
1414 CtReq->un.gft.PortId = cpu_to_be32(context);
1415 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1416 break;
1417
dea31012005-04-17 16:05:31 -05001418 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001419 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001420 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001421 cpu_to_be16(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001422 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
James Smarta0f2d3e2017-02-12 13:52:31 -08001423
1424 /* Register FC4 FCP type if enabled. */
1425 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1426 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1427 CtReq->un.rft.fcpReg = 1;
1428
1429 /* Register NVME type if enabled. Defined LE and swapped.
1430 * rsvd[0] is used as word1 because of the hard-coded
1431 * word0 usage in the ct_request data structure.
1432 */
1433 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1434 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1435 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1436
dea31012005-04-17 16:05:31 -05001437 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1438 break;
1439
1440 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001441 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001442 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001443 cpu_to_be16(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001444 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001445 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001446 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001447 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1448 break;
1449
James Smart92d7f7b2007-06-17 19:56:38 -05001450 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001451 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001452 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001453 cpu_to_be16(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001454 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001455 size = sizeof(CtReq->un.rspn.symbname);
1456 CtReq->un.rspn.len =
1457 lpfc_vport_symbolic_port_name(vport,
1458 CtReq->un.rspn.symbname, size);
1459 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1460 break;
dea31012005-04-17 16:05:31 -05001461 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001462 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001463 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001464 cpu_to_be16(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001465 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001466 sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001467 size = sizeof(CtReq->un.rsnn.symbname);
1468 CtReq->un.rsnn.len =
1469 lpfc_vport_symbolic_node_name(vport,
1470 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001471 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1472 break;
James Smart7ee5d432007-10-27 13:37:17 -04001473 case SLI_CTNS_DA_ID:
1474 /* Implement DA_ID Nameserver request */
1475 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001476 cpu_to_be16(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001477 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001478 cmpl = lpfc_cmpl_ct_cmd_da_id;
1479 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001480 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001481 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001482 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001483 cpu_to_be16(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001484 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001485 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smarta0f2d3e2017-02-12 13:52:31 -08001486
1487 /* The driver always supports FC_TYPE_FCP. However, the
1488 * caller can specify NVME (type x28) as well. But only
1489 * these that FC4 type is supported.
1490 */
1491 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1492 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1493 (context == FC_TYPE_NVME)) {
James Smart8c258642017-02-12 13:52:36 -08001494 if ((vport == phba->pport) && phba->nvmet_support) {
1495 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1496 FC4_FEATURE_NVME_DISC);
James Smartd613b6a2017-02-12 13:52:37 -08001497 lpfc_nvmet_update_targetport(phba);
James Smart8c258642017-02-12 13:52:36 -08001498 } else {
1499 lpfc_nvme_update_localport(vport);
1500 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001501 CtReq->un.rff.type_code = context;
1502
1503 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1504 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1505 (context == FC_TYPE_FCP))
1506 CtReq->un.rff.type_code = context;
1507
1508 else
1509 goto ns_cmd_free_bmpvirt;
1510
James Smart92d7f7b2007-06-17 19:56:38 -05001511 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1512 break;
dea31012005-04-17 16:05:31 -05001513 }
James Smarte47c9092008-02-08 18:49:26 -05001514 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1515 * to hold ndlp reference for the corresponding callback function.
1516 */
James Smart858c9f62007-06-17 19:56:39 -05001517 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001518 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001519 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1520 "Issue CT cmd: cmd:x%x did:x%x",
1521 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001522 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001523 }
James Smart858c9f62007-06-17 19:56:39 -05001524 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001525
1526 /* Decrement ndlp reference count to release ndlp reference held
1527 * for the failed command's callback function.
1528 */
James Smart51ef4c22007-08-02 11:10:31 -04001529 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001530
James Smarta0f2d3e2017-02-12 13:52:31 -08001531ns_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05001532 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1533ns_cmd_free_bmp:
1534 kfree(bmp);
1535ns_cmd_free_mpvirt:
1536 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1537ns_cmd_free_mp:
1538 kfree(mp);
1539ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001540 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1541 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1542 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001543 return 1;
1544}
1545
James Smart4258e982015-12-16 18:11:58 -05001546/**
1547 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1548 * @phba: Pointer to HBA context object.
1549 * @cmdiocb: Pointer to the command IOCBQ.
1550 * @rspiocb: Pointer to the response IOCBQ.
1551 *
1552 * This function to handle the completion of a driver initiated FDMI
1553 * CT command issued during discovery.
1554 */
dea31012005-04-17 16:05:31 -05001555static void
James Smart4258e982015-12-16 18:11:58 -05001556lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1557 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001558{
James Smart4258e982015-12-16 18:11:58 -05001559 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001560 struct lpfc_dmabuf *inp = cmdiocb->context1;
1561 struct lpfc_dmabuf *outp = cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001562 struct lpfc_sli_ct_request *CTcmd = inp->virt;
James Smart4258e982015-12-16 18:11:58 -05001563 struct lpfc_sli_ct_request *CTrsp = outp->virt;
dea31012005-04-17 16:05:31 -05001564 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1565 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart858c9f62007-06-17 19:56:39 -05001566 IOCB_t *irsp = &rspiocb->iocb;
James Smart4258e982015-12-16 18:11:58 -05001567 struct lpfc_nodelist *ndlp;
1568 uint32_t latt, cmd, err;
James Smart858c9f62007-06-17 19:56:39 -05001569
1570 latt = lpfc_els_chk_latt(vport);
James Smart858c9f62007-06-17 19:56:39 -05001571 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1572 "FDMI cmpl: status:x%x/x%x latt:%d",
1573 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1574
1575 if (latt || irsp->ulpStatus) {
James Smart4258e982015-12-16 18:11:58 -05001576
1577 /* Look for a retryable error */
1578 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1579 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1580 case IOERR_SLI_ABORTED:
1581 case IOERR_ABORT_IN_PROGRESS:
1582 case IOERR_SEQUENCE_TIMEOUT:
1583 case IOERR_ILLEGAL_FRAME:
1584 case IOERR_NO_RESOURCES:
1585 case IOERR_ILLEGAL_COMMAND:
1586 cmdiocb->retry++;
1587 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1588 break;
1589
1590 /* Retry the same FDMI command */
1591 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1592 cmdiocb, 0);
1593 if (err == IOCB_ERROR)
1594 break;
1595 return;
1596 default:
1597 break;
1598 }
1599 }
1600
James Smarte8b62012007-08-02 11:10:09 -04001601 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1602 "0229 FDMI cmd %04x failed, latt = %d "
1603 "ulpStatus: x%x, rid x%x\n",
1604 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1605 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001606 }
James Smart76b2c342015-04-07 15:07:19 -04001607 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart76b2c342015-04-07 15:07:19 -04001608
1609 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1610 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1611 return;
1612
James Smart4258e982015-12-16 18:11:58 -05001613 /* Check for a CT LS_RJT response */
1614 cmd = be16_to_cpu(fdmi_cmd);
1615 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1616 /* FDMI rsp failed */
1617 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1618 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1619
1620 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1621 switch (cmd) {
1622 case SLI_MGMT_RHBA:
1623 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1624 /* Fallback to FDMI-1 */
1625 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1626 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1627 /* Start over */
1628 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1629 }
1630 return;
1631
1632 case SLI_MGMT_RPRT:
1633 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1634 /* Fallback to FDMI-1 */
1635 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1636 /* Start over */
1637 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1638 }
1639 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1640 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1641 /* Retry the same command */
1642 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1643 }
1644 return;
1645
1646 case SLI_MGMT_RPA:
1647 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1648 /* Fallback to FDMI-1 */
1649 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1650 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1651 /* Start over */
1652 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1653 }
1654 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1655 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1656 /* Retry the same command */
1657 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1658 }
1659 return;
1660 }
1661 }
1662
James Smart76b2c342015-04-07 15:07:19 -04001663 /*
James Smart4258e982015-12-16 18:11:58 -05001664 * On success, need to cycle thru FDMI registration for discovery
1665 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1666 * DPRT -> RPRT (vports)
James Smart76b2c342015-04-07 15:07:19 -04001667 */
James Smart4258e982015-12-16 18:11:58 -05001668 switch (cmd) {
dea31012005-04-17 16:05:31 -05001669 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05001670 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
dea31012005-04-17 16:05:31 -05001671 break;
1672
dea31012005-04-17 16:05:31 -05001673 case SLI_MGMT_DHBA:
James Smart4258e982015-12-16 18:11:58 -05001674 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
dea31012005-04-17 16:05:31 -05001675 break;
1676
1677 case SLI_MGMT_DPRT:
James Smart4258e982015-12-16 18:11:58 -05001678 if (vport->port_type == LPFC_PHYSICAL_PORT)
1679 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1680 else
1681 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
dea31012005-04-17 16:05:31 -05001682 break;
1683 }
James Smart4258e982015-12-16 18:11:58 -05001684 return;
dea31012005-04-17 16:05:31 -05001685}
James Smart2e0fef82007-06-17 19:56:36 -05001686
James Smart76b2c342015-04-07 15:07:19 -04001687
James Smart4258e982015-12-16 18:11:58 -05001688/**
1689 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1690 * @vport: pointer to a host virtual N_Port data structure.
1691 *
1692 * Called from hbeat timeout routine to check if the number of discovered
1693 * ports has changed. If so, re-register thar port Attribute.
1694 */
1695void
1696lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1697{
1698 struct lpfc_hba *phba = vport->phba;
1699 struct lpfc_nodelist *ndlp;
1700 uint16_t cnt;
1701
1702 if (!lpfc_is_link_up(phba))
1703 return;
1704
James Smarta03a4212016-07-06 12:36:12 -07001705 /* Must be connected to a Fabric */
1706 if (!(vport->fc_flag & FC_FABRIC))
1707 return;
1708
James Smart4258e982015-12-16 18:11:58 -05001709 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1710 return;
1711
1712 cnt = lpfc_find_map_node(vport);
1713 if (cnt == vport->fdmi_num_disc)
1714 return;
1715
1716 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1717 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1718 return;
1719
1720 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1721 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1722 LPFC_FDMI_PORT_ATTR_num_disc);
1723 } else {
1724 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1725 LPFC_FDMI_PORT_ATTR_num_disc);
1726 }
1727}
1728
1729/* Routines for all individual HBA attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001730static int
James Smart4258e982015-12-16 18:11:58 -05001731lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1732{
1733 struct lpfc_fdmi_attr_entry *ae;
1734 uint32_t size;
1735
1736 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1737 memset(ae, 0, sizeof(struct lpfc_name));
1738
1739 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1740 sizeof(struct lpfc_name));
1741 size = FOURBYTES + sizeof(struct lpfc_name);
1742 ad->AttrLen = cpu_to_be16(size);
1743 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1744 return size;
1745}
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001746static int
James Smart4258e982015-12-16 18:11:58 -05001747lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1748 struct lpfc_fdmi_attr_def *ad)
1749{
1750 struct lpfc_fdmi_attr_entry *ae;
1751 uint32_t len, size;
1752
1753 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1754 memset(ae, 0, 256);
1755
1756 strncpy(ae->un.AttrString,
1757 "Emulex Corporation",
1758 sizeof(ae->un.AttrString));
1759 len = strnlen(ae->un.AttrString,
1760 sizeof(ae->un.AttrString));
1761 len += (len & 3) ? (4 - (len & 3)) : 4;
1762 size = FOURBYTES + len;
1763 ad->AttrLen = cpu_to_be16(size);
1764 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1765 return size;
1766}
1767
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001768static int
James Smart4258e982015-12-16 18:11:58 -05001769lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1770{
1771 struct lpfc_hba *phba = vport->phba;
1772 struct lpfc_fdmi_attr_entry *ae;
1773 uint32_t len, size;
1774
1775 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1776 memset(ae, 0, 256);
1777
1778 strncpy(ae->un.AttrString, phba->SerialNumber,
1779 sizeof(ae->un.AttrString));
1780 len = strnlen(ae->un.AttrString,
1781 sizeof(ae->un.AttrString));
1782 len += (len & 3) ? (4 - (len & 3)) : 4;
1783 size = FOURBYTES + len;
1784 ad->AttrLen = cpu_to_be16(size);
1785 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1786 return size;
1787}
1788
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001789static int
James Smart4258e982015-12-16 18:11:58 -05001790lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1791 struct lpfc_fdmi_attr_def *ad)
1792{
1793 struct lpfc_hba *phba = vport->phba;
1794 struct lpfc_fdmi_attr_entry *ae;
1795 uint32_t len, size;
1796
1797 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1798 memset(ae, 0, 256);
1799
1800 strncpy(ae->un.AttrString, phba->ModelName,
1801 sizeof(ae->un.AttrString));
1802 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1803 len += (len & 3) ? (4 - (len & 3)) : 4;
1804 size = FOURBYTES + len;
1805 ad->AttrLen = cpu_to_be16(size);
1806 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1807 return size;
1808}
1809
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001810static int
James Smart4258e982015-12-16 18:11:58 -05001811lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1812 struct lpfc_fdmi_attr_def *ad)
1813{
1814 struct lpfc_hba *phba = vport->phba;
1815 struct lpfc_fdmi_attr_entry *ae;
1816 uint32_t len, size;
1817
1818 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1819 memset(ae, 0, 256);
1820
1821 strncpy(ae->un.AttrString, phba->ModelDesc,
1822 sizeof(ae->un.AttrString));
1823 len = strnlen(ae->un.AttrString,
1824 sizeof(ae->un.AttrString));
1825 len += (len & 3) ? (4 - (len & 3)) : 4;
1826 size = FOURBYTES + len;
1827 ad->AttrLen = cpu_to_be16(size);
1828 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1829 return size;
1830}
1831
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001832static int
James Smart4258e982015-12-16 18:11:58 -05001833lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1834 struct lpfc_fdmi_attr_def *ad)
1835{
1836 struct lpfc_hba *phba = vport->phba;
1837 lpfc_vpd_t *vp = &phba->vpd;
1838 struct lpfc_fdmi_attr_entry *ae;
1839 uint32_t i, j, incr, size;
1840
1841 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1842 memset(ae, 0, 256);
1843
1844 /* Convert JEDEC ID to ascii for hardware version */
1845 incr = vp->rev.biuRev;
1846 for (i = 0; i < 8; i++) {
1847 j = (incr & 0xf);
1848 if (j <= 9)
1849 ae->un.AttrString[7 - i] =
1850 (char)((uint8_t) 0x30 +
1851 (uint8_t) j);
1852 else
1853 ae->un.AttrString[7 - i] =
1854 (char)((uint8_t) 0x61 +
1855 (uint8_t) (j - 10));
1856 incr = (incr >> 4);
1857 }
1858 size = FOURBYTES + 8;
1859 ad->AttrLen = cpu_to_be16(size);
1860 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1861 return size;
1862}
1863
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001864static int
James Smart4258e982015-12-16 18:11:58 -05001865lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1866 struct lpfc_fdmi_attr_def *ad)
1867{
1868 struct lpfc_fdmi_attr_entry *ae;
1869 uint32_t len, size;
1870
1871 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1872 memset(ae, 0, 256);
1873
1874 strncpy(ae->un.AttrString, lpfc_release_version,
1875 sizeof(ae->un.AttrString));
1876 len = strnlen(ae->un.AttrString,
1877 sizeof(ae->un.AttrString));
1878 len += (len & 3) ? (4 - (len & 3)) : 4;
1879 size = FOURBYTES + len;
1880 ad->AttrLen = cpu_to_be16(size);
1881 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1882 return size;
1883}
1884
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001885static int
James Smart4258e982015-12-16 18:11:58 -05001886lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1887 struct lpfc_fdmi_attr_def *ad)
1888{
1889 struct lpfc_hba *phba = vport->phba;
1890 struct lpfc_fdmi_attr_entry *ae;
1891 uint32_t len, size;
1892
1893 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1894 memset(ae, 0, 256);
1895
1896 if (phba->sli_rev == LPFC_SLI_REV4)
1897 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1898 else
1899 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1900 sizeof(ae->un.AttrString));
1901 len = strnlen(ae->un.AttrString,
1902 sizeof(ae->un.AttrString));
1903 len += (len & 3) ? (4 - (len & 3)) : 4;
1904 size = FOURBYTES + len;
1905 ad->AttrLen = cpu_to_be16(size);
1906 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1907 return size;
1908}
1909
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001910static int
James Smart4258e982015-12-16 18:11:58 -05001911lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1912 struct lpfc_fdmi_attr_def *ad)
1913{
1914 struct lpfc_hba *phba = vport->phba;
1915 struct lpfc_fdmi_attr_entry *ae;
1916 uint32_t len, size;
1917
1918 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1919 memset(ae, 0, 256);
1920
1921 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1922 len = strnlen(ae->un.AttrString,
1923 sizeof(ae->un.AttrString));
1924 len += (len & 3) ? (4 - (len & 3)) : 4;
1925 size = FOURBYTES + len;
1926 ad->AttrLen = cpu_to_be16(size);
1927 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1928 return size;
1929}
1930
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001931static int
James Smart4258e982015-12-16 18:11:58 -05001932lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1933 struct lpfc_fdmi_attr_def *ad)
1934{
1935 struct lpfc_fdmi_attr_entry *ae;
1936 uint32_t len, size;
1937
1938 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1939 memset(ae, 0, 256);
1940
1941 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1942 init_utsname()->sysname,
1943 init_utsname()->release,
1944 init_utsname()->version);
1945
1946 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1947 len += (len & 3) ? (4 - (len & 3)) : 4;
1948 size = FOURBYTES + len;
1949 ad->AttrLen = cpu_to_be16(size);
1950 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1951 return size;
1952}
1953
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001954static int
James Smart4258e982015-12-16 18:11:58 -05001955lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1956 struct lpfc_fdmi_attr_def *ad)
1957{
1958 struct lpfc_fdmi_attr_entry *ae;
1959 uint32_t size;
1960
1961 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1962
1963 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1964 size = FOURBYTES + sizeof(uint32_t);
1965 ad->AttrLen = cpu_to_be16(size);
1966 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1967 return size;
1968}
1969
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001970static int
James Smart4258e982015-12-16 18:11:58 -05001971lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1972 struct lpfc_fdmi_attr_def *ad)
1973{
1974 struct lpfc_fdmi_attr_entry *ae;
1975 uint32_t len, size;
1976
1977 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1978 memset(ae, 0, 256);
1979
1980 len = lpfc_vport_symbolic_node_name(vport,
1981 ae->un.AttrString, 256);
1982 len += (len & 3) ? (4 - (len & 3)) : 4;
1983 size = FOURBYTES + len;
1984 ad->AttrLen = cpu_to_be16(size);
1985 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1986 return size;
1987}
1988
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001989static int
James Smart4258e982015-12-16 18:11:58 -05001990lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
1991 struct lpfc_fdmi_attr_def *ad)
1992{
1993 struct lpfc_fdmi_attr_entry *ae;
1994 uint32_t size;
1995
1996 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1997
1998 /* Nothing is defined for this currently */
1999 ae->un.AttrInt = cpu_to_be32(0);
2000 size = FOURBYTES + sizeof(uint32_t);
2001 ad->AttrLen = cpu_to_be16(size);
2002 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2003 return size;
2004}
2005
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002006static int
James Smart4258e982015-12-16 18:11:58 -05002007lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2008 struct lpfc_fdmi_attr_def *ad)
2009{
2010 struct lpfc_fdmi_attr_entry *ae;
2011 uint32_t size;
2012
2013 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2014
2015 /* Each driver instance corresponds to a single port */
2016 ae->un.AttrInt = cpu_to_be32(1);
2017 size = FOURBYTES + sizeof(uint32_t);
2018 ad->AttrLen = cpu_to_be16(size);
2019 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2020 return size;
2021}
2022
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002023static int
James Smart4258e982015-12-16 18:11:58 -05002024lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2025 struct lpfc_fdmi_attr_def *ad)
2026{
2027 struct lpfc_fdmi_attr_entry *ae;
2028 uint32_t size;
2029
2030 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2031 memset(ae, 0, sizeof(struct lpfc_name));
2032
2033 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2034 sizeof(struct lpfc_name));
2035 size = FOURBYTES + sizeof(struct lpfc_name);
2036 ad->AttrLen = cpu_to_be16(size);
2037 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2038 return size;
2039}
2040
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002041static int
James Smart4258e982015-12-16 18:11:58 -05002042lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2043 struct lpfc_fdmi_attr_def *ad)
2044{
2045 struct lpfc_hba *phba = vport->phba;
2046 struct lpfc_fdmi_attr_entry *ae;
2047 uint32_t len, size;
2048
2049 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2050 memset(ae, 0, 256);
2051
2052 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2053 len = strnlen(ae->un.AttrString,
2054 sizeof(ae->un.AttrString));
2055 len += (len & 3) ? (4 - (len & 3)) : 4;
2056 size = FOURBYTES + len;
2057 ad->AttrLen = cpu_to_be16(size);
2058 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2059 return size;
2060}
2061
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002062static int
James Smart4258e982015-12-16 18:11:58 -05002063lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2064 struct lpfc_fdmi_attr_def *ad)
2065{
2066 struct lpfc_fdmi_attr_entry *ae;
2067 uint32_t size;
2068
2069 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2070
2071 /* Driver doesn't have access to this information */
2072 ae->un.AttrInt = cpu_to_be32(0);
2073 size = FOURBYTES + sizeof(uint32_t);
2074 ad->AttrLen = cpu_to_be16(size);
2075 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2076 return size;
2077}
2078
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002079static int
James Smart4258e982015-12-16 18:11:58 -05002080lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2081 struct lpfc_fdmi_attr_def *ad)
2082{
2083 struct lpfc_fdmi_attr_entry *ae;
2084 uint32_t len, size;
2085
2086 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2087 memset(ae, 0, 256);
2088
2089 strncpy(ae->un.AttrString, "EMULEX",
2090 sizeof(ae->un.AttrString));
2091 len = strnlen(ae->un.AttrString,
2092 sizeof(ae->un.AttrString));
2093 len += (len & 3) ? (4 - (len & 3)) : 4;
2094 size = FOURBYTES + len;
2095 ad->AttrLen = cpu_to_be16(size);
2096 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2097 return size;
2098}
2099
2100/* Routines for all individual PORT attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002101static int
James Smart4258e982015-12-16 18:11:58 -05002102lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2103 struct lpfc_fdmi_attr_def *ad)
2104{
2105 struct lpfc_fdmi_attr_entry *ae;
2106 uint32_t size;
2107
2108 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2109 memset(ae, 0, 32);
2110
2111 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2112 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
James Smart82820f02017-05-15 15:20:47 -07002113 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
James Smart4258e982015-12-16 18:11:58 -05002114 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2115 size = FOURBYTES + 32;
2116 ad->AttrLen = cpu_to_be16(size);
2117 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2118 return size;
2119}
2120
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002121static int
James Smart4258e982015-12-16 18:11:58 -05002122lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2123 struct lpfc_fdmi_attr_def *ad)
2124{
2125 struct lpfc_hba *phba = vport->phba;
2126 struct lpfc_fdmi_attr_entry *ae;
2127 uint32_t size;
2128
2129 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2130
2131 ae->un.AttrInt = 0;
James Smarta085e872015-12-16 18:12:02 -05002132 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smartfbd8a6b2018-02-22 08:18:45 -08002133 if (phba->lmt & LMT_64Gb)
2134 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
James Smarta085e872015-12-16 18:12:02 -05002135 if (phba->lmt & LMT_32Gb)
2136 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2137 if (phba->lmt & LMT_16Gb)
2138 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2139 if (phba->lmt & LMT_10Gb)
2140 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2141 if (phba->lmt & LMT_8Gb)
2142 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2143 if (phba->lmt & LMT_4Gb)
2144 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2145 if (phba->lmt & LMT_2Gb)
2146 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2147 if (phba->lmt & LMT_1Gb)
2148 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2149 } else {
2150 /* FCoE links support only one speed */
2151 switch (phba->fc_linkspeed) {
2152 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2153 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2154 break;
2155 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2156 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2157 break;
2158 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2159 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2160 break;
2161 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2162 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2163 break;
2164 }
2165 }
James Smart4258e982015-12-16 18:11:58 -05002166 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2167 size = FOURBYTES + sizeof(uint32_t);
2168 ad->AttrLen = cpu_to_be16(size);
2169 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2170 return size;
2171}
2172
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002173static int
James Smart4258e982015-12-16 18:11:58 -05002174lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2175 struct lpfc_fdmi_attr_def *ad)
2176{
2177 struct lpfc_hba *phba = vport->phba;
2178 struct lpfc_fdmi_attr_entry *ae;
2179 uint32_t size;
2180
2181 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2182
James Smarta085e872015-12-16 18:12:02 -05002183 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2184 switch (phba->fc_linkspeed) {
2185 case LPFC_LINK_SPEED_1GHZ:
2186 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2187 break;
2188 case LPFC_LINK_SPEED_2GHZ:
2189 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2190 break;
2191 case LPFC_LINK_SPEED_4GHZ:
2192 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2193 break;
2194 case LPFC_LINK_SPEED_8GHZ:
2195 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2196 break;
2197 case LPFC_LINK_SPEED_10GHZ:
2198 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2199 break;
2200 case LPFC_LINK_SPEED_16GHZ:
2201 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2202 break;
2203 case LPFC_LINK_SPEED_32GHZ:
2204 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2205 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08002206 case LPFC_LINK_SPEED_64GHZ:
2207 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2208 break;
James Smarta085e872015-12-16 18:12:02 -05002209 default:
2210 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2211 break;
2212 }
2213 } else {
2214 switch (phba->fc_linkspeed) {
2215 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2216 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2217 break;
2218 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2219 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2220 break;
2221 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2222 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2223 break;
2224 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2225 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2226 break;
2227 default:
2228 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2229 break;
2230 }
James Smart4258e982015-12-16 18:11:58 -05002231 }
James Smarta085e872015-12-16 18:12:02 -05002232
James Smart4258e982015-12-16 18:11:58 -05002233 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2234 size = FOURBYTES + sizeof(uint32_t);
2235 ad->AttrLen = cpu_to_be16(size);
2236 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2237 return size;
2238}
2239
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002240static int
James Smart4258e982015-12-16 18:11:58 -05002241lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2242 struct lpfc_fdmi_attr_def *ad)
2243{
2244 struct serv_parm *hsp;
2245 struct lpfc_fdmi_attr_entry *ae;
2246 uint32_t size;
2247
2248 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2249
2250 hsp = (struct serv_parm *)&vport->fc_sparam;
2251 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2252 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2253 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2254 size = FOURBYTES + sizeof(uint32_t);
2255 ad->AttrLen = cpu_to_be16(size);
2256 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2257 return size;
2258}
2259
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002260static int
James Smart4258e982015-12-16 18:11:58 -05002261lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2262 struct lpfc_fdmi_attr_def *ad)
2263{
2264 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2265 struct lpfc_fdmi_attr_entry *ae;
2266 uint32_t len, size;
2267
2268 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2269 memset(ae, 0, 256);
2270
2271 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2272 "/sys/class/scsi_host/host%d", shost->host_no);
2273 len = strnlen((char *)ae->un.AttrString,
2274 sizeof(ae->un.AttrString));
2275 len += (len & 3) ? (4 - (len & 3)) : 4;
2276 size = FOURBYTES + len;
2277 ad->AttrLen = cpu_to_be16(size);
2278 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2279 return size;
2280}
2281
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002282static int
James Smart4258e982015-12-16 18:11:58 -05002283lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2284 struct lpfc_fdmi_attr_def *ad)
2285{
2286 struct lpfc_fdmi_attr_entry *ae;
2287 uint32_t len, size;
2288
2289 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2290 memset(ae, 0, 256);
2291
2292 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2293 init_utsname()->nodename);
2294
2295 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2296 len += (len & 3) ? (4 - (len & 3)) : 4;
2297 size = FOURBYTES + len;
2298 ad->AttrLen = cpu_to_be16(size);
2299 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2300 return size;
2301}
2302
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002303static int
James Smart4258e982015-12-16 18:11:58 -05002304lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2305 struct lpfc_fdmi_attr_def *ad)
2306{
2307 struct lpfc_fdmi_attr_entry *ae;
2308 uint32_t size;
2309
2310 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2311 memset(ae, 0, sizeof(struct lpfc_name));
2312
2313 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2314 sizeof(struct lpfc_name));
2315 size = FOURBYTES + sizeof(struct lpfc_name);
2316 ad->AttrLen = cpu_to_be16(size);
2317 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2318 return size;
2319}
2320
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002321static int
James Smart4258e982015-12-16 18:11:58 -05002322lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2323 struct lpfc_fdmi_attr_def *ad)
2324{
2325 struct lpfc_fdmi_attr_entry *ae;
2326 uint32_t size;
2327
2328 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2329 memset(ae, 0, sizeof(struct lpfc_name));
2330
2331 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2332 sizeof(struct lpfc_name));
2333 size = FOURBYTES + sizeof(struct lpfc_name);
2334 ad->AttrLen = cpu_to_be16(size);
2335 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2336 return size;
2337}
2338
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002339static int
James Smart4258e982015-12-16 18:11:58 -05002340lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2341 struct lpfc_fdmi_attr_def *ad)
2342{
2343 struct lpfc_fdmi_attr_entry *ae;
2344 uint32_t len, size;
2345
2346 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2347 memset(ae, 0, 256);
2348
2349 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2350 len += (len & 3) ? (4 - (len & 3)) : 4;
2351 size = FOURBYTES + len;
2352 ad->AttrLen = cpu_to_be16(size);
2353 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2354 return size;
2355}
2356
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002357static int
James Smart4258e982015-12-16 18:11:58 -05002358lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2359 struct lpfc_fdmi_attr_def *ad)
2360{
2361 struct lpfc_hba *phba = vport->phba;
2362 struct lpfc_fdmi_attr_entry *ae;
2363 uint32_t size;
2364
2365 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2366 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2367 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2368 else
2369 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2370 size = FOURBYTES + sizeof(uint32_t);
2371 ad->AttrLen = cpu_to_be16(size);
2372 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2373 return size;
2374}
2375
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002376static int
James Smart4258e982015-12-16 18:11:58 -05002377lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2378 struct lpfc_fdmi_attr_def *ad)
2379{
2380 struct lpfc_fdmi_attr_entry *ae;
2381 uint32_t size;
2382
2383 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2384 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2385 size = FOURBYTES + sizeof(uint32_t);
2386 ad->AttrLen = cpu_to_be16(size);
2387 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2388 return size;
2389}
2390
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002391static int
James Smart4258e982015-12-16 18:11:58 -05002392lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2393 struct lpfc_fdmi_attr_def *ad)
2394{
2395 struct lpfc_fdmi_attr_entry *ae;
2396 uint32_t size;
2397
2398 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2399 memset(ae, 0, sizeof(struct lpfc_name));
2400
2401 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2402 sizeof(struct lpfc_name));
2403 size = FOURBYTES + sizeof(struct lpfc_name);
2404 ad->AttrLen = cpu_to_be16(size);
2405 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2406 return size;
2407}
2408
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002409static int
James Smart4258e982015-12-16 18:11:58 -05002410lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2411 struct lpfc_fdmi_attr_def *ad)
2412{
2413 struct lpfc_fdmi_attr_entry *ae;
2414 uint32_t size;
2415
2416 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2417 memset(ae, 0, 32);
2418
2419 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2420 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2421 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2422 size = FOURBYTES + 32;
2423 ad->AttrLen = cpu_to_be16(size);
2424 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2425 return size;
2426}
2427
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002428static int
James Smart4258e982015-12-16 18:11:58 -05002429lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2430 struct lpfc_fdmi_attr_def *ad)
2431{
2432 struct lpfc_fdmi_attr_entry *ae;
2433 uint32_t size;
2434
2435 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2436 /* Link Up - operational */
2437 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2438 size = FOURBYTES + sizeof(uint32_t);
2439 ad->AttrLen = cpu_to_be16(size);
2440 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2441 return size;
2442}
2443
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002444static int
James Smart4258e982015-12-16 18:11:58 -05002445lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2446 struct lpfc_fdmi_attr_def *ad)
2447{
2448 struct lpfc_fdmi_attr_entry *ae;
2449 uint32_t size;
2450
2451 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2452 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2453 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2454 size = FOURBYTES + sizeof(uint32_t);
2455 ad->AttrLen = cpu_to_be16(size);
2456 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2457 return size;
2458}
2459
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002460static int
James Smart4258e982015-12-16 18:11:58 -05002461lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2462 struct lpfc_fdmi_attr_def *ad)
2463{
2464 struct lpfc_fdmi_attr_entry *ae;
2465 uint32_t size;
2466
2467 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2468 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2469 size = FOURBYTES + sizeof(uint32_t);
2470 ad->AttrLen = cpu_to_be16(size);
2471 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2472 return size;
2473}
2474
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002475static int
James Smart4258e982015-12-16 18:11:58 -05002476lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2477 struct lpfc_fdmi_attr_def *ad)
2478{
2479 struct lpfc_fdmi_attr_entry *ae;
2480 uint32_t len, size;
2481
2482 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2483 memset(ae, 0, 256);
2484
2485 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2486 sizeof(ae->un.AttrString));
2487 len = strnlen(ae->un.AttrString,
2488 sizeof(ae->un.AttrString));
2489 len += (len & 3) ? (4 - (len & 3)) : 4;
2490 size = FOURBYTES + len;
2491 ad->AttrLen = cpu_to_be16(size);
2492 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2493 return size;
2494}
2495
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002496static int
James Smart4258e982015-12-16 18:11:58 -05002497lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2498 struct lpfc_fdmi_attr_def *ad)
2499{
2500 struct lpfc_fdmi_attr_entry *ae;
2501 uint32_t size;
2502
2503 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2504 memset(ae, 0, 256);
2505
2506 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2507 sizeof(struct lpfc_name));
2508 memcpy((((uint8_t *)&ae->un.AttrString) +
2509 sizeof(struct lpfc_name)),
2510 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2511 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2512 ad->AttrLen = cpu_to_be16(size);
2513 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2514 return size;
2515}
2516
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002517static int
James Smart4258e982015-12-16 18:11:58 -05002518lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2519 struct lpfc_fdmi_attr_def *ad)
2520{
2521 struct lpfc_fdmi_attr_entry *ae;
2522 uint32_t len, size;
2523
2524 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2525 memset(ae, 0, 256);
2526
James Smart56204982016-03-31 14:12:32 -07002527 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
James Smart4258e982015-12-16 18:11:58 -05002528 sizeof(ae->un.AttrString));
2529 len = strnlen(ae->un.AttrString,
2530 sizeof(ae->un.AttrString));
2531 len += (len & 3) ? (4 - (len & 3)) : 4;
2532 size = FOURBYTES + len;
2533 ad->AttrLen = cpu_to_be16(size);
2534 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2535 return size;
2536}
2537
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002538static int
James Smart4258e982015-12-16 18:11:58 -05002539lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2540 struct lpfc_fdmi_attr_def *ad)
2541{
2542 struct lpfc_hba *phba = vport->phba;
2543 struct lpfc_fdmi_attr_entry *ae;
2544 uint32_t len, size;
2545
2546 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2547 memset(ae, 0, 256);
2548
2549 strncpy(ae->un.AttrString, phba->ModelName,
2550 sizeof(ae->un.AttrString));
2551 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2552 len += (len & 3) ? (4 - (len & 3)) : 4;
2553 size = FOURBYTES + len;
2554 ad->AttrLen = cpu_to_be16(size);
2555 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2556 return size;
2557}
2558
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002559static int
James Smart4258e982015-12-16 18:11:58 -05002560lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2561 struct lpfc_fdmi_attr_def *ad)
2562{
2563 struct lpfc_fdmi_attr_entry *ae;
2564 uint32_t size;
2565
2566 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2567
2568 /* SRIOV (type 3) is not supported */
2569 if (vport->vpi)
2570 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2571 else
2572 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2573 size = FOURBYTES + sizeof(uint32_t);
2574 ad->AttrLen = cpu_to_be16(size);
2575 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2576 return size;
2577}
2578
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002579static int
James Smart4258e982015-12-16 18:11:58 -05002580lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2581 struct lpfc_fdmi_attr_def *ad)
2582{
2583 struct lpfc_fdmi_attr_entry *ae;
2584 uint32_t size;
2585
2586 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2587 ae->un.AttrInt = cpu_to_be32(0);
2588 size = FOURBYTES + sizeof(uint32_t);
2589 ad->AttrLen = cpu_to_be16(size);
2590 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2591 return size;
2592}
2593
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002594static int
James Smart4258e982015-12-16 18:11:58 -05002595lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2596 struct lpfc_fdmi_attr_def *ad)
2597{
2598 struct lpfc_fdmi_attr_entry *ae;
2599 uint32_t size;
2600
2601 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
James Smart56204982016-03-31 14:12:32 -07002602 ae->un.AttrInt = cpu_to_be32(1);
James Smart4258e982015-12-16 18:11:58 -05002603 size = FOURBYTES + sizeof(uint32_t);
2604 ad->AttrLen = cpu_to_be16(size);
2605 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2606 return size;
2607}
2608
2609/* RHBA attribute jump table */
2610int (*lpfc_fdmi_hba_action[])
2611 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2612 /* Action routine Mask bit Attribute type */
2613 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2614 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2615 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2616 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2617 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2618 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2619 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2620 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2621 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2622 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2623 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2624 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2625 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2626 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2627 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2628 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2629 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2630 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2631};
2632
2633/* RPA / RPRT attribute jump table */
2634int (*lpfc_fdmi_port_action[])
2635 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2636 /* Action routine Mask bit Attribute type */
2637 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2638 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2639 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2640 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2641 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2642 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2643 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2644 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2645 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2646 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2647 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2648 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2649 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2650 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2651 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2652 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2653 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2654 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2655 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2656 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2657 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2658 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2659 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2660};
2661
2662/**
2663 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2664 * @vport: pointer to a host virtual N_Port data structure.
2665 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2666 * cmdcode: FDMI command to send
2667 * mask: Mask of HBA or PORT Attributes to send
2668 *
2669 * Builds and sends a FDMI command using the CT subsystem.
2670 */
2671int
2672lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2673 int cmdcode, uint32_t new_mask)
dea31012005-04-17 16:05:31 -05002674{
James Smart2e0fef82007-06-17 19:56:36 -05002675 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002676 struct lpfc_dmabuf *mp, *bmp;
2677 struct lpfc_sli_ct_request *CtReq;
2678 struct ulp_bde64 *bpl;
James Smart4258e982015-12-16 18:11:58 -05002679 uint32_t bit_pos;
dea31012005-04-17 16:05:31 -05002680 uint32_t size;
James Smart76b2c342015-04-07 15:07:19 -04002681 uint32_t rsp_size;
James Smart4258e982015-12-16 18:11:58 -05002682 uint32_t mask;
James Smart76b2c342015-04-07 15:07:19 -04002683 struct lpfc_fdmi_reg_hba *rh;
2684 struct lpfc_fdmi_port_entry *pe;
2685 struct lpfc_fdmi_reg_portattr *pab = NULL;
2686 struct lpfc_fdmi_attr_block *ab = NULL;
James Smart4258e982015-12-16 18:11:58 -05002687 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2688 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2689 struct lpfc_iocbq *);
dea31012005-04-17 16:05:31 -05002690
James Smart4258e982015-12-16 18:11:58 -05002691 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2692 return 0;
2693
2694 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
dea31012005-04-17 16:05:31 -05002695
2696 /* fill in BDEs for command */
2697 /* Allocate buffer for command payload */
James Smart76b2c342015-04-07 15:07:19 -04002698 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002699 if (!mp)
2700 goto fdmi_cmd_exit;
2701
2702 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2703 if (!mp->virt)
2704 goto fdmi_cmd_free_mp;
2705
2706 /* Allocate buffer for Buffer ptr list */
James Smart76b2c342015-04-07 15:07:19 -04002707 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002708 if (!bmp)
2709 goto fdmi_cmd_free_mpvirt;
2710
2711 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2712 if (!bmp->virt)
2713 goto fdmi_cmd_free_bmp;
2714
2715 INIT_LIST_HEAD(&mp->list);
2716 INIT_LIST_HEAD(&bmp->list);
2717
2718 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04002719 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2720 "0218 FDMI Request Data: x%x x%x x%x\n",
2721 vport->fc_flag, vport->port_state, cmdcode);
James Smart76b2c342015-04-07 15:07:19 -04002722 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
dea31012005-04-17 16:05:31 -05002723
James Smart76b2c342015-04-07 15:07:19 -04002724 /* First populate the CT_IU preamble */
dea31012005-04-17 16:05:31 -05002725 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2726 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2727 CtReq->RevisionId.bits.InId = 0;
2728
2729 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2730 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
James Smart76b2c342015-04-07 15:07:19 -04002731
2732 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2733 rsp_size = LPFC_BPL_SIZE;
dea31012005-04-17 16:05:31 -05002734 size = 0;
2735
James Smart76b2c342015-04-07 15:07:19 -04002736 /* Next fill in the specific FDMI cmd information */
dea31012005-04-17 16:05:31 -05002737 switch (cmdcode) {
James Smart76b2c342015-04-07 15:07:19 -04002738 case SLI_MGMT_RHAT:
dea31012005-04-17 16:05:31 -05002739 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05002740 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2741 /* HBA Identifier */
2742 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2743 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002744
James Smart4258e982015-12-16 18:11:58 -05002745 if (cmdcode == SLI_MGMT_RHBA) {
2746 /* Registered Port List */
2747 /* One entry (port) per adapter */
2748 rh->rpl.EntryCnt = cpu_to_be32(1);
2749 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002750 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002751
James Smart4258e982015-12-16 18:11:58 -05002752 /* point to the HBA attribute block */
2753 size = 2 * sizeof(struct lpfc_name) +
2754 FOURBYTES;
2755 } else {
2756 size = sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002757 }
James Smart4258e982015-12-16 18:11:58 -05002758 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2759 ab->EntryCnt = 0;
2760 size += FOURBYTES;
2761 bit_pos = 0;
2762 if (new_mask)
2763 mask = new_mask;
2764 else
2765 mask = vport->fdmi_hba_mask;
2766
2767 /* Mask will dictate what attributes to build in the request */
2768 while (mask) {
2769 if (mask & 0x1) {
2770 func = lpfc_fdmi_hba_action[bit_pos];
2771 size += func(vport,
2772 (struct lpfc_fdmi_attr_def *)
2773 ((uint8_t *)rh + size));
2774 ab->EntryCnt++;
2775 if ((size + 256) >
2776 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2777 goto hba_out;
2778 }
2779 mask = mask >> 1;
2780 bit_pos++;
2781 }
2782hba_out:
2783 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2784 /* Total size */
2785 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002786 break;
2787
James Smart76b2c342015-04-07 15:07:19 -04002788 case SLI_MGMT_RPRT:
dea31012005-04-17 16:05:31 -05002789 case SLI_MGMT_RPA:
James Smart4258e982015-12-16 18:11:58 -05002790 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2791 if (cmdcode == SLI_MGMT_RPRT) {
2792 rh = (struct lpfc_fdmi_reg_hba *)pab;
2793 /* HBA Identifier */
2794 memcpy(&rh->hi.PortName,
2795 &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002796 sizeof(struct lpfc_name));
James Smart4258e982015-12-16 18:11:58 -05002797 pab = (struct lpfc_fdmi_reg_portattr *)
2798 ((uint8_t *)pab + sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002799 }
James Smart4258e982015-12-16 18:11:58 -05002800
2801 memcpy((uint8_t *)&pab->PortName,
2802 (uint8_t *)&vport->fc_sparam.portName,
2803 sizeof(struct lpfc_name));
2804 size += sizeof(struct lpfc_name) + FOURBYTES;
2805 pab->ab.EntryCnt = 0;
2806 bit_pos = 0;
2807 if (new_mask)
2808 mask = new_mask;
2809 else
2810 mask = vport->fdmi_port_mask;
2811
2812 /* Mask will dictate what attributes to build in the request */
2813 while (mask) {
2814 if (mask & 0x1) {
2815 func = lpfc_fdmi_port_action[bit_pos];
2816 size += func(vport,
2817 (struct lpfc_fdmi_attr_def *)
2818 ((uint8_t *)pab + size));
2819 pab->ab.EntryCnt++;
2820 if ((size + 256) >
2821 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2822 goto port_out;
2823 }
2824 mask = mask >> 1;
2825 bit_pos++;
2826 }
2827port_out:
2828 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2829 /* Total size */
2830 if (cmdcode == SLI_MGMT_RPRT)
2831 size += sizeof(struct lpfc_name);
2832 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002833 break;
2834
James Smart76b2c342015-04-07 15:07:19 -04002835 case SLI_MGMT_GHAT:
2836 case SLI_MGMT_GRPL:
2837 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002838 case SLI_MGMT_DHBA:
James Smart76b2c342015-04-07 15:07:19 -04002839 case SLI_MGMT_DHAT:
2840 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2841 memcpy((uint8_t *)&pe->PortName,
2842 (uint8_t *)&vport->fc_sparam.portName,
2843 sizeof(struct lpfc_name));
2844 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002845 break;
2846
James Smart76b2c342015-04-07 15:07:19 -04002847 case SLI_MGMT_GPAT:
2848 case SLI_MGMT_GPAS:
2849 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002850 case SLI_MGMT_DPRT:
James Smart76b2c342015-04-07 15:07:19 -04002851 case SLI_MGMT_DPA:
2852 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2853 memcpy((uint8_t *)&pe->PortName,
2854 (uint8_t *)&vport->fc_sparam.portName,
2855 sizeof(struct lpfc_name));
2856 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002857 break;
James Smart76b2c342015-04-07 15:07:19 -04002858 case SLI_MGMT_GRHL:
2859 size = GID_REQUEST_SZ - 4;
2860 break;
2861 default:
2862 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2863 "0298 FDMI cmdcode x%x not supported\n",
2864 cmdcode);
2865 goto fdmi_cmd_free_bmpvirt;
dea31012005-04-17 16:05:31 -05002866 }
James Smart76b2c342015-04-07 15:07:19 -04002867 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
dea31012005-04-17 16:05:31 -05002868
James Smart76b2c342015-04-07 15:07:19 -04002869 bpl = (struct ulp_bde64 *)bmp->virt;
2870 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2871 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
dea31012005-04-17 16:05:31 -05002872 bpl->tus.f.bdeFlags = 0;
2873 bpl->tus.f.bdeSize = size;
dea31012005-04-17 16:05:31 -05002874
James Smart76b2c342015-04-07 15:07:19 -04002875 /*
2876 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
James Smarte47c9092008-02-08 18:49:26 -05002877 * to hold ndlp reference for the corresponding callback function.
2878 */
James Smart76b2c342015-04-07 15:07:19 -04002879 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
dea31012005-04-17 16:05:31 -05002880 return 0;
2881
James Smart76b2c342015-04-07 15:07:19 -04002882 /*
2883 * Decrement ndlp reference count to release ndlp reference held
James Smarte47c9092008-02-08 18:49:26 -05002884 * for the failed command's callback function.
2885 */
James Smart51ef4c22007-08-02 11:10:31 -04002886 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002887
James Smart76b2c342015-04-07 15:07:19 -04002888fdmi_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05002889 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2890fdmi_cmd_free_bmp:
2891 kfree(bmp);
2892fdmi_cmd_free_mpvirt:
2893 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2894fdmi_cmd_free_mp:
2895 kfree(mp);
2896fdmi_cmd_exit:
2897 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04002898 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2899 "0244 Issue FDMI request failed Data: x%x\n",
2900 cmdcode);
dea31012005-04-17 16:05:31 -05002901 return 1;
2902}
2903
James Smart92494142011-02-16 12:39:44 -05002904/**
2905 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2906 * @ptr - Context object of the timer.
2907 *
2908 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2909 * the worker thread.
2910 **/
2911void
Kees Cookf22eb4d2017-09-06 20:24:26 -07002912lpfc_delayed_disc_tmo(struct timer_list *t)
James Smart92494142011-02-16 12:39:44 -05002913{
Kees Cookf22eb4d2017-09-06 20:24:26 -07002914 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
James Smart92494142011-02-16 12:39:44 -05002915 struct lpfc_hba *phba = vport->phba;
2916 uint32_t tmo_posted;
2917 unsigned long iflag;
2918
2919 spin_lock_irqsave(&vport->work_port_lock, iflag);
2920 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2921 if (!tmo_posted)
2922 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2923 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2924
2925 if (!tmo_posted)
2926 lpfc_worker_wake_up(phba);
2927 return;
2928}
2929
2930/**
2931 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2932 * handle delayed discovery.
2933 * @vport: pointer to a host virtual N_Port data structure.
2934 *
2935 * This function start nport discovery of the vport.
2936 **/
2937void
2938lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2939{
2940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2941
2942 spin_lock_irq(shost->host_lock);
2943 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2944 spin_unlock_irq(shost->host_lock);
2945 return;
2946 }
2947 vport->fc_flag &= ~FC_DISC_DELAYED;
2948 spin_unlock_irq(shost->host_lock);
2949
2950 lpfc_do_scr_ns_plogi(vport->phba, vport);
2951}
2952
dea31012005-04-17 16:05:31 -05002953void
James Smart2e0fef82007-06-17 19:56:36 -05002954lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05002955{
2956 struct lpfc_sli *psli = &phba->sli;
2957 lpfc_vpd_t *vp = &phba->vpd;
2958 uint32_t b1, b2, b3, b4, i, rev;
2959 char c;
2960 uint32_t *ptr, str[4];
2961 uint8_t *fwname;
2962
James Smartf1126682009-06-10 17:22:44 -04002963 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart6b5151f2012-01-18 16:24:06 -05002964 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
James Smartf1126682009-06-10 17:22:44 -04002965 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04002966 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002967 rev = vp->rev.sli2FwRev;
2968 else
2969 rev = vp->rev.sli1FwRev;
2970
2971 b1 = (rev & 0x0000f000) >> 12;
2972 b2 = (rev & 0x00000f00) >> 8;
2973 b3 = (rev & 0x000000c0) >> 6;
2974 b4 = (rev & 0x00000030) >> 4;
2975
2976 switch (b4) {
2977 case 0:
2978 c = 'N';
2979 break;
2980 case 1:
2981 c = 'A';
2982 break;
2983 case 2:
2984 c = 'B';
2985 break;
James Smart73d91e52011-10-10 21:32:10 -04002986 case 3:
2987 c = 'X';
2988 break;
dea31012005-04-17 16:05:31 -05002989 default:
2990 c = 0;
2991 break;
2992 }
2993 b4 = (rev & 0x0000000f);
2994
James Smartf4b4c682009-05-22 14:53:12 -04002995 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002996 fwname = vp->rev.sli2FwName;
2997 else
2998 fwname = vp->rev.sli1FwName;
2999
3000 for (i = 0; i < 16; i++)
3001 if (fwname[i] == 0x20)
3002 fwname[i] = 0;
3003
3004 ptr = (uint32_t*)fwname;
3005
3006 for (i = 0; i < 3; i++)
3007 str[i] = be32_to_cpu(*ptr++);
3008
3009 if (c == 0) {
3010 if (flag)
3011 sprintf(fwrevision, "%d.%d%d (%s)",
3012 b1, b2, b3, (char *)str);
3013 else
3014 sprintf(fwrevision, "%d.%d%d", b1,
3015 b2, b3);
3016 } else {
3017 if (flag)
3018 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3019 b1, b2, b3, c,
3020 b4, (char *)str);
3021 else
3022 sprintf(fwrevision, "%d.%d%d%c%d",
3023 b1, b2, b3, c, b4);
3024 }
3025 } else {
3026 rev = vp->rev.smFwRev;
3027
3028 b1 = (rev & 0xff000000) >> 24;
3029 b2 = (rev & 0x00f00000) >> 20;
3030 b3 = (rev & 0x000f0000) >> 16;
3031 c = (rev & 0x0000ff00) >> 8;
3032 b4 = (rev & 0x000000ff);
3033
Roel Kluind44a6d22010-01-17 16:15:57 +01003034 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05003035 }
3036 return;
3037}