blob: f77673ab4a8445b8a3ec34816c21727c1b0804f1 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
dea31012005-04-17 16:05:31 -05009 * *
10 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
dea31012005-04-17 16:05:31 -050021 *******************************************************************/
22
23/*
James Smart09372822008-01-11 01:52:54 -050024 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea31012005-04-17 16:05:31 -050025 */
26
27#include <linux/blkdev.h>
28#include <linux/pci.h>
29#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050031#include <linux/utsname.h>
32
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040036#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040037#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050038
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_hw.h"
41#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040043#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050044#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc.h"
James Smarta0f2d3e2017-02-12 13:52:31 -080046#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
50#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050051#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050052#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050053
James Smarta085e872015-12-16 18:12:02 -050054/* FDMI Port Speed definitions - FC-GS-7 */
55#define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
56#define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
57#define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
58#define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
59#define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
60#define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
61#define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
62#define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
63#define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
64#define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
65#define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
66#define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
67#define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
68#define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
69#define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
70#define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
71#define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
72#define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
73#define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
dea31012005-04-17 16:05:31 -050074
75#define FOURBYTES 4
76
77
78static char *lpfc_release_version = LPFC_DRIVER_VERSION;
79
James Smarted957682007-06-17 19:56:37 -050080static void
81lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050082 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050083{
James Smarted957682007-06-17 19:56:37 -050084 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050085 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040086 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050087 "status = x%x\n",
88 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050089 }
James Smart9c2face2008-01-11 01:53:18 -050090 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
92 "status = x%x\n",
93 size, piocbq->iocb.ulpStatus);
94}
95
96static void
97lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
99{
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -0500101}
102
dea31012005-04-17 16:05:31 -0500103void
James Smart2e0fef82007-06-17 19:56:36 -0500104lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -0500106{
James Smarted957682007-06-17 19:56:37 -0500107 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -0500108 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -0500109 int i;
110 struct lpfc_iocbq *iocbq;
111 dma_addr_t paddr;
112 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -0500113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -0500115
James Smart4fede782010-01-26 23:08:55 -0500116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
117 return;
James Smartf1c3b0f2009-07-19 10:01:32 -0400118
James Smart92d7f7b2007-06-17 19:56:38 -0500119 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
120 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
121 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500124 /* Not enough posted buffers; Try posting more buffers */
125 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400127 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500128 return;
129 }
130
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
133 */
134 if (icmd->ulpBdeCount == 0)
135 return;
136
James Smarted957682007-06-17 19:56:37 -0500137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500141 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500142 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500143 continue;
James Smart9c2face2008-01-11 01:53:18 -0500144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500146 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500149 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500150 bdeBuf = iocbq->context3;
151 iocbq->context3 = NULL;
152 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
153 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
154 size);
155 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500156 }
dea31012005-04-17 16:05:31 -0500157 }
James Smart9c2face2008-01-11 01:53:18 -0500158 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500159 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500163 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500164 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500166 for (i = 0; i < icmd->ulpBdeCount; i++) {
167 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
168 icmd->un.cont64[i].addrLow);
169 mp = lpfc_sli_ringpostbuf_get(phba, pring,
170 paddr);
171 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500173 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500174 }
James Smart495a7142008-06-14 22:52:59 -0400175 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500176 }
James Smartd7c255b2008-08-24 21:50:00 -0400177 list_del(&head);
dea31012005-04-17 16:05:31 -0500178 }
dea31012005-04-17 16:05:31 -0500179}
180
James Smart6669f9b2009-10-02 15:16:45 -0400181/**
James Smart6dd9e312013-01-03 15:43:37 -0500182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
James Smart6669f9b2009-10-02 15:16:45 -0400183 * @phba: Pointer to HBA context object.
James Smart6dd9e312013-01-03 15:43:37 -0500184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
James Smart6669f9b2009-10-02 15:16:45 -0400185 *
James Smart6dd9e312013-01-03 15:43:37 -0500186 * This function serves as the upper level protocol abort handler for CT
187 * protocol.
188 *
189 * Return 1 if abort has been handled, 0 otherwise.
James Smart6669f9b2009-10-02 15:16:45 -0400190 **/
James Smart6dd9e312013-01-03 15:43:37 -0500191int
192lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
James Smart6669f9b2009-10-02 15:16:45 -0400193{
James Smart6dd9e312013-01-03 15:43:37 -0500194 int handled;
James Smart6669f9b2009-10-02 15:16:45 -0400195
James Smart6dd9e312013-01-03 15:43:37 -0500196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
James Smart6669f9b2009-10-02 15:16:45 -0400198
James Smart6dd9e312013-01-03 15:43:37 -0500199 return handled;
James Smart6669f9b2009-10-02 15:16:45 -0400200}
201
dea31012005-04-17 16:05:31 -0500202static void
James Smart2e0fef82007-06-17 19:56:36 -0500203lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500204{
205 struct lpfc_dmabuf *mlast, *next_mlast;
206
207 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
208 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
209 list_del(&mlast->list);
210 kfree(mlast);
211 }
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
213 kfree(mlist);
214 return;
215}
216
217static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500218lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500219 uint32_t size, int *entries)
220{
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
223 int cnt, i = 0;
224
James Smart09372822008-01-11 01:52:54 -0500225 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
227
228 while (size) {
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
231 if (!mp) {
232 if (mlist)
233 lpfc_free_ct_rsp(phba, mlist);
234 return NULL;
235 }
236
237 INIT_LIST_HEAD(&mp->list);
238
James Smart92d7f7b2007-06-17 19:56:38 -0500239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500241 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
242 else
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
244
245 if (!mp->virt) {
246 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700247 if (mlist)
248 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500249 return NULL;
250 }
251
252 /* Queue it to a linked list */
253 if (!mlist)
254 mlist = mp;
255 else
256 list_add_tail(&mp->list, &mlist->list);
257
James Smart34b02dc2008-08-24 21:49:55 -0400258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500259 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500262 bpl->tus.f.bdeSize = (uint16_t) cnt;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264 bpl++;
265
266 i++;
267 size -= cnt;
268 }
269
270 *entries = i;
271 return mlist;
272}
273
James Smart858c9f62007-06-17 19:56:39 -0500274int
275lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
276{
277 struct lpfc_dmabuf *buf_ptr;
278
James Smart51ef4c22007-08-02 11:10:31 -0400279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
282 }
James Smart858c9f62007-06-17 19:56:39 -0500283 if (ctiocb->context1) {
284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
286 kfree(buf_ptr);
287 ctiocb->context1 = NULL;
288 }
289 if (ctiocb->context2) {
290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
291 ctiocb->context2 = NULL;
292 }
293
294 if (ctiocb->context3) {
295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
297 kfree(buf_ptr);
Felipe Pena1109c942013-10-15 21:29:50 -0300298 ctiocb->context3 = NULL;
James Smart858c9f62007-06-17 19:56:39 -0500299 }
300 lpfc_sli_release_iocbq(phba, ctiocb);
301 return 0;
302}
303
James Smart4258e982015-12-16 18:11:58 -0500304/**
305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
306 * @vport: pointer to a host virtual N_Port data structure.
307 * @bmp: Pointer to BPL for SLI command
308 * @inp: Pointer to data buffer for response data.
309 * @outp: Pointer to data buffer that hold the CT command.
310 * @cmpl: completion routine to call when command completes
311 * @ndlp: Destination NPort nodelist entry
312 *
313 * This function as the final part for issuing a CT command.
314 */
dea31012005-04-17 16:05:31 -0500315static int
James Smart2e0fef82007-06-17 19:56:36 -0500316lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500317 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
319 struct lpfc_iocbq *),
320 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500321 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500322{
James Smart2e0fef82007-06-17 19:56:36 -0500323 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500324 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400325 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500326 int rc;
dea31012005-04-17 16:05:31 -0500327
328 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400329 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500330
331 if (geniocb == NULL)
332 return 1;
dea31012005-04-17 16:05:31 -0500333
334 icmd = &geniocb->iocb;
335 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
336 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
337 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart4258e982015-12-16 18:11:58 -0500339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500340
341 if (usr_flg)
342 geniocb->context3 = NULL;
343 else
344 geniocb->context3 = (uint8_t *) bmp;
345
346 /* Save for completion so we can release these resources */
347 geniocb->context1 = (uint8_t *) inp;
348 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500350
351 /* Fill in payload, bp points to frame payload */
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
353
354 /* Fill in rest of iocb */
355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
356 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
James Smart6a9c52c2009-10-02 15:16:51 -0400357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -0500359
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500360 if (!tmo) {
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
363 }
dea31012005-04-17 16:05:31 -0500364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
366 icmd->ulpLe = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -0400369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea31012005-04-17 16:05:31 -0500371
James Smart92d7f7b2007-06-17 19:56:38 -0500372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373 /* For GEN_REQUEST64_CR, use the RPI */
374 icmd->ulpCt_h = 0;
375 icmd->ulpCt_l = 0;
376 }
377
dea31012005-04-17 16:05:31 -0500378 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
380 "0119 Issue GEN REQ IOCB to NPORT x%x "
381 "Data: x%x x%x\n",
382 ndlp->nlp_DID, icmd->ulpIoTag,
383 vport->port_state);
dea31012005-04-17 16:05:31 -0500384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500386 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500387 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500389
390 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500391 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500392 return 1;
393 }
dea31012005-04-17 16:05:31 -0500394
395 return 0;
396}
397
James Smart4258e982015-12-16 18:11:58 -0500398/**
399 * lpfc_ct_cmd - Build and issue a CT command
400 * @vport: pointer to a host virtual N_Port data structure.
401 * @inmp: Pointer to data buffer for response data.
402 * @bmp: Pointer to BPL for SLI command
403 * @ndlp: Destination NPort nodelist entry
404 * @cmpl: completion routine to call when command completes
405 *
406 * This function is called for issuing a CT command.
407 */
dea31012005-04-17 16:05:31 -0500408static int
James Smart2e0fef82007-06-17 19:56:36 -0500409lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500413 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500414{
James Smart2e0fef82007-06-17 19:56:36 -0500415 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
417 struct lpfc_dmabuf *outmp;
418 int cnt = 0, status;
419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
420 CommandResponse.bits.CmdRsp;
421
422 bpl++; /* Skip past ct request */
423
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
426 if (!outmp)
427 return -ENOMEM;
James Smart6a9c52c2009-10-02 15:16:51 -0400428 /*
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
431 * lpfc_alloc_ct_rsp.
432 */
433 cnt += 1;
James Smart2e0fef82007-06-17 19:56:36 -0500434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart6a9c52c2009-10-02 15:16:51 -0400435 cnt, 0, retry);
dea31012005-04-17 16:05:31 -0500436 if (status) {
437 lpfc_free_ct_rsp(phba, outmp);
438 return -ENOMEM;
439 }
440 return 0;
441}
442
James Smart549e55c2007-08-02 11:09:51 -0400443struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500444lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500445 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400446 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500447
James Smart549e55c2007-08-02 11:09:51 -0400448 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500452 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400453 }
James Smart92d7f7b2007-06-17 19:56:38 -0500454 }
James Smart549e55c2007-08-02 11:09:51 -0400455 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500456 return NULL;
457}
458
James Smarta0f2d3e2017-02-12 13:52:31 -0800459static void
460lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
461{
462 struct lpfc_nodelist *ndlp;
463
464 if ((vport->port_type != LPFC_NPIV_PORT) ||
465 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
466
467 ndlp = lpfc_setup_disc_node(vport, Did);
468
469 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smartbd2cdd52017-02-12 13:52:33 -0800470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
471 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
472 Did, ndlp->nlp_flag, vport->fc_flag);
473
James Smarta0f2d3e2017-02-12 13:52:31 -0800474 /* By default, the driver expects to support FCP FC4 */
475 if (fc4_type == FC_TYPE_FCP)
476 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
477
478 if (fc4_type == FC_TYPE_NVME)
479 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
480
481 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
482 "0238 Process x%06x NameServer Rsp "
483 "Data: x%x x%x x%x x%x\n", Did,
484 ndlp->nlp_flag, ndlp->nlp_fc4_type,
485 vport->fc_flag,
486 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800487 } else {
488 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
489 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
490 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
491
James Smarta0f2d3e2017-02-12 13:52:31 -0800492 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
493 "0239 Skip x%06x NameServer Rsp "
494 "Data: x%x x%x\n", Did,
495 vport->fc_flag,
496 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800497 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800498 } else {
499 if (!(vport->fc_flag & FC_RSCN_MODE) ||
500 lpfc_rscn_payload_check(vport, Did)) {
James Smartbd2cdd52017-02-12 13:52:33 -0800501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
502 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
503 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
504
James Smarta0f2d3e2017-02-12 13:52:31 -0800505 /*
James Smartb57ab7462017-06-01 21:07:08 -0700506 * This NPortID was previously a FCP/NVMe target,
James Smarta0f2d3e2017-02-12 13:52:31 -0800507 * Don't even bother to send GFF_ID.
508 */
509 ndlp = lpfc_findnode_did(vport, Did);
James Smartb57ab7462017-06-01 21:07:08 -0700510 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
511 (ndlp->nlp_type &
512 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
513 if (fc4_type == FC_TYPE_FCP)
514 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
515 if (fc4_type == FC_TYPE_NVME)
516 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
517 lpfc_setup_disc_node(vport, Did);
518 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
519 0, Did) == 0)
520 vport->num_disc_nodes++;
521 else
522 lpfc_setup_disc_node(vport, Did);
James Smartbd2cdd52017-02-12 13:52:33 -0800523 } else {
524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
525 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
526 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
527
James Smarta0f2d3e2017-02-12 13:52:31 -0800528 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
529 "0245 Skip x%06x NameServer Rsp "
530 "Data: x%x x%x\n", Did,
531 vport->fc_flag,
532 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800533 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800534 }
535}
536
James Smart1c5b12f2017-04-21 16:05:03 -0700537static void
538lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
539{
540 struct lpfc_hba *phba = vport->phba;
541 struct lpfc_nodelist *ndlp = NULL;
542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
543
544 /*
545 * To conserve rpi's, filter out addresses for other
546 * vports on the same physical HBAs.
547 */
548 if (Did != vport->fc_myDID &&
549 (!lpfc_find_vport_by_did(phba, Did) ||
550 vport->cfg_peer_port_login)) {
551 if (!phba->nvmet_support) {
552 /* FCPI/NVMEI path. Process Did */
553 lpfc_prep_node_fc4type(vport, Did, fc4_type);
554 return;
555 }
556 /* NVMET path. NVMET only cares about NVMEI nodes. */
557 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
558 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
559 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
560 continue;
561 spin_lock_irq(shost->host_lock);
562 if (ndlp->nlp_DID == Did)
563 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
564 else
565 ndlp->nlp_flag |= NLP_NVMET_RECOV;
566 spin_unlock_irq(shost->host_lock);
567 }
568 }
569}
570
dea31012005-04-17 16:05:31 -0500571static int
James Smarta0f2d3e2017-02-12 13:52:31 -0800572lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
573 uint32_t Size)
dea31012005-04-17 16:05:31 -0500574{
575 struct lpfc_sli_ct_request *Response =
576 (struct lpfc_sli_ct_request *) mp->virt;
dea31012005-04-17 16:05:31 -0500577 struct lpfc_dmabuf *mlast, *next_mp;
578 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500579 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500580 int Cnt;
581 struct list_head head;
James Smart1c5b12f2017-04-21 16:05:03 -0700582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
583 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -0500584
James Smart2e0fef82007-06-17 19:56:36 -0500585 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500586 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500587 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500588
dea31012005-04-17 16:05:31 -0500589
590 list_add_tail(&head, &mp->list);
591 list_for_each_entry_safe(mp, next_mp, &head, list) {
592 mlast = mp;
593
James Smart7054a602007-04-25 09:52:34 -0400594 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
595
dea31012005-04-17 16:05:31 -0500596 Size -= Cnt;
597
James Smart1dcb58e2007-04-25 09:51:30 -0400598 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500599 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400600 } else
dea31012005-04-17 16:05:31 -0500601 Cnt -= 16; /* subtract length of CT header */
602
603 /* Loop through entire NameServer list of DIDs */
James Smart4258e982015-12-16 18:11:58 -0500604 while (Cnt >= sizeof(uint32_t)) {
dea31012005-04-17 16:05:31 -0500605 /* Get next DID from NameServer List */
606 CTentry = *ctptr++;
607 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart1c5b12f2017-04-21 16:05:03 -0700608 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
James Smart76b2c342015-04-07 15:07:19 -0400609 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
dea31012005-04-17 16:05:31 -0500610 goto nsout1;
James Smarta0f2d3e2017-02-12 13:52:31 -0800611
James Smart4258e982015-12-16 18:11:58 -0500612 Cnt -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -0500613 }
614 ctptr = NULL;
615
616 }
617
James Smart1c5b12f2017-04-21 16:05:03 -0700618 /* All GID_FT entries processed. If the driver is running in
619 * in target mode, put impacted nodes into recovery and drop
620 * the RPI to flush outstanding IO.
621 */
622 if (vport->phba->nvmet_support) {
623 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
624 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
625 continue;
626 lpfc_disc_state_machine(vport, ndlp, NULL,
627 NLP_EVT_DEVICE_RECOVERY);
628 spin_lock_irq(shost->host_lock);
629 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
Dan Carpenter0d618cf2017-05-04 00:22:16 +0300630 spin_unlock_irq(shost->host_lock);
James Smart1c5b12f2017-04-21 16:05:03 -0700631 }
632 }
633
dea31012005-04-17 16:05:31 -0500634nsout1:
635 list_del(&head);
dea31012005-04-17 16:05:31 -0500636 return 0;
637}
638
dea31012005-04-17 16:05:31 -0500639static void
James Smart2e0fef82007-06-17 19:56:36 -0500640lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
641 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500642{
James Smart2e0fef82007-06-17 19:56:36 -0500643 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500645 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500646 struct lpfc_dmabuf *outp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800647 struct lpfc_dmabuf *inp;
dea31012005-04-17 16:05:31 -0500648 struct lpfc_sli_ct_request *CTrsp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800649 struct lpfc_sli_ct_request *CTreq;
James Smart51ef4c22007-08-02 11:10:31 -0400650 struct lpfc_nodelist *ndlp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800651 int rc, type;
dea31012005-04-17 16:05:31 -0500652
James Smart51ef4c22007-08-02 11:10:31 -0400653 /* First save ndlp, before we overwrite it */
654 ndlp = cmdiocb->context_un.ndlp;
655
dea31012005-04-17 16:05:31 -0500656 /* we pass cmdiocb to state machine which needs rspiocb as well */
657 cmdiocb->context_un.rsp_iocb = rspiocb;
James Smarta0f2d3e2017-02-12 13:52:31 -0800658 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -0500659 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
James Smart858c9f62007-06-17 19:56:39 -0500660 irsp = &rspiocb->iocb;
661
662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
663 "GID_FT cmpl: status:x%x/x%x rtry:%d",
664 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500665
James Smart92d7f7b2007-06-17 19:56:38 -0500666 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500667 if (vport->load_flag & FC_UNLOADING) {
668 if (vport->fc_flag & FC_RSCN_MODE)
669 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500670 goto out;
James Smarteada2722008-12-04 22:39:13 -0500671 }
James Smart92d7f7b2007-06-17 19:56:38 -0500672
James Smart58da1ff2008-04-07 10:15:56 -0400673 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400674 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
675 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500676 if (vport->fc_flag & FC_RSCN_MODE)
677 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500678 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
679 goto out;
680 }
James Smart58da1ff2008-04-07 10:15:56 -0400681 if (lpfc_error_lost_link(irsp)) {
682 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
683 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500684 if (vport->fc_flag & FC_RSCN_MODE)
685 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400686 goto out;
687 }
James Smart858c9f62007-06-17 19:56:39 -0500688 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500689 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500690 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400691 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
James Smartedb22f02012-10-31 14:45:21 -0400692 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
James Smarte3d2b802012-08-14 14:25:43 -0400693 IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500694 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500695
James Smarta0f2d3e2017-02-12 13:52:31 -0800696 type = lpfc_get_gidft_type(vport, cmdiocb);
697 if (type == 0)
698 goto out;
699
James Smart58da1ff2008-04-07 10:15:56 -0400700 /* CT command is being retried */
James Smarta0f2d3e2017-02-12 13:52:31 -0800701 vport->gidft_inp--;
James Smart58da1ff2008-04-07 10:15:56 -0400702 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smarta0f2d3e2017-02-12 13:52:31 -0800703 vport->fc_ns_retry, type);
James Smart58da1ff2008-04-07 10:15:56 -0400704 if (rc == 0)
705 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500706 }
James Smarteada2722008-12-04 22:39:13 -0500707 if (vport->fc_flag & FC_RSCN_MODE)
708 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500709 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400710 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
711 "0257 GID_FT Query error: 0x%x 0x%x\n",
712 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500713 } else {
714 /* Good status, continue checking */
James Smarta0f2d3e2017-02-12 13:52:31 -0800715 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
dea31012005-04-17 16:05:31 -0500716 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
717 if (CTrsp->CommandResponse.bits.CmdRsp ==
James Smart76b2c342015-04-07 15:07:19 -0400718 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400719 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800720 "0208 NameServer Rsp Data: x%x x%x\n",
721 vport->fc_flag,
722 CTreq->un.gid.Fc4Type);
723
724 lpfc_ns_rsp(vport,
725 outp,
726 CTreq->un.gid.Fc4Type,
dea31012005-04-17 16:05:31 -0500727 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
728 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
729 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
730 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400731 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
732 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400733 lpfc_printf_vlog(vport, KERN_INFO,
734 LOG_DISCOVERY,
735 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400736 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400737 CTrsp->CommandResponse.bits.CmdRsp,
738 (uint32_t) CTrsp->ReasonCode,
739 (uint32_t) CTrsp->Explanation,
740 vport->fc_flag);
741
742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
743 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
744 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
745 (uint32_t) CTrsp->ReasonCode,
746 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400747 } else {
748 lpfc_printf_vlog(vport, KERN_INFO,
749 LOG_DISCOVERY,
750 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500751 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500752 CTrsp->CommandResponse.bits.CmdRsp,
753 (uint32_t) CTrsp->ReasonCode,
754 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500755 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500756
James Smarta58cbd52007-08-02 11:09:43 -0400757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500758 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
759 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
760 (uint32_t) CTrsp->ReasonCode,
761 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400762 }
763
James Smart858c9f62007-06-17 19:56:39 -0500764
dea31012005-04-17 16:05:31 -0500765 } else {
766 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400767 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
768 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500769 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500770 CTrsp->CommandResponse.bits.CmdRsp,
771 (uint32_t) CTrsp->ReasonCode,
772 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500773 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500774
775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
776 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
777 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
778 (uint32_t) CTrsp->ReasonCode,
779 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500780 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800781 vport->gidft_inp--;
dea31012005-04-17 16:05:31 -0500782 }
783 /* Link up / RSCN discovery */
James Smarta0f2d3e2017-02-12 13:52:31 -0800784 if ((vport->num_disc_nodes == 0) &&
785 (vport->gidft_inp == 0)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500786 /*
787 * The driver has cycled through all Nports in the RSCN payload.
788 * Complete the handling by cleaning up and marking the
789 * current driver state.
790 */
791 if (vport->port_state >= LPFC_DISC_AUTH) {
792 if (vport->fc_flag & FC_RSCN_MODE) {
793 lpfc_els_flush_rscn(vport);
794 spin_lock_irq(shost->host_lock);
795 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
796 spin_unlock_irq(shost->host_lock);
797 }
798 else
799 lpfc_els_flush_rscn(vport);
800 }
801
802 lpfc_disc_start(vport);
803 }
dea31012005-04-17 16:05:31 -0500804out:
James Smart51ef4c22007-08-02 11:10:31 -0400805 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500806 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500807 return;
808}
809
James Smart311464e2007-08-02 11:10:37 -0400810static void
James Smart92d7f7b2007-06-17 19:56:38 -0500811lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
812 struct lpfc_iocbq *rspiocb)
813{
814 struct lpfc_vport *vport = cmdiocb->vport;
815 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
816 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500817 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
818 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
819 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500820 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500821 uint8_t fbits;
822 struct lpfc_nodelist *ndlp;
823
824 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
825 did = be32_to_cpu(did);
826
James Smart858c9f62007-06-17 19:56:39 -0500827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
828 "GFF_ID cmpl: status:x%x/x%x did:x%x",
829 irsp->ulpStatus, irsp->un.ulpWord[4], did);
830
James Smart92d7f7b2007-06-17 19:56:38 -0500831 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
832 /* Good status, continue checking */
833 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
834 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
835
836 if (CTrsp->CommandResponse.bits.CmdRsp ==
837 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
838 if ((fbits & FC4_FEATURE_INIT) &&
839 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400840 lpfc_printf_vlog(vport, KERN_INFO,
841 LOG_DISCOVERY,
842 "0270 Skip x%x GFF "
843 "NameServer Rsp Data: (init) "
844 "x%x x%x\n", did, fbits,
845 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500846 goto out;
847 }
848 }
849 }
James Smart858c9f62007-06-17 19:56:39 -0500850 else {
James Smart0ff10d42008-01-11 01:52:36 -0500851 /* Check for retry */
852 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
853 retry = 1;
854 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
James Smarte3d2b802012-08-14 14:25:43 -0400855 switch ((irsp->un.ulpWord[4] &
856 IOERR_PARAM_MASK)) {
857
James Smart0ff10d42008-01-11 01:52:36 -0500858 case IOERR_NO_RESOURCES:
859 /* We don't increment the retry
860 * count for this case.
861 */
862 break;
863 case IOERR_LINK_DOWN:
864 case IOERR_SLI_ABORTED:
865 case IOERR_SLI_DOWN:
866 retry = 0;
867 break;
868 default:
869 cmdiocb->retry++;
870 }
871 }
872 else
873 cmdiocb->retry++;
874
875 if (retry) {
876 /* CT command is being retried */
877 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
878 cmdiocb->retry, did);
879 if (rc == 0) {
880 /* success */
881 lpfc_ct_free_iocb(phba, cmdiocb);
882 return;
883 }
884 }
885 }
James Smarte8b62012007-08-02 11:10:09 -0400886 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
887 "0267 NameServer GFF Rsp "
888 "x%x Error (%d %d) Data: x%x x%x\n",
889 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500890 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500891 }
892
James Smart92d7f7b2007-06-17 19:56:38 -0500893 /* This is a target port, unregistered port, or the GFF_ID failed */
894 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400895 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400896 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
897 "0242 Process x%x GFF "
898 "NameServer Rsp Data: x%x x%x x%x\n",
899 did, ndlp->nlp_flag, vport->fc_flag,
900 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500901 } else {
James Smarte8b62012007-08-02 11:10:09 -0400902 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
903 "0243 Skip x%x GFF "
904 "NameServer Rsp Data: x%x x%x\n", did,
905 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500906 }
907out:
908 /* Link up / RSCN discovery */
909 if (vport->num_disc_nodes)
910 vport->num_disc_nodes--;
911 if (vport->num_disc_nodes == 0) {
912 /*
913 * The driver has cycled through all Nports in the RSCN payload.
914 * Complete the handling by cleaning up and marking the
915 * current driver state.
916 */
917 if (vport->port_state >= LPFC_DISC_AUTH) {
918 if (vport->fc_flag & FC_RSCN_MODE) {
919 lpfc_els_flush_rscn(vport);
920 spin_lock_irq(shost->host_lock);
921 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
922 spin_unlock_irq(shost->host_lock);
923 }
924 else
925 lpfc_els_flush_rscn(vport);
926 }
927 lpfc_disc_start(vport);
928 }
James Smart858c9f62007-06-17 19:56:39 -0500929 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500930 return;
931}
932
James Smarta0f2d3e2017-02-12 13:52:31 -0800933static void
934lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
935 struct lpfc_iocbq *rspiocb)
936{
937 struct lpfc_vport *vport = cmdiocb->vport;
938 IOCB_t *irsp = &rspiocb->iocb;
939 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
940 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
941 struct lpfc_sli_ct_request *CTrsp;
942 int did;
943 struct lpfc_nodelist *ndlp;
944 uint32_t fc4_data_0, fc4_data_1;
945
946 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
947 did = be32_to_cpu(did);
948
James Smartbd2cdd52017-02-12 13:52:33 -0800949 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
950 "GFT_ID cmpl: status:x%x/x%x did:x%x",
951 irsp->ulpStatus, irsp->un.ulpWord[4], did);
952
James Smarta0f2d3e2017-02-12 13:52:31 -0800953 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
954 /* Good status, continue checking */
955 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
956 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
957 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700958 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800959 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
960 did, fc4_data_0, fc4_data_1);
961
962 ndlp = lpfc_findnode_did(vport, did);
963 if (ndlp) {
964 /* The bitmask value for FCP and NVME FCP types is
965 * the same because they are 32 bits distant from
966 * each other in word0 and word0.
967 */
968 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
969 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
970 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
971 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700972 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800973 "3064 Setting ndlp %p, DID x%06x with "
974 "FC4 x%08x, Data: x%08x x%08x\n",
975 ndlp, did, ndlp->nlp_fc4_type,
976 FC_TYPE_FCP, FC_TYPE_NVME);
James Smartb5ccc7d2017-03-04 09:30:39 -0800977 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
Gustavo A. R. Silvae6ef6a72017-05-23 10:09:28 -0500978
979 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
980 lpfc_issue_els_prli(vport, ndlp, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -0800981 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800982 } else
983 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
984 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
985
986 lpfc_ct_free_iocb(phba, cmdiocb);
987}
James Smart92d7f7b2007-06-17 19:56:38 -0500988
dea31012005-04-17 16:05:31 -0500989static void
James Smart7ee5d432007-10-27 13:37:17 -0400990lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
991 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500992{
James Smart92d7f7b2007-06-17 19:56:38 -0500993 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500994 struct lpfc_dmabuf *inp;
995 struct lpfc_dmabuf *outp;
996 IOCB_t *irsp;
997 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400998 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500999 int cmdcode, rc;
1000 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -05001001 uint32_t latt;
dea31012005-04-17 16:05:31 -05001002
James Smart51ef4c22007-08-02 11:10:31 -04001003 /* First save ndlp, before we overwrite it */
1004 ndlp = cmdiocb->context_un.ndlp;
1005
dea31012005-04-17 16:05:31 -05001006 /* we pass cmdiocb to state machine which needs rspiocb as well */
1007 cmdiocb->context_un.rsp_iocb = rspiocb;
1008
1009 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1010 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001011 irsp = &rspiocb->iocb;
1012
James Smart92d7f7b2007-06-17 19:56:38 -05001013 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1014 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -05001015 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1016
James Smart858c9f62007-06-17 19:56:39 -05001017 latt = lpfc_els_chk_latt(vport);
1018
1019 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -04001020 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -04001021 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -04001022 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1023 latt, irsp->ulpStatus,
1024 CTrsp->CommandResponse.bits.CmdRsp,
1025 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05001026
James Smart858c9f62007-06-17 19:56:39 -05001027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1028 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1029 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1030
James Smart92d7f7b2007-06-17 19:56:38 -05001031 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001032 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6e155202013-07-15 18:35:21 -04001033 "0268 NS cmd x%x Error (x%x x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04001034 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001035
James Smart92d7f7b2007-06-17 19:56:38 -05001036 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001037 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1038 IOERR_SLI_DOWN) ||
1039 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1040 IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -05001041 goto out;
1042
1043 retry = cmdiocb->retry;
1044 if (retry >= LPFC_MAX_NS_RETRY)
1045 goto out;
1046
1047 retry++;
James Smarte8b62012007-08-02 11:10:09 -04001048 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04001049 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -05001050 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1051 if (rc == 0)
1052 goto out;
1053 }
1054
1055out:
James Smart51ef4c22007-08-02 11:10:31 -04001056 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -05001057 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001058 return;
1059}
1060
1061static void
James Smart7ee5d432007-10-27 13:37:17 -04001062lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1063 struct lpfc_iocbq *rspiocb)
1064{
1065 IOCB_t *irsp = &rspiocb->iocb;
1066 struct lpfc_vport *vport = cmdiocb->vport;
1067
James Smart98c9ea52007-10-27 13:37:33 -04001068 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1069 struct lpfc_dmabuf *outp;
1070 struct lpfc_sli_ct_request *CTrsp;
1071
1072 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1073 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1074 if (CTrsp->CommandResponse.bits.CmdRsp ==
1075 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1076 vport->ct_flags |= FC_CT_RFT_ID;
1077 }
James Smart7ee5d432007-10-27 13:37:17 -04001078 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1079 return;
1080}
1081
1082static void
James Smart2e0fef82007-06-17 19:56:36 -05001083lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1084 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001085{
James Smart7ee5d432007-10-27 13:37:17 -04001086 IOCB_t *irsp = &rspiocb->iocb;
1087 struct lpfc_vport *vport = cmdiocb->vport;
1088
James Smart98c9ea52007-10-27 13:37:33 -04001089 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1090 struct lpfc_dmabuf *outp;
1091 struct lpfc_sli_ct_request *CTrsp;
1092
1093 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1094 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1095 if (CTrsp->CommandResponse.bits.CmdRsp ==
1096 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1097 vport->ct_flags |= FC_CT_RNN_ID;
1098 }
James Smart7ee5d432007-10-27 13:37:17 -04001099 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001100 return;
1101}
1102
1103static void
James Smart92d7f7b2007-06-17 19:56:38 -05001104lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1105 struct lpfc_iocbq *rspiocb)
1106{
James Smart7ee5d432007-10-27 13:37:17 -04001107 IOCB_t *irsp = &rspiocb->iocb;
1108 struct lpfc_vport *vport = cmdiocb->vport;
1109
James Smart98c9ea52007-10-27 13:37:33 -04001110 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1111 struct lpfc_dmabuf *outp;
1112 struct lpfc_sli_ct_request *CTrsp;
1113
1114 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1115 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1116 if (CTrsp->CommandResponse.bits.CmdRsp ==
1117 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1118 vport->ct_flags |= FC_CT_RSPN_ID;
1119 }
James Smart7ee5d432007-10-27 13:37:17 -04001120 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05001121 return;
1122}
1123
1124static void
James Smart2e0fef82007-06-17 19:56:36 -05001125lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1126 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001127{
James Smart7ee5d432007-10-27 13:37:17 -04001128 IOCB_t *irsp = &rspiocb->iocb;
1129 struct lpfc_vport *vport = cmdiocb->vport;
1130
James Smart98c9ea52007-10-27 13:37:33 -04001131 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1132 struct lpfc_dmabuf *outp;
1133 struct lpfc_sli_ct_request *CTrsp;
1134
1135 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1136 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1137 if (CTrsp->CommandResponse.bits.CmdRsp ==
1138 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1139 vport->ct_flags |= FC_CT_RSNN_NN;
1140 }
James Smart7ee5d432007-10-27 13:37:17 -04001141 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1142 return;
1143}
1144
1145static void
1146lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1147 struct lpfc_iocbq *rspiocb)
1148{
1149 struct lpfc_vport *vport = cmdiocb->vport;
1150
1151 /* even if it fails we will act as though it succeeded. */
1152 vport->ct_flags = 0;
1153 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001154 return;
1155}
1156
James Smart2fb9bd82006-12-02 13:33:57 -05001157static void
James Smart92d7f7b2007-06-17 19:56:38 -05001158lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1159 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001160{
James Smart92d7f7b2007-06-17 19:56:38 -05001161 IOCB_t *irsp = &rspiocb->iocb;
1162 struct lpfc_vport *vport = cmdiocb->vport;
1163
James Smart98c9ea52007-10-27 13:37:33 -04001164 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1165 struct lpfc_dmabuf *outp;
1166 struct lpfc_sli_ct_request *CTrsp;
1167
1168 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1169 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1170 if (CTrsp->CommandResponse.bits.CmdRsp ==
1171 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1172 vport->ct_flags |= FC_CT_RFF_ID;
1173 }
James Smart7ee5d432007-10-27 13:37:17 -04001174 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001175 return;
1176}
1177
James Smarta0f2d3e2017-02-12 13:52:31 -08001178/*
1179 * Although the symbolic port name is thought to be an integer
1180 * as of January 18, 2016, leave it as a string until more of
1181 * the record state becomes defined.
1182 */
James Smart495a7142008-06-14 22:52:59 -04001183int
James Smart92d7f7b2007-06-17 19:56:38 -05001184lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1185 size_t size)
1186{
1187 int n;
James Smart92d7f7b2007-06-17 19:56:38 -05001188
James Smarta0f2d3e2017-02-12 13:52:31 -08001189 /*
1190 * Use the lpfc board number as the Symbolic Port
1191 * Name object. NPIV is not in play so this integer
1192 * value is sufficient and unique per FC-ID.
1193 */
1194 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
James Smart92d7f7b2007-06-17 19:56:38 -05001195 return n;
1196}
1197
James Smarta0f2d3e2017-02-12 13:52:31 -08001198
James Smart92d7f7b2007-06-17 19:56:38 -05001199int
1200lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1201 size_t size)
dea31012005-04-17 16:05:31 -05001202{
James Smart6b5151f2012-01-18 16:24:06 -05001203 char fwrev[FW_REV_STR_SIZE];
James Smart92d7f7b2007-06-17 19:56:38 -05001204 int n;
dea31012005-04-17 16:05:31 -05001205
James Smart92d7f7b2007-06-17 19:56:38 -05001206 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001207
James Smartf0bf5f92015-04-07 15:07:18 -04001208 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
James Smartf0bf5f92015-04-07 15:07:18 -04001209 if (size < n)
1210 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001211
James Smartf0bf5f92015-04-07 15:07:18 -04001212 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
James Smartf0bf5f92015-04-07 15:07:18 -04001213 if (size < n)
1214 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001215
James Smarta0f2d3e2017-02-12 13:52:31 -08001216 n += snprintf(symbol + n, size - n, " DV%s.",
1217 lpfc_release_version);
James Smartf0bf5f92015-04-07 15:07:18 -04001218 if (size < n)
1219 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001220
1221 n += snprintf(symbol + n, size - n, " HN:%s.",
1222 init_utsname()->nodename);
1223 if (size < n)
1224 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001225
1226 /* Note :- OS name is "Linux" */
James Smarta0f2d3e2017-02-12 13:52:31 -08001227 n += snprintf(symbol + n, size - n, " OS:%s\n",
1228 init_utsname()->sysname);
James Smart92d7f7b2007-06-17 19:56:38 -05001229 return n;
dea31012005-04-17 16:05:31 -05001230}
1231
James Smart76b2c342015-04-07 15:07:19 -04001232static uint32_t
1233lpfc_find_map_node(struct lpfc_vport *vport)
1234{
1235 struct lpfc_nodelist *ndlp, *next_ndlp;
1236 struct Scsi_Host *shost;
1237 uint32_t cnt = 0;
1238
1239 shost = lpfc_shost_from_vport(vport);
1240 spin_lock_irq(shost->host_lock);
1241 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1242 if (ndlp->nlp_type & NLP_FABRIC)
1243 continue;
1244 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1245 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1246 cnt++;
1247 }
1248 spin_unlock_irq(shost->host_lock);
1249 return cnt;
1250}
1251
dea31012005-04-17 16:05:31 -05001252/*
James Smarta0f2d3e2017-02-12 13:52:31 -08001253 * This routine will return the FC4 Type associated with the CT
1254 * GID_FT command.
1255 */
1256int
1257lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1258{
1259 struct lpfc_sli_ct_request *CtReq;
1260 struct lpfc_dmabuf *mp;
1261 uint32_t type;
1262
1263 mp = cmdiocb->context1;
1264 if (mp == NULL)
1265 return 0;
1266 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1267 type = (uint32_t)CtReq->un.gid.Fc4Type;
1268 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1269 return 0;
1270 return type;
1271}
1272
1273/*
dea31012005-04-17 16:05:31 -05001274 * lpfc_ns_cmd
1275 * Description:
1276 * Issue Cmd to NameServer
1277 * SLI_CTNS_GID_FT
1278 * LI_CTNS_RFT_ID
1279 */
1280int
James Smart92d7f7b2007-06-17 19:56:38 -05001281lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1282 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001283{
James Smart92d7f7b2007-06-17 19:56:38 -05001284 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001285 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001286 struct lpfc_dmabuf *mp, *bmp;
1287 struct lpfc_sli_ct_request *CtReq;
1288 struct ulp_bde64 *bpl;
1289 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1290 struct lpfc_iocbq *) = NULL;
1291 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001292 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001293 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001294
1295 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001296 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1297 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001298 rc=1;
1299 goto ns_cmd_exit;
1300 }
dea31012005-04-17 16:05:31 -05001301
1302 /* fill in BDEs for command */
1303 /* Allocate buffer for command payload */
James Smart4258e982015-12-16 18:11:58 -05001304 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001305 if (!mp) {
1306 rc=2;
dea31012005-04-17 16:05:31 -05001307 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001308 }
dea31012005-04-17 16:05:31 -05001309
1310 INIT_LIST_HEAD(&mp->list);
1311 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001312 if (!mp->virt) {
1313 rc=3;
dea31012005-04-17 16:05:31 -05001314 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001315 }
dea31012005-04-17 16:05:31 -05001316
1317 /* Allocate buffer for Buffer ptr list */
James Smart4258e982015-12-16 18:11:58 -05001318 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001319 if (!bmp) {
1320 rc=4;
dea31012005-04-17 16:05:31 -05001321 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001322 }
dea31012005-04-17 16:05:31 -05001323
1324 INIT_LIST_HEAD(&bmp->list);
1325 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001326 if (!bmp->virt) {
1327 rc=5;
dea31012005-04-17 16:05:31 -05001328 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001329 }
dea31012005-04-17 16:05:31 -05001330
1331 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001332 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -08001333 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1334 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1335 context);
dea31012005-04-17 16:05:31 -05001336
1337 bpl = (struct ulp_bde64 *) bmp->virt;
1338 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001339 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1340 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001341 bpl->tus.f.bdeFlags = 0;
1342 if (cmdcode == SLI_CTNS_GID_FT)
1343 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001344 else if (cmdcode == SLI_CTNS_GFF_ID)
1345 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
James Smarta0f2d3e2017-02-12 13:52:31 -08001346 else if (cmdcode == SLI_CTNS_GFT_ID)
1347 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001348 else if (cmdcode == SLI_CTNS_RFT_ID)
1349 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1350 else if (cmdcode == SLI_CTNS_RNN_ID)
1351 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001352 else if (cmdcode == SLI_CTNS_RSPN_ID)
1353 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001354 else if (cmdcode == SLI_CTNS_RSNN_NN)
1355 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001356 else if (cmdcode == SLI_CTNS_DA_ID)
1357 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001358 else if (cmdcode == SLI_CTNS_RFF_ID)
1359 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001360 else
1361 bpl->tus.f.bdeSize = 0;
1362 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1363
1364 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
James Smart4258e982015-12-16 18:11:58 -05001365 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
dea31012005-04-17 16:05:31 -05001366 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1367 CtReq->RevisionId.bits.InId = 0;
1368 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1369 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1370 CtReq->CommandResponse.bits.Size = 0;
1371 switch (cmdcode) {
1372 case SLI_CTNS_GID_FT:
1373 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001374 cpu_to_be16(SLI_CTNS_GID_FT);
James Smarta0f2d3e2017-02-12 13:52:31 -08001375 CtReq->un.gid.Fc4Type = context;
1376
James Smart92d7f7b2007-06-17 19:56:38 -05001377 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001378 vport->port_state = LPFC_NS_QRY;
1379 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001380 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1381 rsp_size = FC_MAX_NS_RSP;
1382 break;
1383
James Smart92d7f7b2007-06-17 19:56:38 -05001384 case SLI_CTNS_GFF_ID:
1385 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001386 cpu_to_be16(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001387 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001388 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1389 break;
1390
James Smarta0f2d3e2017-02-12 13:52:31 -08001391 case SLI_CTNS_GFT_ID:
1392 CtReq->CommandResponse.bits.CmdRsp =
1393 cpu_to_be16(SLI_CTNS_GFT_ID);
1394 CtReq->un.gft.PortId = cpu_to_be32(context);
1395 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1396 break;
1397
dea31012005-04-17 16:05:31 -05001398 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001399 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001400 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001401 cpu_to_be16(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001402 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
James Smarta0f2d3e2017-02-12 13:52:31 -08001403
1404 /* Register FC4 FCP type if enabled. */
1405 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1406 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1407 CtReq->un.rft.fcpReg = 1;
1408
1409 /* Register NVME type if enabled. Defined LE and swapped.
1410 * rsvd[0] is used as word1 because of the hard-coded
1411 * word0 usage in the ct_request data structure.
1412 */
1413 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1414 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1415 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1416
dea31012005-04-17 16:05:31 -05001417 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1418 break;
1419
1420 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001421 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001422 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001423 cpu_to_be16(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001424 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001425 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001426 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001427 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1428 break;
1429
James Smart92d7f7b2007-06-17 19:56:38 -05001430 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001431 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001432 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001433 cpu_to_be16(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001434 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001435 size = sizeof(CtReq->un.rspn.symbname);
1436 CtReq->un.rspn.len =
1437 lpfc_vport_symbolic_port_name(vport,
1438 CtReq->un.rspn.symbname, size);
1439 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1440 break;
dea31012005-04-17 16:05:31 -05001441 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001442 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001443 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001444 cpu_to_be16(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001445 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001446 sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001447 size = sizeof(CtReq->un.rsnn.symbname);
1448 CtReq->un.rsnn.len =
1449 lpfc_vport_symbolic_node_name(vport,
1450 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001451 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1452 break;
James Smart7ee5d432007-10-27 13:37:17 -04001453 case SLI_CTNS_DA_ID:
1454 /* Implement DA_ID Nameserver request */
1455 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001456 cpu_to_be16(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001457 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001458 cmpl = lpfc_cmpl_ct_cmd_da_id;
1459 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001460 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001461 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001462 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001463 cpu_to_be16(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001464 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001465 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smarta0f2d3e2017-02-12 13:52:31 -08001466
1467 /* The driver always supports FC_TYPE_FCP. However, the
1468 * caller can specify NVME (type x28) as well. But only
1469 * these that FC4 type is supported.
1470 */
1471 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1472 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1473 (context == FC_TYPE_NVME)) {
James Smart8c258642017-02-12 13:52:36 -08001474 if ((vport == phba->pport) && phba->nvmet_support) {
1475 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1476 FC4_FEATURE_NVME_DISC);
James Smartd613b6a2017-02-12 13:52:37 -08001477 lpfc_nvmet_update_targetport(phba);
James Smart8c258642017-02-12 13:52:36 -08001478 } else {
1479 lpfc_nvme_update_localport(vport);
1480 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001481 CtReq->un.rff.type_code = context;
1482
1483 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1484 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1485 (context == FC_TYPE_FCP))
1486 CtReq->un.rff.type_code = context;
1487
1488 else
1489 goto ns_cmd_free_bmpvirt;
1490
James Smart92d7f7b2007-06-17 19:56:38 -05001491 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1492 break;
dea31012005-04-17 16:05:31 -05001493 }
James Smarte47c9092008-02-08 18:49:26 -05001494 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1495 * to hold ndlp reference for the corresponding callback function.
1496 */
James Smart858c9f62007-06-17 19:56:39 -05001497 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001498 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1500 "Issue CT cmd: cmd:x%x did:x%x",
1501 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001502 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001503 }
James Smart858c9f62007-06-17 19:56:39 -05001504 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001505
1506 /* Decrement ndlp reference count to release ndlp reference held
1507 * for the failed command's callback function.
1508 */
James Smart51ef4c22007-08-02 11:10:31 -04001509 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001510
James Smarta0f2d3e2017-02-12 13:52:31 -08001511ns_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05001512 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1513ns_cmd_free_bmp:
1514 kfree(bmp);
1515ns_cmd_free_mpvirt:
1516 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1517ns_cmd_free_mp:
1518 kfree(mp);
1519ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001520 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1521 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1522 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001523 return 1;
1524}
1525
James Smart4258e982015-12-16 18:11:58 -05001526/**
1527 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1528 * @phba: Pointer to HBA context object.
1529 * @cmdiocb: Pointer to the command IOCBQ.
1530 * @rspiocb: Pointer to the response IOCBQ.
1531 *
1532 * This function to handle the completion of a driver initiated FDMI
1533 * CT command issued during discovery.
1534 */
dea31012005-04-17 16:05:31 -05001535static void
James Smart4258e982015-12-16 18:11:58 -05001536lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1537 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001538{
James Smart4258e982015-12-16 18:11:58 -05001539 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001540 struct lpfc_dmabuf *inp = cmdiocb->context1;
1541 struct lpfc_dmabuf *outp = cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001542 struct lpfc_sli_ct_request *CTcmd = inp->virt;
James Smart4258e982015-12-16 18:11:58 -05001543 struct lpfc_sli_ct_request *CTrsp = outp->virt;
dea31012005-04-17 16:05:31 -05001544 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1545 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart858c9f62007-06-17 19:56:39 -05001546 IOCB_t *irsp = &rspiocb->iocb;
James Smart4258e982015-12-16 18:11:58 -05001547 struct lpfc_nodelist *ndlp;
1548 uint32_t latt, cmd, err;
James Smart858c9f62007-06-17 19:56:39 -05001549
1550 latt = lpfc_els_chk_latt(vport);
James Smart858c9f62007-06-17 19:56:39 -05001551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1552 "FDMI cmpl: status:x%x/x%x latt:%d",
1553 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1554
1555 if (latt || irsp->ulpStatus) {
James Smart4258e982015-12-16 18:11:58 -05001556
1557 /* Look for a retryable error */
1558 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1559 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1560 case IOERR_SLI_ABORTED:
1561 case IOERR_ABORT_IN_PROGRESS:
1562 case IOERR_SEQUENCE_TIMEOUT:
1563 case IOERR_ILLEGAL_FRAME:
1564 case IOERR_NO_RESOURCES:
1565 case IOERR_ILLEGAL_COMMAND:
1566 cmdiocb->retry++;
1567 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1568 break;
1569
1570 /* Retry the same FDMI command */
1571 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1572 cmdiocb, 0);
1573 if (err == IOCB_ERROR)
1574 break;
1575 return;
1576 default:
1577 break;
1578 }
1579 }
1580
James Smarte8b62012007-08-02 11:10:09 -04001581 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1582 "0229 FDMI cmd %04x failed, latt = %d "
1583 "ulpStatus: x%x, rid x%x\n",
1584 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1585 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001586 }
James Smart76b2c342015-04-07 15:07:19 -04001587 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart76b2c342015-04-07 15:07:19 -04001588
1589 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1590 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1591 return;
1592
James Smart4258e982015-12-16 18:11:58 -05001593 /* Check for a CT LS_RJT response */
1594 cmd = be16_to_cpu(fdmi_cmd);
1595 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1596 /* FDMI rsp failed */
1597 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1598 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1599
1600 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1601 switch (cmd) {
1602 case SLI_MGMT_RHBA:
1603 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1604 /* Fallback to FDMI-1 */
1605 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1606 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1607 /* Start over */
1608 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1609 }
1610 return;
1611
1612 case SLI_MGMT_RPRT:
1613 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1614 /* Fallback to FDMI-1 */
1615 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1616 /* Start over */
1617 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1618 }
1619 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1620 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1621 /* Retry the same command */
1622 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1623 }
1624 return;
1625
1626 case SLI_MGMT_RPA:
1627 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1628 /* Fallback to FDMI-1 */
1629 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1630 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1631 /* Start over */
1632 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1633 }
1634 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1635 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1636 /* Retry the same command */
1637 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1638 }
1639 return;
1640 }
1641 }
1642
James Smart76b2c342015-04-07 15:07:19 -04001643 /*
James Smart4258e982015-12-16 18:11:58 -05001644 * On success, need to cycle thru FDMI registration for discovery
1645 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1646 * DPRT -> RPRT (vports)
James Smart76b2c342015-04-07 15:07:19 -04001647 */
James Smart4258e982015-12-16 18:11:58 -05001648 switch (cmd) {
dea31012005-04-17 16:05:31 -05001649 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05001650 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
dea31012005-04-17 16:05:31 -05001651 break;
1652
dea31012005-04-17 16:05:31 -05001653 case SLI_MGMT_DHBA:
James Smart4258e982015-12-16 18:11:58 -05001654 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
dea31012005-04-17 16:05:31 -05001655 break;
1656
1657 case SLI_MGMT_DPRT:
James Smart4258e982015-12-16 18:11:58 -05001658 if (vport->port_type == LPFC_PHYSICAL_PORT)
1659 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1660 else
1661 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
dea31012005-04-17 16:05:31 -05001662 break;
1663 }
James Smart4258e982015-12-16 18:11:58 -05001664 return;
dea31012005-04-17 16:05:31 -05001665}
James Smart2e0fef82007-06-17 19:56:36 -05001666
James Smart76b2c342015-04-07 15:07:19 -04001667
James Smart4258e982015-12-16 18:11:58 -05001668/**
1669 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1670 * @vport: pointer to a host virtual N_Port data structure.
1671 *
1672 * Called from hbeat timeout routine to check if the number of discovered
1673 * ports has changed. If so, re-register thar port Attribute.
1674 */
1675void
1676lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1677{
1678 struct lpfc_hba *phba = vport->phba;
1679 struct lpfc_nodelist *ndlp;
1680 uint16_t cnt;
1681
1682 if (!lpfc_is_link_up(phba))
1683 return;
1684
James Smarta03a4212016-07-06 12:36:12 -07001685 /* Must be connected to a Fabric */
1686 if (!(vport->fc_flag & FC_FABRIC))
1687 return;
1688
James Smart4258e982015-12-16 18:11:58 -05001689 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1690 return;
1691
1692 cnt = lpfc_find_map_node(vport);
1693 if (cnt == vport->fdmi_num_disc)
1694 return;
1695
1696 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1697 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1698 return;
1699
1700 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1701 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1702 LPFC_FDMI_PORT_ATTR_num_disc);
1703 } else {
1704 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1705 LPFC_FDMI_PORT_ATTR_num_disc);
1706 }
1707}
1708
1709/* Routines for all individual HBA attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001710static int
James Smart4258e982015-12-16 18:11:58 -05001711lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1712{
1713 struct lpfc_fdmi_attr_entry *ae;
1714 uint32_t size;
1715
1716 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1717 memset(ae, 0, sizeof(struct lpfc_name));
1718
1719 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1720 sizeof(struct lpfc_name));
1721 size = FOURBYTES + sizeof(struct lpfc_name);
1722 ad->AttrLen = cpu_to_be16(size);
1723 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1724 return size;
1725}
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001726static int
James Smart4258e982015-12-16 18:11:58 -05001727lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1728 struct lpfc_fdmi_attr_def *ad)
1729{
1730 struct lpfc_fdmi_attr_entry *ae;
1731 uint32_t len, size;
1732
1733 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1734 memset(ae, 0, 256);
1735
1736 strncpy(ae->un.AttrString,
1737 "Emulex Corporation",
1738 sizeof(ae->un.AttrString));
1739 len = strnlen(ae->un.AttrString,
1740 sizeof(ae->un.AttrString));
1741 len += (len & 3) ? (4 - (len & 3)) : 4;
1742 size = FOURBYTES + len;
1743 ad->AttrLen = cpu_to_be16(size);
1744 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1745 return size;
1746}
1747
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001748static int
James Smart4258e982015-12-16 18:11:58 -05001749lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1750{
1751 struct lpfc_hba *phba = vport->phba;
1752 struct lpfc_fdmi_attr_entry *ae;
1753 uint32_t len, size;
1754
1755 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1756 memset(ae, 0, 256);
1757
1758 strncpy(ae->un.AttrString, phba->SerialNumber,
1759 sizeof(ae->un.AttrString));
1760 len = strnlen(ae->un.AttrString,
1761 sizeof(ae->un.AttrString));
1762 len += (len & 3) ? (4 - (len & 3)) : 4;
1763 size = FOURBYTES + len;
1764 ad->AttrLen = cpu_to_be16(size);
1765 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1766 return size;
1767}
1768
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001769static int
James Smart4258e982015-12-16 18:11:58 -05001770lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1771 struct lpfc_fdmi_attr_def *ad)
1772{
1773 struct lpfc_hba *phba = vport->phba;
1774 struct lpfc_fdmi_attr_entry *ae;
1775 uint32_t len, size;
1776
1777 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1778 memset(ae, 0, 256);
1779
1780 strncpy(ae->un.AttrString, phba->ModelName,
1781 sizeof(ae->un.AttrString));
1782 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1783 len += (len & 3) ? (4 - (len & 3)) : 4;
1784 size = FOURBYTES + len;
1785 ad->AttrLen = cpu_to_be16(size);
1786 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1787 return size;
1788}
1789
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001790static int
James Smart4258e982015-12-16 18:11:58 -05001791lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1792 struct lpfc_fdmi_attr_def *ad)
1793{
1794 struct lpfc_hba *phba = vport->phba;
1795 struct lpfc_fdmi_attr_entry *ae;
1796 uint32_t len, size;
1797
1798 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1799 memset(ae, 0, 256);
1800
1801 strncpy(ae->un.AttrString, phba->ModelDesc,
1802 sizeof(ae->un.AttrString));
1803 len = strnlen(ae->un.AttrString,
1804 sizeof(ae->un.AttrString));
1805 len += (len & 3) ? (4 - (len & 3)) : 4;
1806 size = FOURBYTES + len;
1807 ad->AttrLen = cpu_to_be16(size);
1808 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1809 return size;
1810}
1811
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001812static int
James Smart4258e982015-12-16 18:11:58 -05001813lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1814 struct lpfc_fdmi_attr_def *ad)
1815{
1816 struct lpfc_hba *phba = vport->phba;
1817 lpfc_vpd_t *vp = &phba->vpd;
1818 struct lpfc_fdmi_attr_entry *ae;
1819 uint32_t i, j, incr, size;
1820
1821 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1822 memset(ae, 0, 256);
1823
1824 /* Convert JEDEC ID to ascii for hardware version */
1825 incr = vp->rev.biuRev;
1826 for (i = 0; i < 8; i++) {
1827 j = (incr & 0xf);
1828 if (j <= 9)
1829 ae->un.AttrString[7 - i] =
1830 (char)((uint8_t) 0x30 +
1831 (uint8_t) j);
1832 else
1833 ae->un.AttrString[7 - i] =
1834 (char)((uint8_t) 0x61 +
1835 (uint8_t) (j - 10));
1836 incr = (incr >> 4);
1837 }
1838 size = FOURBYTES + 8;
1839 ad->AttrLen = cpu_to_be16(size);
1840 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1841 return size;
1842}
1843
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001844static int
James Smart4258e982015-12-16 18:11:58 -05001845lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1846 struct lpfc_fdmi_attr_def *ad)
1847{
1848 struct lpfc_fdmi_attr_entry *ae;
1849 uint32_t len, size;
1850
1851 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1852 memset(ae, 0, 256);
1853
1854 strncpy(ae->un.AttrString, lpfc_release_version,
1855 sizeof(ae->un.AttrString));
1856 len = strnlen(ae->un.AttrString,
1857 sizeof(ae->un.AttrString));
1858 len += (len & 3) ? (4 - (len & 3)) : 4;
1859 size = FOURBYTES + len;
1860 ad->AttrLen = cpu_to_be16(size);
1861 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1862 return size;
1863}
1864
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001865static int
James Smart4258e982015-12-16 18:11:58 -05001866lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1867 struct lpfc_fdmi_attr_def *ad)
1868{
1869 struct lpfc_hba *phba = vport->phba;
1870 struct lpfc_fdmi_attr_entry *ae;
1871 uint32_t len, size;
1872
1873 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1874 memset(ae, 0, 256);
1875
1876 if (phba->sli_rev == LPFC_SLI_REV4)
1877 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1878 else
1879 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1880 sizeof(ae->un.AttrString));
1881 len = strnlen(ae->un.AttrString,
1882 sizeof(ae->un.AttrString));
1883 len += (len & 3) ? (4 - (len & 3)) : 4;
1884 size = FOURBYTES + len;
1885 ad->AttrLen = cpu_to_be16(size);
1886 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1887 return size;
1888}
1889
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001890static int
James Smart4258e982015-12-16 18:11:58 -05001891lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1892 struct lpfc_fdmi_attr_def *ad)
1893{
1894 struct lpfc_hba *phba = vport->phba;
1895 struct lpfc_fdmi_attr_entry *ae;
1896 uint32_t len, size;
1897
1898 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1899 memset(ae, 0, 256);
1900
1901 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1902 len = strnlen(ae->un.AttrString,
1903 sizeof(ae->un.AttrString));
1904 len += (len & 3) ? (4 - (len & 3)) : 4;
1905 size = FOURBYTES + len;
1906 ad->AttrLen = cpu_to_be16(size);
1907 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1908 return size;
1909}
1910
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001911static int
James Smart4258e982015-12-16 18:11:58 -05001912lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1913 struct lpfc_fdmi_attr_def *ad)
1914{
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 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1922 init_utsname()->sysname,
1923 init_utsname()->release,
1924 init_utsname()->version);
1925
1926 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1927 len += (len & 3) ? (4 - (len & 3)) : 4;
1928 size = FOURBYTES + len;
1929 ad->AttrLen = cpu_to_be16(size);
1930 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1931 return size;
1932}
1933
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001934static int
James Smart4258e982015-12-16 18:11:58 -05001935lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1936 struct lpfc_fdmi_attr_def *ad)
1937{
1938 struct lpfc_fdmi_attr_entry *ae;
1939 uint32_t size;
1940
1941 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1942
1943 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1944 size = FOURBYTES + sizeof(uint32_t);
1945 ad->AttrLen = cpu_to_be16(size);
1946 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1947 return size;
1948}
1949
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001950static int
James Smart4258e982015-12-16 18:11:58 -05001951lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1952 struct lpfc_fdmi_attr_def *ad)
1953{
1954 struct lpfc_fdmi_attr_entry *ae;
1955 uint32_t len, size;
1956
1957 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1958 memset(ae, 0, 256);
1959
1960 len = lpfc_vport_symbolic_node_name(vport,
1961 ae->un.AttrString, 256);
1962 len += (len & 3) ? (4 - (len & 3)) : 4;
1963 size = FOURBYTES + len;
1964 ad->AttrLen = cpu_to_be16(size);
1965 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1966 return size;
1967}
1968
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001969static int
James Smart4258e982015-12-16 18:11:58 -05001970lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
1971 struct lpfc_fdmi_attr_def *ad)
1972{
1973 struct lpfc_fdmi_attr_entry *ae;
1974 uint32_t size;
1975
1976 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1977
1978 /* Nothing is defined for this currently */
1979 ae->un.AttrInt = cpu_to_be32(0);
1980 size = FOURBYTES + sizeof(uint32_t);
1981 ad->AttrLen = cpu_to_be16(size);
1982 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
1983 return size;
1984}
1985
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001986static int
James Smart4258e982015-12-16 18:11:58 -05001987lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
1988 struct lpfc_fdmi_attr_def *ad)
1989{
1990 struct lpfc_fdmi_attr_entry *ae;
1991 uint32_t size;
1992
1993 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1994
1995 /* Each driver instance corresponds to a single port */
1996 ae->un.AttrInt = cpu_to_be32(1);
1997 size = FOURBYTES + sizeof(uint32_t);
1998 ad->AttrLen = cpu_to_be16(size);
1999 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2000 return size;
2001}
2002
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002003static int
James Smart4258e982015-12-16 18:11:58 -05002004lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2005 struct lpfc_fdmi_attr_def *ad)
2006{
2007 struct lpfc_fdmi_attr_entry *ae;
2008 uint32_t size;
2009
2010 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2011 memset(ae, 0, sizeof(struct lpfc_name));
2012
2013 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2014 sizeof(struct lpfc_name));
2015 size = FOURBYTES + sizeof(struct lpfc_name);
2016 ad->AttrLen = cpu_to_be16(size);
2017 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2018 return size;
2019}
2020
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002021static int
James Smart4258e982015-12-16 18:11:58 -05002022lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2023 struct lpfc_fdmi_attr_def *ad)
2024{
2025 struct lpfc_hba *phba = vport->phba;
2026 struct lpfc_fdmi_attr_entry *ae;
2027 uint32_t len, size;
2028
2029 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2030 memset(ae, 0, 256);
2031
2032 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2033 len = strnlen(ae->un.AttrString,
2034 sizeof(ae->un.AttrString));
2035 len += (len & 3) ? (4 - (len & 3)) : 4;
2036 size = FOURBYTES + len;
2037 ad->AttrLen = cpu_to_be16(size);
2038 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2039 return size;
2040}
2041
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002042static int
James Smart4258e982015-12-16 18:11:58 -05002043lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2044 struct lpfc_fdmi_attr_def *ad)
2045{
2046 struct lpfc_fdmi_attr_entry *ae;
2047 uint32_t size;
2048
2049 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2050
2051 /* Driver doesn't have access to this information */
2052 ae->un.AttrInt = cpu_to_be32(0);
2053 size = FOURBYTES + sizeof(uint32_t);
2054 ad->AttrLen = cpu_to_be16(size);
2055 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2056 return size;
2057}
2058
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002059static int
James Smart4258e982015-12-16 18:11:58 -05002060lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2061 struct lpfc_fdmi_attr_def *ad)
2062{
2063 struct lpfc_fdmi_attr_entry *ae;
2064 uint32_t len, size;
2065
2066 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2067 memset(ae, 0, 256);
2068
2069 strncpy(ae->un.AttrString, "EMULEX",
2070 sizeof(ae->un.AttrString));
2071 len = strnlen(ae->un.AttrString,
2072 sizeof(ae->un.AttrString));
2073 len += (len & 3) ? (4 - (len & 3)) : 4;
2074 size = FOURBYTES + len;
2075 ad->AttrLen = cpu_to_be16(size);
2076 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2077 return size;
2078}
2079
2080/* Routines for all individual PORT attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002081static int
James Smart4258e982015-12-16 18:11:58 -05002082lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2083 struct lpfc_fdmi_attr_def *ad)
2084{
2085 struct lpfc_fdmi_attr_entry *ae;
2086 uint32_t size;
2087
2088 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2089 memset(ae, 0, 32);
2090
2091 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2092 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
James Smart82820f02017-05-15 15:20:47 -07002093 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
James Smart4258e982015-12-16 18:11:58 -05002094 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2095 size = FOURBYTES + 32;
2096 ad->AttrLen = cpu_to_be16(size);
2097 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2098 return size;
2099}
2100
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002101static int
James Smart4258e982015-12-16 18:11:58 -05002102lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2103 struct lpfc_fdmi_attr_def *ad)
2104{
2105 struct lpfc_hba *phba = vport->phba;
2106 struct lpfc_fdmi_attr_entry *ae;
2107 uint32_t size;
2108
2109 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2110
2111 ae->un.AttrInt = 0;
James Smarta085e872015-12-16 18:12:02 -05002112 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2113 if (phba->lmt & LMT_32Gb)
2114 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2115 if (phba->lmt & LMT_16Gb)
2116 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2117 if (phba->lmt & LMT_10Gb)
2118 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2119 if (phba->lmt & LMT_8Gb)
2120 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2121 if (phba->lmt & LMT_4Gb)
2122 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2123 if (phba->lmt & LMT_2Gb)
2124 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2125 if (phba->lmt & LMT_1Gb)
2126 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2127 } else {
2128 /* FCoE links support only one speed */
2129 switch (phba->fc_linkspeed) {
2130 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2131 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2132 break;
2133 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2134 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2135 break;
2136 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2137 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2138 break;
2139 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2140 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2141 break;
2142 }
2143 }
James Smart4258e982015-12-16 18:11:58 -05002144 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2145 size = FOURBYTES + sizeof(uint32_t);
2146 ad->AttrLen = cpu_to_be16(size);
2147 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2148 return size;
2149}
2150
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002151static int
James Smart4258e982015-12-16 18:11:58 -05002152lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2153 struct lpfc_fdmi_attr_def *ad)
2154{
2155 struct lpfc_hba *phba = vport->phba;
2156 struct lpfc_fdmi_attr_entry *ae;
2157 uint32_t size;
2158
2159 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2160
James Smarta085e872015-12-16 18:12:02 -05002161 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2162 switch (phba->fc_linkspeed) {
2163 case LPFC_LINK_SPEED_1GHZ:
2164 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2165 break;
2166 case LPFC_LINK_SPEED_2GHZ:
2167 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2168 break;
2169 case LPFC_LINK_SPEED_4GHZ:
2170 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2171 break;
2172 case LPFC_LINK_SPEED_8GHZ:
2173 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2174 break;
2175 case LPFC_LINK_SPEED_10GHZ:
2176 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2177 break;
2178 case LPFC_LINK_SPEED_16GHZ:
2179 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2180 break;
2181 case LPFC_LINK_SPEED_32GHZ:
2182 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2183 break;
2184 default:
2185 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2186 break;
2187 }
2188 } else {
2189 switch (phba->fc_linkspeed) {
2190 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2191 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2192 break;
2193 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2194 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2195 break;
2196 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2197 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2198 break;
2199 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2200 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2201 break;
2202 default:
2203 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2204 break;
2205 }
James Smart4258e982015-12-16 18:11:58 -05002206 }
James Smarta085e872015-12-16 18:12:02 -05002207
James Smart4258e982015-12-16 18:11:58 -05002208 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2209 size = FOURBYTES + sizeof(uint32_t);
2210 ad->AttrLen = cpu_to_be16(size);
2211 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2212 return size;
2213}
2214
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002215static int
James Smart4258e982015-12-16 18:11:58 -05002216lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2217 struct lpfc_fdmi_attr_def *ad)
2218{
2219 struct serv_parm *hsp;
2220 struct lpfc_fdmi_attr_entry *ae;
2221 uint32_t size;
2222
2223 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2224
2225 hsp = (struct serv_parm *)&vport->fc_sparam;
2226 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2227 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2228 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2229 size = FOURBYTES + sizeof(uint32_t);
2230 ad->AttrLen = cpu_to_be16(size);
2231 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2232 return size;
2233}
2234
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002235static int
James Smart4258e982015-12-16 18:11:58 -05002236lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2237 struct lpfc_fdmi_attr_def *ad)
2238{
2239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2240 struct lpfc_fdmi_attr_entry *ae;
2241 uint32_t len, size;
2242
2243 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2244 memset(ae, 0, 256);
2245
2246 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2247 "/sys/class/scsi_host/host%d", shost->host_no);
2248 len = strnlen((char *)ae->un.AttrString,
2249 sizeof(ae->un.AttrString));
2250 len += (len & 3) ? (4 - (len & 3)) : 4;
2251 size = FOURBYTES + len;
2252 ad->AttrLen = cpu_to_be16(size);
2253 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2254 return size;
2255}
2256
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002257static int
James Smart4258e982015-12-16 18:11:58 -05002258lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2259 struct lpfc_fdmi_attr_def *ad)
2260{
2261 struct lpfc_fdmi_attr_entry *ae;
2262 uint32_t len, size;
2263
2264 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2265 memset(ae, 0, 256);
2266
2267 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2268 init_utsname()->nodename);
2269
2270 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2271 len += (len & 3) ? (4 - (len & 3)) : 4;
2272 size = FOURBYTES + len;
2273 ad->AttrLen = cpu_to_be16(size);
2274 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2275 return size;
2276}
2277
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002278static int
James Smart4258e982015-12-16 18:11:58 -05002279lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2280 struct lpfc_fdmi_attr_def *ad)
2281{
2282 struct lpfc_fdmi_attr_entry *ae;
2283 uint32_t size;
2284
2285 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2286 memset(ae, 0, sizeof(struct lpfc_name));
2287
2288 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2289 sizeof(struct lpfc_name));
2290 size = FOURBYTES + sizeof(struct lpfc_name);
2291 ad->AttrLen = cpu_to_be16(size);
2292 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2293 return size;
2294}
2295
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002296static int
James Smart4258e982015-12-16 18:11:58 -05002297lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2298 struct lpfc_fdmi_attr_def *ad)
2299{
2300 struct lpfc_fdmi_attr_entry *ae;
2301 uint32_t size;
2302
2303 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2304 memset(ae, 0, sizeof(struct lpfc_name));
2305
2306 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2307 sizeof(struct lpfc_name));
2308 size = FOURBYTES + sizeof(struct lpfc_name);
2309 ad->AttrLen = cpu_to_be16(size);
2310 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2311 return size;
2312}
2313
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002314static int
James Smart4258e982015-12-16 18:11:58 -05002315lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2316 struct lpfc_fdmi_attr_def *ad)
2317{
2318 struct lpfc_fdmi_attr_entry *ae;
2319 uint32_t len, size;
2320
2321 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2322 memset(ae, 0, 256);
2323
2324 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2325 len += (len & 3) ? (4 - (len & 3)) : 4;
2326 size = FOURBYTES + len;
2327 ad->AttrLen = cpu_to_be16(size);
2328 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2329 return size;
2330}
2331
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002332static int
James Smart4258e982015-12-16 18:11:58 -05002333lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2334 struct lpfc_fdmi_attr_def *ad)
2335{
2336 struct lpfc_hba *phba = vport->phba;
2337 struct lpfc_fdmi_attr_entry *ae;
2338 uint32_t size;
2339
2340 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2341 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2342 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2343 else
2344 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2345 size = FOURBYTES + sizeof(uint32_t);
2346 ad->AttrLen = cpu_to_be16(size);
2347 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2348 return size;
2349}
2350
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002351static int
James Smart4258e982015-12-16 18:11:58 -05002352lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2353 struct lpfc_fdmi_attr_def *ad)
2354{
2355 struct lpfc_fdmi_attr_entry *ae;
2356 uint32_t size;
2357
2358 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2359 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2360 size = FOURBYTES + sizeof(uint32_t);
2361 ad->AttrLen = cpu_to_be16(size);
2362 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2363 return size;
2364}
2365
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002366static int
James Smart4258e982015-12-16 18:11:58 -05002367lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2368 struct lpfc_fdmi_attr_def *ad)
2369{
2370 struct lpfc_fdmi_attr_entry *ae;
2371 uint32_t size;
2372
2373 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2374 memset(ae, 0, sizeof(struct lpfc_name));
2375
2376 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2377 sizeof(struct lpfc_name));
2378 size = FOURBYTES + sizeof(struct lpfc_name);
2379 ad->AttrLen = cpu_to_be16(size);
2380 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2381 return size;
2382}
2383
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002384static int
James Smart4258e982015-12-16 18:11:58 -05002385lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2386 struct lpfc_fdmi_attr_def *ad)
2387{
2388 struct lpfc_fdmi_attr_entry *ae;
2389 uint32_t size;
2390
2391 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2392 memset(ae, 0, 32);
2393
2394 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2395 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2396 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2397 size = FOURBYTES + 32;
2398 ad->AttrLen = cpu_to_be16(size);
2399 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2400 return size;
2401}
2402
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002403static int
James Smart4258e982015-12-16 18:11:58 -05002404lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2405 struct lpfc_fdmi_attr_def *ad)
2406{
2407 struct lpfc_fdmi_attr_entry *ae;
2408 uint32_t size;
2409
2410 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2411 /* Link Up - operational */
2412 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2413 size = FOURBYTES + sizeof(uint32_t);
2414 ad->AttrLen = cpu_to_be16(size);
2415 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2416 return size;
2417}
2418
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002419static int
James Smart4258e982015-12-16 18:11:58 -05002420lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2421 struct lpfc_fdmi_attr_def *ad)
2422{
2423 struct lpfc_fdmi_attr_entry *ae;
2424 uint32_t size;
2425
2426 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2427 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2428 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2429 size = FOURBYTES + sizeof(uint32_t);
2430 ad->AttrLen = cpu_to_be16(size);
2431 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2432 return size;
2433}
2434
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002435static int
James Smart4258e982015-12-16 18:11:58 -05002436lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2437 struct lpfc_fdmi_attr_def *ad)
2438{
2439 struct lpfc_fdmi_attr_entry *ae;
2440 uint32_t size;
2441
2442 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2443 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2444 size = FOURBYTES + sizeof(uint32_t);
2445 ad->AttrLen = cpu_to_be16(size);
2446 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2447 return size;
2448}
2449
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002450static int
James Smart4258e982015-12-16 18:11:58 -05002451lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2452 struct lpfc_fdmi_attr_def *ad)
2453{
2454 struct lpfc_fdmi_attr_entry *ae;
2455 uint32_t len, size;
2456
2457 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2458 memset(ae, 0, 256);
2459
2460 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2461 sizeof(ae->un.AttrString));
2462 len = strnlen(ae->un.AttrString,
2463 sizeof(ae->un.AttrString));
2464 len += (len & 3) ? (4 - (len & 3)) : 4;
2465 size = FOURBYTES + len;
2466 ad->AttrLen = cpu_to_be16(size);
2467 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2468 return size;
2469}
2470
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002471static int
James Smart4258e982015-12-16 18:11:58 -05002472lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2473 struct lpfc_fdmi_attr_def *ad)
2474{
2475 struct lpfc_fdmi_attr_entry *ae;
2476 uint32_t size;
2477
2478 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2479 memset(ae, 0, 256);
2480
2481 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2482 sizeof(struct lpfc_name));
2483 memcpy((((uint8_t *)&ae->un.AttrString) +
2484 sizeof(struct lpfc_name)),
2485 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2486 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2487 ad->AttrLen = cpu_to_be16(size);
2488 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2489 return size;
2490}
2491
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002492static int
James Smart4258e982015-12-16 18:11:58 -05002493lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2494 struct lpfc_fdmi_attr_def *ad)
2495{
2496 struct lpfc_fdmi_attr_entry *ae;
2497 uint32_t len, size;
2498
2499 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2500 memset(ae, 0, 256);
2501
James Smart56204982016-03-31 14:12:32 -07002502 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
James Smart4258e982015-12-16 18:11:58 -05002503 sizeof(ae->un.AttrString));
2504 len = strnlen(ae->un.AttrString,
2505 sizeof(ae->un.AttrString));
2506 len += (len & 3) ? (4 - (len & 3)) : 4;
2507 size = FOURBYTES + len;
2508 ad->AttrLen = cpu_to_be16(size);
2509 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2510 return size;
2511}
2512
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002513static int
James Smart4258e982015-12-16 18:11:58 -05002514lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2515 struct lpfc_fdmi_attr_def *ad)
2516{
2517 struct lpfc_hba *phba = vport->phba;
2518 struct lpfc_fdmi_attr_entry *ae;
2519 uint32_t len, size;
2520
2521 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2522 memset(ae, 0, 256);
2523
2524 strncpy(ae->un.AttrString, phba->ModelName,
2525 sizeof(ae->un.AttrString));
2526 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2527 len += (len & 3) ? (4 - (len & 3)) : 4;
2528 size = FOURBYTES + len;
2529 ad->AttrLen = cpu_to_be16(size);
2530 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2531 return size;
2532}
2533
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002534static int
James Smart4258e982015-12-16 18:11:58 -05002535lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2536 struct lpfc_fdmi_attr_def *ad)
2537{
2538 struct lpfc_fdmi_attr_entry *ae;
2539 uint32_t size;
2540
2541 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2542
2543 /* SRIOV (type 3) is not supported */
2544 if (vport->vpi)
2545 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2546 else
2547 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2548 size = FOURBYTES + sizeof(uint32_t);
2549 ad->AttrLen = cpu_to_be16(size);
2550 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2551 return size;
2552}
2553
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002554static int
James Smart4258e982015-12-16 18:11:58 -05002555lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2556 struct lpfc_fdmi_attr_def *ad)
2557{
2558 struct lpfc_fdmi_attr_entry *ae;
2559 uint32_t size;
2560
2561 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2562 ae->un.AttrInt = cpu_to_be32(0);
2563 size = FOURBYTES + sizeof(uint32_t);
2564 ad->AttrLen = cpu_to_be16(size);
2565 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2566 return size;
2567}
2568
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002569static int
James Smart4258e982015-12-16 18:11:58 -05002570lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2571 struct lpfc_fdmi_attr_def *ad)
2572{
2573 struct lpfc_fdmi_attr_entry *ae;
2574 uint32_t size;
2575
2576 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
James Smart56204982016-03-31 14:12:32 -07002577 ae->un.AttrInt = cpu_to_be32(1);
James Smart4258e982015-12-16 18:11:58 -05002578 size = FOURBYTES + sizeof(uint32_t);
2579 ad->AttrLen = cpu_to_be16(size);
2580 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2581 return size;
2582}
2583
2584/* RHBA attribute jump table */
2585int (*lpfc_fdmi_hba_action[])
2586 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2587 /* Action routine Mask bit Attribute type */
2588 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2589 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2590 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2591 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2592 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2593 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2594 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2595 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2596 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2597 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2598 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2599 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2600 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2601 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2602 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2603 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2604 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2605 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2606};
2607
2608/* RPA / RPRT attribute jump table */
2609int (*lpfc_fdmi_port_action[])
2610 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2611 /* Action routine Mask bit Attribute type */
2612 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2613 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2614 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2615 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2616 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2617 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2618 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2619 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2620 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2621 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2622 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2623 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2624 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2625 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2626 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2627 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2628 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2629 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2630 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2631 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2632 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2633 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2634 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2635};
2636
2637/**
2638 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2639 * @vport: pointer to a host virtual N_Port data structure.
2640 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2641 * cmdcode: FDMI command to send
2642 * mask: Mask of HBA or PORT Attributes to send
2643 *
2644 * Builds and sends a FDMI command using the CT subsystem.
2645 */
2646int
2647lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2648 int cmdcode, uint32_t new_mask)
dea31012005-04-17 16:05:31 -05002649{
James Smart2e0fef82007-06-17 19:56:36 -05002650 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002651 struct lpfc_dmabuf *mp, *bmp;
2652 struct lpfc_sli_ct_request *CtReq;
2653 struct ulp_bde64 *bpl;
James Smart4258e982015-12-16 18:11:58 -05002654 uint32_t bit_pos;
dea31012005-04-17 16:05:31 -05002655 uint32_t size;
James Smart76b2c342015-04-07 15:07:19 -04002656 uint32_t rsp_size;
James Smart4258e982015-12-16 18:11:58 -05002657 uint32_t mask;
James Smart76b2c342015-04-07 15:07:19 -04002658 struct lpfc_fdmi_reg_hba *rh;
2659 struct lpfc_fdmi_port_entry *pe;
2660 struct lpfc_fdmi_reg_portattr *pab = NULL;
2661 struct lpfc_fdmi_attr_block *ab = NULL;
James Smart4258e982015-12-16 18:11:58 -05002662 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2663 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2664 struct lpfc_iocbq *);
dea31012005-04-17 16:05:31 -05002665
James Smart4258e982015-12-16 18:11:58 -05002666 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2667 return 0;
2668
2669 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
dea31012005-04-17 16:05:31 -05002670
2671 /* fill in BDEs for command */
2672 /* Allocate buffer for command payload */
James Smart76b2c342015-04-07 15:07:19 -04002673 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002674 if (!mp)
2675 goto fdmi_cmd_exit;
2676
2677 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2678 if (!mp->virt)
2679 goto fdmi_cmd_free_mp;
2680
2681 /* Allocate buffer for Buffer ptr list */
James Smart76b2c342015-04-07 15:07:19 -04002682 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002683 if (!bmp)
2684 goto fdmi_cmd_free_mpvirt;
2685
2686 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2687 if (!bmp->virt)
2688 goto fdmi_cmd_free_bmp;
2689
2690 INIT_LIST_HEAD(&mp->list);
2691 INIT_LIST_HEAD(&bmp->list);
2692
2693 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04002694 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2695 "0218 FDMI Request Data: x%x x%x x%x\n",
2696 vport->fc_flag, vport->port_state, cmdcode);
James Smart76b2c342015-04-07 15:07:19 -04002697 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
dea31012005-04-17 16:05:31 -05002698
James Smart76b2c342015-04-07 15:07:19 -04002699 /* First populate the CT_IU preamble */
dea31012005-04-17 16:05:31 -05002700 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2701 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2702 CtReq->RevisionId.bits.InId = 0;
2703
2704 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2705 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
James Smart76b2c342015-04-07 15:07:19 -04002706
2707 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2708 rsp_size = LPFC_BPL_SIZE;
dea31012005-04-17 16:05:31 -05002709 size = 0;
2710
James Smart76b2c342015-04-07 15:07:19 -04002711 /* Next fill in the specific FDMI cmd information */
dea31012005-04-17 16:05:31 -05002712 switch (cmdcode) {
James Smart76b2c342015-04-07 15:07:19 -04002713 case SLI_MGMT_RHAT:
dea31012005-04-17 16:05:31 -05002714 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05002715 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2716 /* HBA Identifier */
2717 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2718 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002719
James Smart4258e982015-12-16 18:11:58 -05002720 if (cmdcode == SLI_MGMT_RHBA) {
2721 /* Registered Port List */
2722 /* One entry (port) per adapter */
2723 rh->rpl.EntryCnt = cpu_to_be32(1);
2724 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002725 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002726
James Smart4258e982015-12-16 18:11:58 -05002727 /* point to the HBA attribute block */
2728 size = 2 * sizeof(struct lpfc_name) +
2729 FOURBYTES;
2730 } else {
2731 size = sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002732 }
James Smart4258e982015-12-16 18:11:58 -05002733 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2734 ab->EntryCnt = 0;
2735 size += FOURBYTES;
2736 bit_pos = 0;
2737 if (new_mask)
2738 mask = new_mask;
2739 else
2740 mask = vport->fdmi_hba_mask;
2741
2742 /* Mask will dictate what attributes to build in the request */
2743 while (mask) {
2744 if (mask & 0x1) {
2745 func = lpfc_fdmi_hba_action[bit_pos];
2746 size += func(vport,
2747 (struct lpfc_fdmi_attr_def *)
2748 ((uint8_t *)rh + size));
2749 ab->EntryCnt++;
2750 if ((size + 256) >
2751 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2752 goto hba_out;
2753 }
2754 mask = mask >> 1;
2755 bit_pos++;
2756 }
2757hba_out:
2758 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2759 /* Total size */
2760 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002761 break;
2762
James Smart76b2c342015-04-07 15:07:19 -04002763 case SLI_MGMT_RPRT:
dea31012005-04-17 16:05:31 -05002764 case SLI_MGMT_RPA:
James Smart4258e982015-12-16 18:11:58 -05002765 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2766 if (cmdcode == SLI_MGMT_RPRT) {
2767 rh = (struct lpfc_fdmi_reg_hba *)pab;
2768 /* HBA Identifier */
2769 memcpy(&rh->hi.PortName,
2770 &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002771 sizeof(struct lpfc_name));
James Smart4258e982015-12-16 18:11:58 -05002772 pab = (struct lpfc_fdmi_reg_portattr *)
2773 ((uint8_t *)pab + sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002774 }
James Smart4258e982015-12-16 18:11:58 -05002775
2776 memcpy((uint8_t *)&pab->PortName,
2777 (uint8_t *)&vport->fc_sparam.portName,
2778 sizeof(struct lpfc_name));
2779 size += sizeof(struct lpfc_name) + FOURBYTES;
2780 pab->ab.EntryCnt = 0;
2781 bit_pos = 0;
2782 if (new_mask)
2783 mask = new_mask;
2784 else
2785 mask = vport->fdmi_port_mask;
2786
2787 /* Mask will dictate what attributes to build in the request */
2788 while (mask) {
2789 if (mask & 0x1) {
2790 func = lpfc_fdmi_port_action[bit_pos];
2791 size += func(vport,
2792 (struct lpfc_fdmi_attr_def *)
2793 ((uint8_t *)pab + size));
2794 pab->ab.EntryCnt++;
2795 if ((size + 256) >
2796 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2797 goto port_out;
2798 }
2799 mask = mask >> 1;
2800 bit_pos++;
2801 }
2802port_out:
2803 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2804 /* Total size */
2805 if (cmdcode == SLI_MGMT_RPRT)
2806 size += sizeof(struct lpfc_name);
2807 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002808 break;
2809
James Smart76b2c342015-04-07 15:07:19 -04002810 case SLI_MGMT_GHAT:
2811 case SLI_MGMT_GRPL:
2812 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002813 case SLI_MGMT_DHBA:
James Smart76b2c342015-04-07 15:07:19 -04002814 case SLI_MGMT_DHAT:
2815 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2816 memcpy((uint8_t *)&pe->PortName,
2817 (uint8_t *)&vport->fc_sparam.portName,
2818 sizeof(struct lpfc_name));
2819 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002820 break;
2821
James Smart76b2c342015-04-07 15:07:19 -04002822 case SLI_MGMT_GPAT:
2823 case SLI_MGMT_GPAS:
2824 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002825 case SLI_MGMT_DPRT:
James Smart76b2c342015-04-07 15:07:19 -04002826 case SLI_MGMT_DPA:
2827 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2828 memcpy((uint8_t *)&pe->PortName,
2829 (uint8_t *)&vport->fc_sparam.portName,
2830 sizeof(struct lpfc_name));
2831 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002832 break;
James Smart76b2c342015-04-07 15:07:19 -04002833 case SLI_MGMT_GRHL:
2834 size = GID_REQUEST_SZ - 4;
2835 break;
2836 default:
2837 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2838 "0298 FDMI cmdcode x%x not supported\n",
2839 cmdcode);
2840 goto fdmi_cmd_free_bmpvirt;
dea31012005-04-17 16:05:31 -05002841 }
James Smart76b2c342015-04-07 15:07:19 -04002842 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
dea31012005-04-17 16:05:31 -05002843
James Smart76b2c342015-04-07 15:07:19 -04002844 bpl = (struct ulp_bde64 *)bmp->virt;
2845 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2846 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
dea31012005-04-17 16:05:31 -05002847 bpl->tus.f.bdeFlags = 0;
2848 bpl->tus.f.bdeSize = size;
dea31012005-04-17 16:05:31 -05002849
James Smart76b2c342015-04-07 15:07:19 -04002850 /*
2851 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
James Smarte47c9092008-02-08 18:49:26 -05002852 * to hold ndlp reference for the corresponding callback function.
2853 */
James Smart76b2c342015-04-07 15:07:19 -04002854 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
dea31012005-04-17 16:05:31 -05002855 return 0;
2856
James Smart76b2c342015-04-07 15:07:19 -04002857 /*
2858 * Decrement ndlp reference count to release ndlp reference held
James Smarte47c9092008-02-08 18:49:26 -05002859 * for the failed command's callback function.
2860 */
James Smart51ef4c22007-08-02 11:10:31 -04002861 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002862
James Smart76b2c342015-04-07 15:07:19 -04002863fdmi_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05002864 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2865fdmi_cmd_free_bmp:
2866 kfree(bmp);
2867fdmi_cmd_free_mpvirt:
2868 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2869fdmi_cmd_free_mp:
2870 kfree(mp);
2871fdmi_cmd_exit:
2872 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04002873 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2874 "0244 Issue FDMI request failed Data: x%x\n",
2875 cmdcode);
dea31012005-04-17 16:05:31 -05002876 return 1;
2877}
2878
James Smart92494142011-02-16 12:39:44 -05002879/**
2880 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2881 * @ptr - Context object of the timer.
2882 *
2883 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2884 * the worker thread.
2885 **/
2886void
Kees Cookf22eb4d2017-09-06 20:24:26 -07002887lpfc_delayed_disc_tmo(struct timer_list *t)
James Smart92494142011-02-16 12:39:44 -05002888{
Kees Cookf22eb4d2017-09-06 20:24:26 -07002889 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
James Smart92494142011-02-16 12:39:44 -05002890 struct lpfc_hba *phba = vport->phba;
2891 uint32_t tmo_posted;
2892 unsigned long iflag;
2893
2894 spin_lock_irqsave(&vport->work_port_lock, iflag);
2895 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2896 if (!tmo_posted)
2897 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2898 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2899
2900 if (!tmo_posted)
2901 lpfc_worker_wake_up(phba);
2902 return;
2903}
2904
2905/**
2906 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2907 * handle delayed discovery.
2908 * @vport: pointer to a host virtual N_Port data structure.
2909 *
2910 * This function start nport discovery of the vport.
2911 **/
2912void
2913lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2914{
2915 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2916
2917 spin_lock_irq(shost->host_lock);
2918 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2919 spin_unlock_irq(shost->host_lock);
2920 return;
2921 }
2922 vport->fc_flag &= ~FC_DISC_DELAYED;
2923 spin_unlock_irq(shost->host_lock);
2924
2925 lpfc_do_scr_ns_plogi(vport->phba, vport);
2926}
2927
dea31012005-04-17 16:05:31 -05002928void
James Smart2e0fef82007-06-17 19:56:36 -05002929lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05002930{
2931 struct lpfc_sli *psli = &phba->sli;
2932 lpfc_vpd_t *vp = &phba->vpd;
2933 uint32_t b1, b2, b3, b4, i, rev;
2934 char c;
2935 uint32_t *ptr, str[4];
2936 uint8_t *fwname;
2937
James Smartf1126682009-06-10 17:22:44 -04002938 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart6b5151f2012-01-18 16:24:06 -05002939 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
James Smartf1126682009-06-10 17:22:44 -04002940 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04002941 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002942 rev = vp->rev.sli2FwRev;
2943 else
2944 rev = vp->rev.sli1FwRev;
2945
2946 b1 = (rev & 0x0000f000) >> 12;
2947 b2 = (rev & 0x00000f00) >> 8;
2948 b3 = (rev & 0x000000c0) >> 6;
2949 b4 = (rev & 0x00000030) >> 4;
2950
2951 switch (b4) {
2952 case 0:
2953 c = 'N';
2954 break;
2955 case 1:
2956 c = 'A';
2957 break;
2958 case 2:
2959 c = 'B';
2960 break;
James Smart73d91e52011-10-10 21:32:10 -04002961 case 3:
2962 c = 'X';
2963 break;
dea31012005-04-17 16:05:31 -05002964 default:
2965 c = 0;
2966 break;
2967 }
2968 b4 = (rev & 0x0000000f);
2969
James Smartf4b4c682009-05-22 14:53:12 -04002970 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002971 fwname = vp->rev.sli2FwName;
2972 else
2973 fwname = vp->rev.sli1FwName;
2974
2975 for (i = 0; i < 16; i++)
2976 if (fwname[i] == 0x20)
2977 fwname[i] = 0;
2978
2979 ptr = (uint32_t*)fwname;
2980
2981 for (i = 0; i < 3; i++)
2982 str[i] = be32_to_cpu(*ptr++);
2983
2984 if (c == 0) {
2985 if (flag)
2986 sprintf(fwrevision, "%d.%d%d (%s)",
2987 b1, b2, b3, (char *)str);
2988 else
2989 sprintf(fwrevision, "%d.%d%d", b1,
2990 b2, b3);
2991 } else {
2992 if (flag)
2993 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
2994 b1, b2, b3, c,
2995 b4, (char *)str);
2996 else
2997 sprintf(fwrevision, "%d.%d%d%c%d",
2998 b1, b2, b3, c, b4);
2999 }
3000 } else {
3001 rev = vp->rev.smFwRev;
3002
3003 b1 = (rev & 0xff000000) >> 24;
3004 b2 = (rev & 0x00f00000) >> 20;
3005 b3 = (rev & 0x000f0000) >> 16;
3006 c = (rev & 0x0000ff00) >> 8;
3007 b4 = (rev & 0x000000ff);
3008
Roel Kluind44a6d22010-01-17 16:15:57 +01003009 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05003010 }
3011 return;
3012}