blob: d4a200ae5a6fcaa08fd0d7a99e5860cea8672854 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartcf8037f2018-02-22 08:18:52 -08004 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
James Smartd080abe2017-02-12 13:52:39 -08005 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
dea31012005-04-17 16:05:31 -05009 * *
10 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
dea31012005-04-17 16:05:31 -050021 *******************************************************************/
22
23/*
James Smart09372822008-01-11 01:52:54 -050024 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea31012005-04-17 16:05:31 -050025 */
26
27#include <linux/blkdev.h>
28#include <linux/pci.h>
29#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050031#include <linux/utsname.h>
32
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040036#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040037#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050038
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_hw.h"
41#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040043#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050044#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc.h"
James Smarta0f2d3e2017-02-12 13:52:31 -080046#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
50#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050051#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050052#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050053
James Smarta085e872015-12-16 18:12:02 -050054/* FDMI Port Speed definitions - FC-GS-7 */
55#define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
56#define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
57#define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
58#define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
59#define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
60#define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
61#define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
62#define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
63#define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
64#define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
65#define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
66#define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
67#define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
68#define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
69#define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
70#define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
71#define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
72#define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
73#define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
dea31012005-04-17 16:05:31 -050074
75#define FOURBYTES 4
76
77
78static char *lpfc_release_version = LPFC_DRIVER_VERSION;
79
James Smarted957682007-06-17 19:56:37 -050080static void
81lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050082 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050083{
James Smarted957682007-06-17 19:56:37 -050084 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050085 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040086 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050087 "status = x%x\n",
88 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050089 }
James Smart9c2face2008-01-11 01:53:18 -050090 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
92 "status = x%x\n",
93 size, piocbq->iocb.ulpStatus);
94}
95
96static void
97lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
99{
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -0500101}
102
dea31012005-04-17 16:05:31 -0500103void
James Smart2e0fef82007-06-17 19:56:36 -0500104lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -0500106{
James Smarted957682007-06-17 19:56:37 -0500107 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -0500108 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -0500109 int i;
110 struct lpfc_iocbq *iocbq;
111 dma_addr_t paddr;
112 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -0500113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -0500115
James Smart4fede782010-01-26 23:08:55 -0500116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
117 return;
James Smartf1c3b0f2009-07-19 10:01:32 -0400118
James Smart92d7f7b2007-06-17 19:56:38 -0500119 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
120 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
121 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500124 /* Not enough posted buffers; Try posting more buffers */
125 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400127 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500128 return;
129 }
130
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
133 */
134 if (icmd->ulpBdeCount == 0)
135 return;
136
James Smarted957682007-06-17 19:56:37 -0500137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500141 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500142 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500143 continue;
James Smart9c2face2008-01-11 01:53:18 -0500144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500146 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500149 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500150 bdeBuf = iocbq->context3;
151 iocbq->context3 = NULL;
152 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
153 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
154 size);
155 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500156 }
dea31012005-04-17 16:05:31 -0500157 }
James Smart9c2face2008-01-11 01:53:18 -0500158 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500159 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500163 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500164 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500166 for (i = 0; i < icmd->ulpBdeCount; i++) {
167 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
168 icmd->un.cont64[i].addrLow);
169 mp = lpfc_sli_ringpostbuf_get(phba, pring,
170 paddr);
171 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500173 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500174 }
James Smart495a7142008-06-14 22:52:59 -0400175 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500176 }
James Smartd7c255b2008-08-24 21:50:00 -0400177 list_del(&head);
dea31012005-04-17 16:05:31 -0500178 }
dea31012005-04-17 16:05:31 -0500179}
180
James Smart6669f9b2009-10-02 15:16:45 -0400181/**
James Smart6dd9e312013-01-03 15:43:37 -0500182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
James Smart6669f9b2009-10-02 15:16:45 -0400183 * @phba: Pointer to HBA context object.
James Smart6dd9e312013-01-03 15:43:37 -0500184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
James Smart6669f9b2009-10-02 15:16:45 -0400185 *
James Smart6dd9e312013-01-03 15:43:37 -0500186 * This function serves as the upper level protocol abort handler for CT
187 * protocol.
188 *
189 * Return 1 if abort has been handled, 0 otherwise.
James Smart6669f9b2009-10-02 15:16:45 -0400190 **/
James Smart6dd9e312013-01-03 15:43:37 -0500191int
192lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
James Smart6669f9b2009-10-02 15:16:45 -0400193{
James Smart6dd9e312013-01-03 15:43:37 -0500194 int handled;
James Smart6669f9b2009-10-02 15:16:45 -0400195
James Smart6dd9e312013-01-03 15:43:37 -0500196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
James Smart6669f9b2009-10-02 15:16:45 -0400198
James Smart6dd9e312013-01-03 15:43:37 -0500199 return handled;
James Smart6669f9b2009-10-02 15:16:45 -0400200}
201
dea31012005-04-17 16:05:31 -0500202static void
James Smart2e0fef82007-06-17 19:56:36 -0500203lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500204{
205 struct lpfc_dmabuf *mlast, *next_mlast;
206
207 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
208 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
209 list_del(&mlast->list);
210 kfree(mlast);
211 }
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
213 kfree(mlist);
214 return;
215}
216
217static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500218lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500219 uint32_t size, int *entries)
220{
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
223 int cnt, i = 0;
224
James Smart09372822008-01-11 01:52:54 -0500225 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
227
228 while (size) {
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
231 if (!mp) {
232 if (mlist)
233 lpfc_free_ct_rsp(phba, mlist);
234 return NULL;
235 }
236
237 INIT_LIST_HEAD(&mp->list);
238
James Smart92d7f7b2007-06-17 19:56:38 -0500239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500241 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
242 else
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
244
245 if (!mp->virt) {
246 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700247 if (mlist)
248 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500249 return NULL;
250 }
251
252 /* Queue it to a linked list */
253 if (!mlist)
254 mlist = mp;
255 else
256 list_add_tail(&mp->list, &mlist->list);
257
James Smart34b02dc2008-08-24 21:49:55 -0400258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500259 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500262 bpl->tus.f.bdeSize = (uint16_t) cnt;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264 bpl++;
265
266 i++;
267 size -= cnt;
268 }
269
270 *entries = i;
271 return mlist;
272}
273
James Smart858c9f62007-06-17 19:56:39 -0500274int
275lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
276{
277 struct lpfc_dmabuf *buf_ptr;
278
James Smart51ef4c22007-08-02 11:10:31 -0400279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
282 }
James Smart858c9f62007-06-17 19:56:39 -0500283 if (ctiocb->context1) {
284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
286 kfree(buf_ptr);
287 ctiocb->context1 = NULL;
288 }
289 if (ctiocb->context2) {
290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
291 ctiocb->context2 = NULL;
292 }
293
294 if (ctiocb->context3) {
295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
297 kfree(buf_ptr);
Felipe Pena1109c942013-10-15 21:29:50 -0300298 ctiocb->context3 = NULL;
James Smart858c9f62007-06-17 19:56:39 -0500299 }
300 lpfc_sli_release_iocbq(phba, ctiocb);
301 return 0;
302}
303
James Smart4258e982015-12-16 18:11:58 -0500304/**
305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
306 * @vport: pointer to a host virtual N_Port data structure.
307 * @bmp: Pointer to BPL for SLI command
308 * @inp: Pointer to data buffer for response data.
309 * @outp: Pointer to data buffer that hold the CT command.
310 * @cmpl: completion routine to call when command completes
311 * @ndlp: Destination NPort nodelist entry
312 *
313 * This function as the final part for issuing a CT command.
314 */
dea31012005-04-17 16:05:31 -0500315static int
James Smart2e0fef82007-06-17 19:56:36 -0500316lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500317 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
319 struct lpfc_iocbq *),
320 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500321 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500322{
James Smart2e0fef82007-06-17 19:56:36 -0500323 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500324 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400325 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500326 int rc;
dea31012005-04-17 16:05:31 -0500327
328 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400329 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500330
331 if (geniocb == NULL)
332 return 1;
dea31012005-04-17 16:05:31 -0500333
334 icmd = &geniocb->iocb;
335 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
336 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
337 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart4258e982015-12-16 18:11:58 -0500339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500340
341 if (usr_flg)
342 geniocb->context3 = NULL;
343 else
344 geniocb->context3 = (uint8_t *) bmp;
345
346 /* Save for completion so we can release these resources */
347 geniocb->context1 = (uint8_t *) inp;
348 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500350
351 /* Fill in payload, bp points to frame payload */
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
353
354 /* Fill in rest of iocb */
355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
356 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
James Smart6a9c52c2009-10-02 15:16:51 -0400357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -0500359
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500360 if (!tmo) {
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
363 }
dea31012005-04-17 16:05:31 -0500364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
366 icmd->ulpLe = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -0400369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea31012005-04-17 16:05:31 -0500371
James Smart92d7f7b2007-06-17 19:56:38 -0500372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373 /* For GEN_REQUEST64_CR, use the RPI */
374 icmd->ulpCt_h = 0;
375 icmd->ulpCt_l = 0;
376 }
377
dea31012005-04-17 16:05:31 -0500378 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
380 "0119 Issue GEN REQ IOCB to NPORT x%x "
381 "Data: x%x x%x\n",
382 ndlp->nlp_DID, icmd->ulpIoTag,
383 vport->port_state);
dea31012005-04-17 16:05:31 -0500384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500386 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500387 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500389
390 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500391 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500392 return 1;
393 }
dea31012005-04-17 16:05:31 -0500394
395 return 0;
396}
397
James Smart4258e982015-12-16 18:11:58 -0500398/**
399 * lpfc_ct_cmd - Build and issue a CT command
400 * @vport: pointer to a host virtual N_Port data structure.
401 * @inmp: Pointer to data buffer for response data.
402 * @bmp: Pointer to BPL for SLI command
403 * @ndlp: Destination NPort nodelist entry
404 * @cmpl: completion routine to call when command completes
405 *
406 * This function is called for issuing a CT command.
407 */
dea31012005-04-17 16:05:31 -0500408static int
James Smart2e0fef82007-06-17 19:56:36 -0500409lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500413 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500414{
James Smart2e0fef82007-06-17 19:56:36 -0500415 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
417 struct lpfc_dmabuf *outmp;
418 int cnt = 0, status;
419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
420 CommandResponse.bits.CmdRsp;
421
422 bpl++; /* Skip past ct request */
423
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
426 if (!outmp)
427 return -ENOMEM;
James Smart6a9c52c2009-10-02 15:16:51 -0400428 /*
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
431 * lpfc_alloc_ct_rsp.
432 */
433 cnt += 1;
James Smart2e0fef82007-06-17 19:56:36 -0500434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart6a9c52c2009-10-02 15:16:51 -0400435 cnt, 0, retry);
dea31012005-04-17 16:05:31 -0500436 if (status) {
437 lpfc_free_ct_rsp(phba, outmp);
438 return -ENOMEM;
439 }
440 return 0;
441}
442
James Smart549e55c2007-08-02 11:09:51 -0400443struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500444lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500445 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400446 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500447
James Smart549e55c2007-08-02 11:09:51 -0400448 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500452 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400453 }
James Smart92d7f7b2007-06-17 19:56:38 -0500454 }
James Smart549e55c2007-08-02 11:09:51 -0400455 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500456 return NULL;
457}
458
James Smarta0f2d3e2017-02-12 13:52:31 -0800459static void
460lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
461{
462 struct lpfc_nodelist *ndlp;
463
464 if ((vport->port_type != LPFC_NPIV_PORT) ||
465 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
466
467 ndlp = lpfc_setup_disc_node(vport, Did);
468
469 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smartbd2cdd52017-02-12 13:52:33 -0800470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
471 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
472 Did, ndlp->nlp_flag, vport->fc_flag);
473
James Smartb0a00d82018-04-09 14:24:32 -0700474 /* Don't assume the rport is always the previous
475 * FC4 type.
476 */
477 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
478
James Smarta0f2d3e2017-02-12 13:52:31 -0800479 /* By default, the driver expects to support FCP FC4 */
480 if (fc4_type == FC_TYPE_FCP)
481 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
482
483 if (fc4_type == FC_TYPE_NVME)
484 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
485
486 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
487 "0238 Process x%06x NameServer Rsp "
488 "Data: x%x x%x x%x x%x\n", Did,
489 ndlp->nlp_flag, ndlp->nlp_fc4_type,
490 vport->fc_flag,
491 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800492 } else {
493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
494 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
495 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
496
James Smarta0f2d3e2017-02-12 13:52:31 -0800497 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
498 "0239 Skip x%06x NameServer Rsp "
499 "Data: x%x x%x\n", Did,
500 vport->fc_flag,
501 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800502 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800503 } else {
504 if (!(vport->fc_flag & FC_RSCN_MODE) ||
505 lpfc_rscn_payload_check(vport, Did)) {
James Smartbd2cdd52017-02-12 13:52:33 -0800506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
507 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
508 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
509
James Smarta0f2d3e2017-02-12 13:52:31 -0800510 /*
James Smartb57ab7462017-06-01 21:07:08 -0700511 * This NPortID was previously a FCP/NVMe target,
James Smarta0f2d3e2017-02-12 13:52:31 -0800512 * Don't even bother to send GFF_ID.
513 */
514 ndlp = lpfc_findnode_did(vport, Did);
James Smartb57ab7462017-06-01 21:07:08 -0700515 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
516 (ndlp->nlp_type &
517 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
518 if (fc4_type == FC_TYPE_FCP)
519 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
520 if (fc4_type == FC_TYPE_NVME)
521 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
522 lpfc_setup_disc_node(vport, Did);
523 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
524 0, Did) == 0)
525 vport->num_disc_nodes++;
526 else
527 lpfc_setup_disc_node(vport, Did);
James Smartbd2cdd52017-02-12 13:52:33 -0800528 } else {
529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
530 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
531 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
532
James Smarta0f2d3e2017-02-12 13:52:31 -0800533 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
534 "0245 Skip x%06x NameServer Rsp "
535 "Data: x%x x%x\n", Did,
536 vport->fc_flag,
537 vport->fc_rscn_id_cnt);
James Smartbd2cdd52017-02-12 13:52:33 -0800538 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800539 }
540}
541
James Smart1c5b12f2017-04-21 16:05:03 -0700542static void
543lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
544{
545 struct lpfc_hba *phba = vport->phba;
546 struct lpfc_nodelist *ndlp = NULL;
547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
548
549 /*
550 * To conserve rpi's, filter out addresses for other
551 * vports on the same physical HBAs.
552 */
553 if (Did != vport->fc_myDID &&
554 (!lpfc_find_vport_by_did(phba, Did) ||
555 vport->cfg_peer_port_login)) {
556 if (!phba->nvmet_support) {
557 /* FCPI/NVMEI path. Process Did */
558 lpfc_prep_node_fc4type(vport, Did, fc4_type);
559 return;
560 }
561 /* NVMET path. NVMET only cares about NVMEI nodes. */
562 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
563 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
564 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
565 continue;
566 spin_lock_irq(shost->host_lock);
567 if (ndlp->nlp_DID == Did)
568 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
569 else
570 ndlp->nlp_flag |= NLP_NVMET_RECOV;
571 spin_unlock_irq(shost->host_lock);
572 }
573 }
574}
575
dea31012005-04-17 16:05:31 -0500576static int
James Smarta0f2d3e2017-02-12 13:52:31 -0800577lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
578 uint32_t Size)
dea31012005-04-17 16:05:31 -0500579{
580 struct lpfc_sli_ct_request *Response =
581 (struct lpfc_sli_ct_request *) mp->virt;
dea31012005-04-17 16:05:31 -0500582 struct lpfc_dmabuf *mlast, *next_mp;
583 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500584 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500585 int Cnt;
586 struct list_head head;
James Smart1c5b12f2017-04-21 16:05:03 -0700587 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
588 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -0500589
James Smart2e0fef82007-06-17 19:56:36 -0500590 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500591 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500592 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500593
dea31012005-04-17 16:05:31 -0500594
595 list_add_tail(&head, &mp->list);
596 list_for_each_entry_safe(mp, next_mp, &head, list) {
597 mlast = mp;
598
James Smart7054a602007-04-25 09:52:34 -0400599 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
600
dea31012005-04-17 16:05:31 -0500601 Size -= Cnt;
602
James Smart1dcb58e2007-04-25 09:51:30 -0400603 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500604 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400605 } else
dea31012005-04-17 16:05:31 -0500606 Cnt -= 16; /* subtract length of CT header */
607
608 /* Loop through entire NameServer list of DIDs */
James Smart4258e982015-12-16 18:11:58 -0500609 while (Cnt >= sizeof(uint32_t)) {
dea31012005-04-17 16:05:31 -0500610 /* Get next DID from NameServer List */
611 CTentry = *ctptr++;
612 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart1c5b12f2017-04-21 16:05:03 -0700613 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
James Smart76b2c342015-04-07 15:07:19 -0400614 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
dea31012005-04-17 16:05:31 -0500615 goto nsout1;
James Smarta0f2d3e2017-02-12 13:52:31 -0800616
James Smart4258e982015-12-16 18:11:58 -0500617 Cnt -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -0500618 }
619 ctptr = NULL;
620
621 }
622
James Smart1c5b12f2017-04-21 16:05:03 -0700623 /* All GID_FT entries processed. If the driver is running in
624 * in target mode, put impacted nodes into recovery and drop
625 * the RPI to flush outstanding IO.
626 */
627 if (vport->phba->nvmet_support) {
628 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
629 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
630 continue;
631 lpfc_disc_state_machine(vport, ndlp, NULL,
632 NLP_EVT_DEVICE_RECOVERY);
633 spin_lock_irq(shost->host_lock);
634 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
Dan Carpenter0d618cf2017-05-04 00:22:16 +0300635 spin_unlock_irq(shost->host_lock);
James Smart1c5b12f2017-04-21 16:05:03 -0700636 }
637 }
638
dea31012005-04-17 16:05:31 -0500639nsout1:
640 list_del(&head);
dea31012005-04-17 16:05:31 -0500641 return 0;
642}
643
dea31012005-04-17 16:05:31 -0500644static void
James Smart2e0fef82007-06-17 19:56:36 -0500645lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
646 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500647{
James Smart2e0fef82007-06-17 19:56:36 -0500648 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500650 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500651 struct lpfc_dmabuf *outp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800652 struct lpfc_dmabuf *inp;
dea31012005-04-17 16:05:31 -0500653 struct lpfc_sli_ct_request *CTrsp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800654 struct lpfc_sli_ct_request *CTreq;
James Smart51ef4c22007-08-02 11:10:31 -0400655 struct lpfc_nodelist *ndlp;
James Smarta0f2d3e2017-02-12 13:52:31 -0800656 int rc, type;
dea31012005-04-17 16:05:31 -0500657
James Smart51ef4c22007-08-02 11:10:31 -0400658 /* First save ndlp, before we overwrite it */
659 ndlp = cmdiocb->context_un.ndlp;
660
dea31012005-04-17 16:05:31 -0500661 /* we pass cmdiocb to state machine which needs rspiocb as well */
662 cmdiocb->context_un.rsp_iocb = rspiocb;
James Smarta0f2d3e2017-02-12 13:52:31 -0800663 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -0500664 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
James Smart858c9f62007-06-17 19:56:39 -0500665 irsp = &rspiocb->iocb;
666
667 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
668 "GID_FT cmpl: status:x%x/x%x rtry:%d",
669 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500670
James Smart92d7f7b2007-06-17 19:56:38 -0500671 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500672 if (vport->load_flag & FC_UNLOADING) {
673 if (vport->fc_flag & FC_RSCN_MODE)
674 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500675 goto out;
James Smarteada2722008-12-04 22:39:13 -0500676 }
James Smart92d7f7b2007-06-17 19:56:38 -0500677
James Smart58da1ff2008-04-07 10:15:56 -0400678 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400679 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
680 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500681 if (vport->fc_flag & FC_RSCN_MODE)
682 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500683 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
684 goto out;
685 }
James Smart58da1ff2008-04-07 10:15:56 -0400686 if (lpfc_error_lost_link(irsp)) {
687 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
688 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500689 if (vport->fc_flag & FC_RSCN_MODE)
690 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400691 goto out;
692 }
James Smart49382502017-11-20 16:00:38 -0800693
694 spin_lock_irq(shost->host_lock);
695 if (vport->fc_flag & FC_RSCN_DEFERRED) {
696 vport->fc_flag &= ~FC_RSCN_DEFERRED;
697 spin_unlock_irq(shost->host_lock);
698
James Smartb04744c2018-04-09 14:24:29 -0700699 /* This is a GID_FT completing so the gidft_inp counter was
700 * incremented before the GID_FT was issued to the wire.
701 */
702 vport->gidft_inp--;
703
James Smart49382502017-11-20 16:00:38 -0800704 /*
705 * Skip processing the NS response
706 * Re-issue the NS cmd
707 */
708 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
709 "0151 Process Deferred RSCN Data: x%x x%x\n",
710 vport->fc_flag, vport->fc_rscn_id_cnt);
711 lpfc_els_handle_rscn(vport);
712
713 goto out;
714 }
715 spin_unlock_irq(shost->host_lock);
716
James Smart858c9f62007-06-17 19:56:39 -0500717 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500718 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500719 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400720 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
James Smartedb22f02012-10-31 14:45:21 -0400721 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
James Smarte3d2b802012-08-14 14:25:43 -0400722 IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500723 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500724
James Smarta0f2d3e2017-02-12 13:52:31 -0800725 type = lpfc_get_gidft_type(vport, cmdiocb);
726 if (type == 0)
727 goto out;
728
James Smart58da1ff2008-04-07 10:15:56 -0400729 /* CT command is being retried */
James Smarta0f2d3e2017-02-12 13:52:31 -0800730 vport->gidft_inp--;
James Smart58da1ff2008-04-07 10:15:56 -0400731 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smarta0f2d3e2017-02-12 13:52:31 -0800732 vport->fc_ns_retry, type);
James Smart58da1ff2008-04-07 10:15:56 -0400733 if (rc == 0)
734 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500735 }
James Smarteada2722008-12-04 22:39:13 -0500736 if (vport->fc_flag & FC_RSCN_MODE)
737 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500738 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400739 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
740 "0257 GID_FT Query error: 0x%x 0x%x\n",
741 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500742 } else {
743 /* Good status, continue checking */
James Smarta0f2d3e2017-02-12 13:52:31 -0800744 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
dea31012005-04-17 16:05:31 -0500745 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
746 if (CTrsp->CommandResponse.bits.CmdRsp ==
James Smart76b2c342015-04-07 15:07:19 -0400747 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400748 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800749 "0208 NameServer Rsp Data: x%x x%x\n",
750 vport->fc_flag,
751 CTreq->un.gid.Fc4Type);
752
753 lpfc_ns_rsp(vport,
754 outp,
755 CTreq->un.gid.Fc4Type,
dea31012005-04-17 16:05:31 -0500756 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
757 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
758 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
759 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400760 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
761 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400762 lpfc_printf_vlog(vport, KERN_INFO,
763 LOG_DISCOVERY,
764 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400765 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400766 CTrsp->CommandResponse.bits.CmdRsp,
767 (uint32_t) CTrsp->ReasonCode,
768 (uint32_t) CTrsp->Explanation,
769 vport->fc_flag);
770
771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
772 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
773 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
774 (uint32_t) CTrsp->ReasonCode,
775 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400776 } else {
777 lpfc_printf_vlog(vport, KERN_INFO,
778 LOG_DISCOVERY,
779 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500780 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500781 CTrsp->CommandResponse.bits.CmdRsp,
782 (uint32_t) CTrsp->ReasonCode,
783 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500784 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500785
James Smarta58cbd52007-08-02 11:09:43 -0400786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500787 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
788 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
789 (uint32_t) CTrsp->ReasonCode,
790 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400791 }
792
James Smart858c9f62007-06-17 19:56:39 -0500793
dea31012005-04-17 16:05:31 -0500794 } else {
795 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400796 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
797 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500798 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500799 CTrsp->CommandResponse.bits.CmdRsp,
800 (uint32_t) CTrsp->ReasonCode,
801 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500802 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500803
804 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
805 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
806 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
807 (uint32_t) CTrsp->ReasonCode,
808 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500809 }
James Smarta0f2d3e2017-02-12 13:52:31 -0800810 vport->gidft_inp--;
dea31012005-04-17 16:05:31 -0500811 }
812 /* Link up / RSCN discovery */
James Smarta0f2d3e2017-02-12 13:52:31 -0800813 if ((vport->num_disc_nodes == 0) &&
814 (vport->gidft_inp == 0)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500815 /*
816 * The driver has cycled through all Nports in the RSCN payload.
817 * Complete the handling by cleaning up and marking the
818 * current driver state.
819 */
820 if (vport->port_state >= LPFC_DISC_AUTH) {
821 if (vport->fc_flag & FC_RSCN_MODE) {
822 lpfc_els_flush_rscn(vport);
823 spin_lock_irq(shost->host_lock);
824 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
825 spin_unlock_irq(shost->host_lock);
826 }
827 else
828 lpfc_els_flush_rscn(vport);
829 }
830
831 lpfc_disc_start(vport);
832 }
dea31012005-04-17 16:05:31 -0500833out:
James Smart51ef4c22007-08-02 11:10:31 -0400834 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500835 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500836 return;
837}
838
James Smart311464e2007-08-02 11:10:37 -0400839static void
James Smart92d7f7b2007-06-17 19:56:38 -0500840lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
841 struct lpfc_iocbq *rspiocb)
842{
843 struct lpfc_vport *vport = cmdiocb->vport;
844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
845 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500846 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
847 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
848 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500849 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500850 uint8_t fbits;
851 struct lpfc_nodelist *ndlp;
852
853 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
854 did = be32_to_cpu(did);
855
James Smart858c9f62007-06-17 19:56:39 -0500856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
857 "GFF_ID cmpl: status:x%x/x%x did:x%x",
858 irsp->ulpStatus, irsp->un.ulpWord[4], did);
859
James Smart92d7f7b2007-06-17 19:56:38 -0500860 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
861 /* Good status, continue checking */
862 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
863 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
864
865 if (CTrsp->CommandResponse.bits.CmdRsp ==
866 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
867 if ((fbits & FC4_FEATURE_INIT) &&
868 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400869 lpfc_printf_vlog(vport, KERN_INFO,
870 LOG_DISCOVERY,
871 "0270 Skip x%x GFF "
872 "NameServer Rsp Data: (init) "
873 "x%x x%x\n", did, fbits,
874 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500875 goto out;
876 }
877 }
878 }
James Smart858c9f62007-06-17 19:56:39 -0500879 else {
James Smart0ff10d42008-01-11 01:52:36 -0500880 /* Check for retry */
881 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
882 retry = 1;
883 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
James Smarte3d2b802012-08-14 14:25:43 -0400884 switch ((irsp->un.ulpWord[4] &
885 IOERR_PARAM_MASK)) {
886
James Smart0ff10d42008-01-11 01:52:36 -0500887 case IOERR_NO_RESOURCES:
888 /* We don't increment the retry
889 * count for this case.
890 */
891 break;
892 case IOERR_LINK_DOWN:
893 case IOERR_SLI_ABORTED:
894 case IOERR_SLI_DOWN:
895 retry = 0;
896 break;
897 default:
898 cmdiocb->retry++;
899 }
900 }
901 else
902 cmdiocb->retry++;
903
904 if (retry) {
905 /* CT command is being retried */
906 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
907 cmdiocb->retry, did);
908 if (rc == 0) {
909 /* success */
910 lpfc_ct_free_iocb(phba, cmdiocb);
911 return;
912 }
913 }
914 }
James Smarte8b62012007-08-02 11:10:09 -0400915 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
916 "0267 NameServer GFF Rsp "
917 "x%x Error (%d %d) Data: x%x x%x\n",
918 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500919 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500920 }
921
James Smart92d7f7b2007-06-17 19:56:38 -0500922 /* This is a target port, unregistered port, or the GFF_ID failed */
923 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400924 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400925 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
926 "0242 Process x%x GFF "
927 "NameServer Rsp Data: x%x x%x x%x\n",
928 did, ndlp->nlp_flag, vport->fc_flag,
929 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500930 } else {
James Smarte8b62012007-08-02 11:10:09 -0400931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
932 "0243 Skip x%x GFF "
933 "NameServer Rsp Data: x%x x%x\n", did,
934 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500935 }
936out:
937 /* Link up / RSCN discovery */
938 if (vport->num_disc_nodes)
939 vport->num_disc_nodes--;
940 if (vport->num_disc_nodes == 0) {
941 /*
942 * The driver has cycled through all Nports in the RSCN payload.
943 * Complete the handling by cleaning up and marking the
944 * current driver state.
945 */
946 if (vport->port_state >= LPFC_DISC_AUTH) {
947 if (vport->fc_flag & FC_RSCN_MODE) {
948 lpfc_els_flush_rscn(vport);
949 spin_lock_irq(shost->host_lock);
950 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
951 spin_unlock_irq(shost->host_lock);
952 }
953 else
954 lpfc_els_flush_rscn(vport);
955 }
956 lpfc_disc_start(vport);
957 }
James Smart858c9f62007-06-17 19:56:39 -0500958 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500959 return;
960}
961
James Smarta0f2d3e2017-02-12 13:52:31 -0800962static void
963lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
964 struct lpfc_iocbq *rspiocb)
965{
966 struct lpfc_vport *vport = cmdiocb->vport;
967 IOCB_t *irsp = &rspiocb->iocb;
968 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
969 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
970 struct lpfc_sli_ct_request *CTrsp;
971 int did;
972 struct lpfc_nodelist *ndlp;
973 uint32_t fc4_data_0, fc4_data_1;
974
975 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
976 did = be32_to_cpu(did);
977
James Smartbd2cdd52017-02-12 13:52:33 -0800978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
979 "GFT_ID cmpl: status:x%x/x%x did:x%x",
980 irsp->ulpStatus, irsp->un.ulpWord[4], did);
981
James Smarta0f2d3e2017-02-12 13:52:31 -0800982 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
983 /* Good status, continue checking */
984 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
985 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
986 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
Dick Kennedyffb70cd2017-08-23 16:55:34 -0700987 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -0800988 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
989 did, fc4_data_0, fc4_data_1);
990
991 ndlp = lpfc_findnode_did(vport, did);
992 if (ndlp) {
993 /* The bitmask value for FCP and NVME FCP types is
994 * the same because they are 32 bits distant from
995 * each other in word0 and word0.
996 */
997 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
998 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
999 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1000 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
Dick Kennedyffb70cd2017-08-23 16:55:34 -07001001 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -08001002 "3064 Setting ndlp %p, DID x%06x with "
1003 "FC4 x%08x, Data: x%08x x%08x\n",
1004 ndlp, did, ndlp->nlp_fc4_type,
1005 FC_TYPE_FCP, FC_TYPE_NVME);
James Smartb5ccc7d2017-03-04 09:30:39 -08001006 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
Gustavo A. R. Silvae6ef6a72017-05-23 10:09:28 -05001007
1008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1009 lpfc_issue_els_prli(vport, ndlp, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08001010 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001011 } else
1012 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1013 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1014
1015 lpfc_ct_free_iocb(phba, cmdiocb);
1016}
James Smart92d7f7b2007-06-17 19:56:38 -05001017
dea31012005-04-17 16:05:31 -05001018static void
James Smart7ee5d432007-10-27 13:37:17 -04001019lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1020 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001021{
James Smart92d7f7b2007-06-17 19:56:38 -05001022 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001023 struct lpfc_dmabuf *inp;
1024 struct lpfc_dmabuf *outp;
1025 IOCB_t *irsp;
1026 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -04001027 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05001028 int cmdcode, rc;
1029 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -05001030 uint32_t latt;
dea31012005-04-17 16:05:31 -05001031
James Smart51ef4c22007-08-02 11:10:31 -04001032 /* First save ndlp, before we overwrite it */
1033 ndlp = cmdiocb->context_un.ndlp;
1034
dea31012005-04-17 16:05:31 -05001035 /* we pass cmdiocb to state machine which needs rspiocb as well */
1036 cmdiocb->context_un.rsp_iocb = rspiocb;
1037
1038 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1039 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001040 irsp = &rspiocb->iocb;
1041
James Smart92d7f7b2007-06-17 19:56:38 -05001042 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1043 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -05001044 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1045
James Smart858c9f62007-06-17 19:56:39 -05001046 latt = lpfc_els_chk_latt(vport);
1047
1048 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -04001049 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -04001050 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -04001051 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1052 latt, irsp->ulpStatus,
1053 CTrsp->CommandResponse.bits.CmdRsp,
1054 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -05001055
James Smart858c9f62007-06-17 19:56:39 -05001056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1057 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1058 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1059
James Smart92d7f7b2007-06-17 19:56:38 -05001060 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001061 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smart6e155202013-07-15 18:35:21 -04001062 "0268 NS cmd x%x Error (x%x x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04001063 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001064
James Smart92d7f7b2007-06-17 19:56:38 -05001065 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001066 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1067 IOERR_SLI_DOWN) ||
1068 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1069 IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -05001070 goto out;
1071
1072 retry = cmdiocb->retry;
1073 if (retry >= LPFC_MAX_NS_RETRY)
1074 goto out;
1075
1076 retry++;
James Smarte8b62012007-08-02 11:10:09 -04001077 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04001078 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -05001079 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1080 if (rc == 0)
1081 goto out;
1082 }
1083
1084out:
James Smart51ef4c22007-08-02 11:10:31 -04001085 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -05001086 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001087 return;
1088}
1089
1090static void
James Smart7ee5d432007-10-27 13:37:17 -04001091lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1092 struct lpfc_iocbq *rspiocb)
1093{
1094 IOCB_t *irsp = &rspiocb->iocb;
1095 struct lpfc_vport *vport = cmdiocb->vport;
1096
James Smart98c9ea52007-10-27 13:37:33 -04001097 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1098 struct lpfc_dmabuf *outp;
1099 struct lpfc_sli_ct_request *CTrsp;
1100
1101 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1102 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1103 if (CTrsp->CommandResponse.bits.CmdRsp ==
1104 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1105 vport->ct_flags |= FC_CT_RFT_ID;
1106 }
James Smart7ee5d432007-10-27 13:37:17 -04001107 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1108 return;
1109}
1110
1111static void
James Smart2e0fef82007-06-17 19:56:36 -05001112lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1113 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001114{
James Smart7ee5d432007-10-27 13:37:17 -04001115 IOCB_t *irsp = &rspiocb->iocb;
1116 struct lpfc_vport *vport = cmdiocb->vport;
1117
James Smart98c9ea52007-10-27 13:37:33 -04001118 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1119 struct lpfc_dmabuf *outp;
1120 struct lpfc_sli_ct_request *CTrsp;
1121
1122 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1123 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1124 if (CTrsp->CommandResponse.bits.CmdRsp ==
1125 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1126 vport->ct_flags |= FC_CT_RNN_ID;
1127 }
James Smart7ee5d432007-10-27 13:37:17 -04001128 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001129 return;
1130}
1131
1132static void
James Smart92d7f7b2007-06-17 19:56:38 -05001133lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1134 struct lpfc_iocbq *rspiocb)
1135{
James Smart7ee5d432007-10-27 13:37:17 -04001136 IOCB_t *irsp = &rspiocb->iocb;
1137 struct lpfc_vport *vport = cmdiocb->vport;
1138
James Smart98c9ea52007-10-27 13:37:33 -04001139 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1140 struct lpfc_dmabuf *outp;
1141 struct lpfc_sli_ct_request *CTrsp;
1142
1143 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1144 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1145 if (CTrsp->CommandResponse.bits.CmdRsp ==
1146 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1147 vport->ct_flags |= FC_CT_RSPN_ID;
1148 }
James Smart7ee5d432007-10-27 13:37:17 -04001149 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05001150 return;
1151}
1152
1153static void
James Smart2e0fef82007-06-17 19:56:36 -05001154lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1155 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001156{
James Smart7ee5d432007-10-27 13:37:17 -04001157 IOCB_t *irsp = &rspiocb->iocb;
1158 struct lpfc_vport *vport = cmdiocb->vport;
1159
James Smart98c9ea52007-10-27 13:37:33 -04001160 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1161 struct lpfc_dmabuf *outp;
1162 struct lpfc_sli_ct_request *CTrsp;
1163
1164 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1165 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1166 if (CTrsp->CommandResponse.bits.CmdRsp ==
1167 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1168 vport->ct_flags |= FC_CT_RSNN_NN;
1169 }
James Smart7ee5d432007-10-27 13:37:17 -04001170 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1171 return;
1172}
1173
1174static void
1175lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1176 struct lpfc_iocbq *rspiocb)
1177{
1178 struct lpfc_vport *vport = cmdiocb->vport;
1179
1180 /* even if it fails we will act as though it succeeded. */
1181 vport->ct_flags = 0;
1182 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001183 return;
1184}
1185
James Smart2fb9bd82006-12-02 13:33:57 -05001186static void
James Smart92d7f7b2007-06-17 19:56:38 -05001187lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1188 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001189{
James Smart92d7f7b2007-06-17 19:56:38 -05001190 IOCB_t *irsp = &rspiocb->iocb;
1191 struct lpfc_vport *vport = cmdiocb->vport;
1192
James Smart98c9ea52007-10-27 13:37:33 -04001193 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1194 struct lpfc_dmabuf *outp;
1195 struct lpfc_sli_ct_request *CTrsp;
1196
1197 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1198 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1199 if (CTrsp->CommandResponse.bits.CmdRsp ==
1200 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1201 vport->ct_flags |= FC_CT_RFF_ID;
1202 }
James Smart7ee5d432007-10-27 13:37:17 -04001203 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001204 return;
1205}
1206
James Smarta0f2d3e2017-02-12 13:52:31 -08001207/*
1208 * Although the symbolic port name is thought to be an integer
1209 * as of January 18, 2016, leave it as a string until more of
1210 * the record state becomes defined.
1211 */
James Smart495a7142008-06-14 22:52:59 -04001212int
James Smart92d7f7b2007-06-17 19:56:38 -05001213lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1214 size_t size)
1215{
1216 int n;
James Smart92d7f7b2007-06-17 19:56:38 -05001217
James Smarta0f2d3e2017-02-12 13:52:31 -08001218 /*
1219 * Use the lpfc board number as the Symbolic Port
1220 * Name object. NPIV is not in play so this integer
1221 * value is sufficient and unique per FC-ID.
1222 */
1223 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
James Smart92d7f7b2007-06-17 19:56:38 -05001224 return n;
1225}
1226
James Smarta0f2d3e2017-02-12 13:52:31 -08001227
James Smart92d7f7b2007-06-17 19:56:38 -05001228int
1229lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1230 size_t size)
dea31012005-04-17 16:05:31 -05001231{
James Smart6b5151f2012-01-18 16:24:06 -05001232 char fwrev[FW_REV_STR_SIZE];
James Smart92d7f7b2007-06-17 19:56:38 -05001233 int n;
dea31012005-04-17 16:05:31 -05001234
James Smart92d7f7b2007-06-17 19:56:38 -05001235 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001236
James Smartf0bf5f92015-04-07 15:07:18 -04001237 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
James Smartf0bf5f92015-04-07 15:07:18 -04001238 if (size < n)
1239 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001240
James Smartf0bf5f92015-04-07 15:07:18 -04001241 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
James Smartf0bf5f92015-04-07 15:07:18 -04001242 if (size < n)
1243 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001244
James Smarta0f2d3e2017-02-12 13:52:31 -08001245 n += snprintf(symbol + n, size - n, " DV%s.",
1246 lpfc_release_version);
James Smartf0bf5f92015-04-07 15:07:18 -04001247 if (size < n)
1248 return n;
James Smarta0f2d3e2017-02-12 13:52:31 -08001249
1250 n += snprintf(symbol + n, size - n, " HN:%s.",
1251 init_utsname()->nodename);
1252 if (size < n)
1253 return n;
James Smartf0bf5f92015-04-07 15:07:18 -04001254
1255 /* Note :- OS name is "Linux" */
James Smarta0f2d3e2017-02-12 13:52:31 -08001256 n += snprintf(symbol + n, size - n, " OS:%s\n",
1257 init_utsname()->sysname);
James Smart92d7f7b2007-06-17 19:56:38 -05001258 return n;
dea31012005-04-17 16:05:31 -05001259}
1260
James Smart76b2c342015-04-07 15:07:19 -04001261static uint32_t
1262lpfc_find_map_node(struct lpfc_vport *vport)
1263{
1264 struct lpfc_nodelist *ndlp, *next_ndlp;
1265 struct Scsi_Host *shost;
1266 uint32_t cnt = 0;
1267
1268 shost = lpfc_shost_from_vport(vport);
1269 spin_lock_irq(shost->host_lock);
1270 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1271 if (ndlp->nlp_type & NLP_FABRIC)
1272 continue;
1273 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1274 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1275 cnt++;
1276 }
1277 spin_unlock_irq(shost->host_lock);
1278 return cnt;
1279}
1280
dea31012005-04-17 16:05:31 -05001281/*
James Smarta0f2d3e2017-02-12 13:52:31 -08001282 * This routine will return the FC4 Type associated with the CT
1283 * GID_FT command.
1284 */
1285int
1286lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1287{
1288 struct lpfc_sli_ct_request *CtReq;
1289 struct lpfc_dmabuf *mp;
1290 uint32_t type;
1291
1292 mp = cmdiocb->context1;
1293 if (mp == NULL)
1294 return 0;
1295 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1296 type = (uint32_t)CtReq->un.gid.Fc4Type;
1297 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1298 return 0;
1299 return type;
1300}
1301
1302/*
dea31012005-04-17 16:05:31 -05001303 * lpfc_ns_cmd
1304 * Description:
1305 * Issue Cmd to NameServer
1306 * SLI_CTNS_GID_FT
1307 * LI_CTNS_RFT_ID
1308 */
1309int
James Smart92d7f7b2007-06-17 19:56:38 -05001310lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1311 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001312{
James Smart92d7f7b2007-06-17 19:56:38 -05001313 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001314 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001315 struct lpfc_dmabuf *mp, *bmp;
1316 struct lpfc_sli_ct_request *CtReq;
1317 struct ulp_bde64 *bpl;
1318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1319 struct lpfc_iocbq *) = NULL;
1320 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001321 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001322 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001323
1324 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001325 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1326 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001327 rc=1;
1328 goto ns_cmd_exit;
1329 }
dea31012005-04-17 16:05:31 -05001330
1331 /* fill in BDEs for command */
1332 /* Allocate buffer for command payload */
James Smart4258e982015-12-16 18:11:58 -05001333 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001334 if (!mp) {
1335 rc=2;
dea31012005-04-17 16:05:31 -05001336 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001337 }
dea31012005-04-17 16:05:31 -05001338
1339 INIT_LIST_HEAD(&mp->list);
1340 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001341 if (!mp->virt) {
1342 rc=3;
dea31012005-04-17 16:05:31 -05001343 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001344 }
dea31012005-04-17 16:05:31 -05001345
1346 /* Allocate buffer for Buffer ptr list */
James Smart4258e982015-12-16 18:11:58 -05001347 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001348 if (!bmp) {
1349 rc=4;
dea31012005-04-17 16:05:31 -05001350 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001351 }
dea31012005-04-17 16:05:31 -05001352
1353 INIT_LIST_HEAD(&bmp->list);
1354 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001355 if (!bmp->virt) {
1356 rc=5;
dea31012005-04-17 16:05:31 -05001357 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001358 }
dea31012005-04-17 16:05:31 -05001359
1360 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001361 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
James Smarta0f2d3e2017-02-12 13:52:31 -08001362 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1363 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1364 context);
dea31012005-04-17 16:05:31 -05001365
1366 bpl = (struct ulp_bde64 *) bmp->virt;
1367 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001368 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1369 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001370 bpl->tus.f.bdeFlags = 0;
1371 if (cmdcode == SLI_CTNS_GID_FT)
1372 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001373 else if (cmdcode == SLI_CTNS_GFF_ID)
1374 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
James Smarta0f2d3e2017-02-12 13:52:31 -08001375 else if (cmdcode == SLI_CTNS_GFT_ID)
1376 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001377 else if (cmdcode == SLI_CTNS_RFT_ID)
1378 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1379 else if (cmdcode == SLI_CTNS_RNN_ID)
1380 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001381 else if (cmdcode == SLI_CTNS_RSPN_ID)
1382 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001383 else if (cmdcode == SLI_CTNS_RSNN_NN)
1384 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001385 else if (cmdcode == SLI_CTNS_DA_ID)
1386 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001387 else if (cmdcode == SLI_CTNS_RFF_ID)
1388 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001389 else
1390 bpl->tus.f.bdeSize = 0;
1391 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1392
1393 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
James Smart4258e982015-12-16 18:11:58 -05001394 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
dea31012005-04-17 16:05:31 -05001395 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1396 CtReq->RevisionId.bits.InId = 0;
1397 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1398 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1399 CtReq->CommandResponse.bits.Size = 0;
1400 switch (cmdcode) {
1401 case SLI_CTNS_GID_FT:
1402 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001403 cpu_to_be16(SLI_CTNS_GID_FT);
James Smarta0f2d3e2017-02-12 13:52:31 -08001404 CtReq->un.gid.Fc4Type = context;
1405
James Smart92d7f7b2007-06-17 19:56:38 -05001406 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001407 vport->port_state = LPFC_NS_QRY;
1408 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001409 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1410 rsp_size = FC_MAX_NS_RSP;
1411 break;
1412
James Smart92d7f7b2007-06-17 19:56:38 -05001413 case SLI_CTNS_GFF_ID:
1414 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001415 cpu_to_be16(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001416 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001417 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1418 break;
1419
James Smarta0f2d3e2017-02-12 13:52:31 -08001420 case SLI_CTNS_GFT_ID:
1421 CtReq->CommandResponse.bits.CmdRsp =
1422 cpu_to_be16(SLI_CTNS_GFT_ID);
1423 CtReq->un.gft.PortId = cpu_to_be32(context);
1424 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1425 break;
1426
dea31012005-04-17 16:05:31 -05001427 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001428 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001429 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001430 cpu_to_be16(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001431 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
James Smarta0f2d3e2017-02-12 13:52:31 -08001432
1433 /* Register FC4 FCP type if enabled. */
1434 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1435 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1436 CtReq->un.rft.fcpReg = 1;
1437
1438 /* Register NVME type if enabled. Defined LE and swapped.
1439 * rsvd[0] is used as word1 because of the hard-coded
1440 * word0 usage in the ct_request data structure.
1441 */
1442 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1443 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1444 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1445
dea31012005-04-17 16:05:31 -05001446 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1447 break;
1448
1449 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001450 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001451 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001452 cpu_to_be16(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001453 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001454 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001455 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001456 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1457 break;
1458
James Smart92d7f7b2007-06-17 19:56:38 -05001459 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001460 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001461 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001462 cpu_to_be16(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001463 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001464 size = sizeof(CtReq->un.rspn.symbname);
1465 CtReq->un.rspn.len =
1466 lpfc_vport_symbolic_port_name(vport,
1467 CtReq->un.rspn.symbname, size);
1468 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1469 break;
dea31012005-04-17 16:05:31 -05001470 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001471 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001472 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001473 cpu_to_be16(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001474 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
James Smart4258e982015-12-16 18:11:58 -05001475 sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001476 size = sizeof(CtReq->un.rsnn.symbname);
1477 CtReq->un.rsnn.len =
1478 lpfc_vport_symbolic_node_name(vport,
1479 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001480 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1481 break;
James Smart7ee5d432007-10-27 13:37:17 -04001482 case SLI_CTNS_DA_ID:
1483 /* Implement DA_ID Nameserver request */
1484 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001485 cpu_to_be16(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001486 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001487 cmpl = lpfc_cmpl_ct_cmd_da_id;
1488 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001489 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001490 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001491 CtReq->CommandResponse.bits.CmdRsp =
James Smart76b2c342015-04-07 15:07:19 -04001492 cpu_to_be16(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001493 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001494 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smarta0f2d3e2017-02-12 13:52:31 -08001495
1496 /* The driver always supports FC_TYPE_FCP. However, the
1497 * caller can specify NVME (type x28) as well. But only
1498 * these that FC4 type is supported.
1499 */
1500 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1501 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1502 (context == FC_TYPE_NVME)) {
James Smart8c258642017-02-12 13:52:36 -08001503 if ((vport == phba->pport) && phba->nvmet_support) {
1504 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1505 FC4_FEATURE_NVME_DISC);
James Smartd613b6a2017-02-12 13:52:37 -08001506 lpfc_nvmet_update_targetport(phba);
James Smart8c258642017-02-12 13:52:36 -08001507 } else {
1508 lpfc_nvme_update_localport(vport);
1509 }
James Smarta0f2d3e2017-02-12 13:52:31 -08001510 CtReq->un.rff.type_code = context;
1511
1512 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1513 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1514 (context == FC_TYPE_FCP))
1515 CtReq->un.rff.type_code = context;
1516
1517 else
1518 goto ns_cmd_free_bmpvirt;
1519
James Smart92d7f7b2007-06-17 19:56:38 -05001520 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1521 break;
dea31012005-04-17 16:05:31 -05001522 }
James Smarte47c9092008-02-08 18:49:26 -05001523 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1524 * to hold ndlp reference for the corresponding callback function.
1525 */
James Smart858c9f62007-06-17 19:56:39 -05001526 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001527 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1529 "Issue CT cmd: cmd:x%x did:x%x",
1530 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001531 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001532 }
James Smart858c9f62007-06-17 19:56:39 -05001533 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001534
1535 /* Decrement ndlp reference count to release ndlp reference held
1536 * for the failed command's callback function.
1537 */
James Smart51ef4c22007-08-02 11:10:31 -04001538 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001539
James Smarta0f2d3e2017-02-12 13:52:31 -08001540ns_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05001541 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1542ns_cmd_free_bmp:
1543 kfree(bmp);
1544ns_cmd_free_mpvirt:
1545 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1546ns_cmd_free_mp:
1547 kfree(mp);
1548ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001549 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1550 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1551 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001552 return 1;
1553}
1554
James Smart4258e982015-12-16 18:11:58 -05001555/**
1556 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1557 * @phba: Pointer to HBA context object.
1558 * @cmdiocb: Pointer to the command IOCBQ.
1559 * @rspiocb: Pointer to the response IOCBQ.
1560 *
1561 * This function to handle the completion of a driver initiated FDMI
1562 * CT command issued during discovery.
1563 */
dea31012005-04-17 16:05:31 -05001564static void
James Smart4258e982015-12-16 18:11:58 -05001565lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1566 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001567{
James Smart4258e982015-12-16 18:11:58 -05001568 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001569 struct lpfc_dmabuf *inp = cmdiocb->context1;
1570 struct lpfc_dmabuf *outp = cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001571 struct lpfc_sli_ct_request *CTcmd = inp->virt;
James Smart4258e982015-12-16 18:11:58 -05001572 struct lpfc_sli_ct_request *CTrsp = outp->virt;
dea31012005-04-17 16:05:31 -05001573 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1574 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart858c9f62007-06-17 19:56:39 -05001575 IOCB_t *irsp = &rspiocb->iocb;
James Smart4258e982015-12-16 18:11:58 -05001576 struct lpfc_nodelist *ndlp;
1577 uint32_t latt, cmd, err;
James Smart858c9f62007-06-17 19:56:39 -05001578
1579 latt = lpfc_els_chk_latt(vport);
James Smart858c9f62007-06-17 19:56:39 -05001580 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1581 "FDMI cmpl: status:x%x/x%x latt:%d",
1582 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1583
1584 if (latt || irsp->ulpStatus) {
James Smart4258e982015-12-16 18:11:58 -05001585
1586 /* Look for a retryable error */
1587 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1588 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1589 case IOERR_SLI_ABORTED:
1590 case IOERR_ABORT_IN_PROGRESS:
1591 case IOERR_SEQUENCE_TIMEOUT:
1592 case IOERR_ILLEGAL_FRAME:
1593 case IOERR_NO_RESOURCES:
1594 case IOERR_ILLEGAL_COMMAND:
1595 cmdiocb->retry++;
1596 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1597 break;
1598
1599 /* Retry the same FDMI command */
1600 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1601 cmdiocb, 0);
1602 if (err == IOCB_ERROR)
1603 break;
1604 return;
1605 default:
1606 break;
1607 }
1608 }
1609
James Smarte8b62012007-08-02 11:10:09 -04001610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1611 "0229 FDMI cmd %04x failed, latt = %d "
1612 "ulpStatus: x%x, rid x%x\n",
1613 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1614 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001615 }
James Smart76b2c342015-04-07 15:07:19 -04001616 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart76b2c342015-04-07 15:07:19 -04001617
1618 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1619 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1620 return;
1621
James Smart4258e982015-12-16 18:11:58 -05001622 /* Check for a CT LS_RJT response */
1623 cmd = be16_to_cpu(fdmi_cmd);
1624 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1625 /* FDMI rsp failed */
1626 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1627 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1628
1629 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1630 switch (cmd) {
1631 case SLI_MGMT_RHBA:
1632 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1633 /* Fallback to FDMI-1 */
1634 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1635 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1636 /* Start over */
1637 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1638 }
1639 return;
1640
1641 case SLI_MGMT_RPRT:
1642 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1643 /* Fallback to FDMI-1 */
1644 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1645 /* Start over */
1646 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1647 }
1648 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1649 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1650 /* Retry the same command */
1651 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1652 }
1653 return;
1654
1655 case SLI_MGMT_RPA:
1656 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1657 /* Fallback to FDMI-1 */
1658 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1659 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1660 /* Start over */
1661 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1662 }
1663 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1664 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1665 /* Retry the same command */
1666 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1667 }
1668 return;
1669 }
1670 }
1671
James Smart76b2c342015-04-07 15:07:19 -04001672 /*
James Smart4258e982015-12-16 18:11:58 -05001673 * On success, need to cycle thru FDMI registration for discovery
1674 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1675 * DPRT -> RPRT (vports)
James Smart76b2c342015-04-07 15:07:19 -04001676 */
James Smart4258e982015-12-16 18:11:58 -05001677 switch (cmd) {
dea31012005-04-17 16:05:31 -05001678 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05001679 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
dea31012005-04-17 16:05:31 -05001680 break;
1681
dea31012005-04-17 16:05:31 -05001682 case SLI_MGMT_DHBA:
James Smart4258e982015-12-16 18:11:58 -05001683 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
dea31012005-04-17 16:05:31 -05001684 break;
1685
1686 case SLI_MGMT_DPRT:
James Smart4258e982015-12-16 18:11:58 -05001687 if (vport->port_type == LPFC_PHYSICAL_PORT)
1688 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1689 else
1690 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
dea31012005-04-17 16:05:31 -05001691 break;
1692 }
James Smart4258e982015-12-16 18:11:58 -05001693 return;
dea31012005-04-17 16:05:31 -05001694}
James Smart2e0fef82007-06-17 19:56:36 -05001695
James Smart76b2c342015-04-07 15:07:19 -04001696
James Smart4258e982015-12-16 18:11:58 -05001697/**
1698 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1699 * @vport: pointer to a host virtual N_Port data structure.
1700 *
1701 * Called from hbeat timeout routine to check if the number of discovered
1702 * ports has changed. If so, re-register thar port Attribute.
1703 */
1704void
1705lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1706{
1707 struct lpfc_hba *phba = vport->phba;
1708 struct lpfc_nodelist *ndlp;
1709 uint16_t cnt;
1710
1711 if (!lpfc_is_link_up(phba))
1712 return;
1713
James Smarta03a4212016-07-06 12:36:12 -07001714 /* Must be connected to a Fabric */
1715 if (!(vport->fc_flag & FC_FABRIC))
1716 return;
1717
James Smart4258e982015-12-16 18:11:58 -05001718 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1719 return;
1720
1721 cnt = lpfc_find_map_node(vport);
1722 if (cnt == vport->fdmi_num_disc)
1723 return;
1724
1725 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1726 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1727 return;
1728
1729 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1730 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1731 LPFC_FDMI_PORT_ATTR_num_disc);
1732 } else {
1733 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1734 LPFC_FDMI_PORT_ATTR_num_disc);
1735 }
1736}
1737
1738/* Routines for all individual HBA attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001739static int
James Smart4258e982015-12-16 18:11:58 -05001740lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1741{
1742 struct lpfc_fdmi_attr_entry *ae;
1743 uint32_t size;
1744
1745 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1746 memset(ae, 0, sizeof(struct lpfc_name));
1747
1748 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1749 sizeof(struct lpfc_name));
1750 size = FOURBYTES + sizeof(struct lpfc_name);
1751 ad->AttrLen = cpu_to_be16(size);
1752 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1753 return size;
1754}
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001755static int
James Smart4258e982015-12-16 18:11:58 -05001756lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1757 struct lpfc_fdmi_attr_def *ad)
1758{
1759 struct lpfc_fdmi_attr_entry *ae;
1760 uint32_t len, size;
1761
1762 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1763 memset(ae, 0, 256);
1764
1765 strncpy(ae->un.AttrString,
1766 "Emulex Corporation",
1767 sizeof(ae->un.AttrString));
1768 len = strnlen(ae->un.AttrString,
1769 sizeof(ae->un.AttrString));
1770 len += (len & 3) ? (4 - (len & 3)) : 4;
1771 size = FOURBYTES + len;
1772 ad->AttrLen = cpu_to_be16(size);
1773 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1774 return size;
1775}
1776
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001777static int
James Smart4258e982015-12-16 18:11:58 -05001778lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1779{
1780 struct lpfc_hba *phba = vport->phba;
1781 struct lpfc_fdmi_attr_entry *ae;
1782 uint32_t len, size;
1783
1784 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1785 memset(ae, 0, 256);
1786
1787 strncpy(ae->un.AttrString, phba->SerialNumber,
1788 sizeof(ae->un.AttrString));
1789 len = strnlen(ae->un.AttrString,
1790 sizeof(ae->un.AttrString));
1791 len += (len & 3) ? (4 - (len & 3)) : 4;
1792 size = FOURBYTES + len;
1793 ad->AttrLen = cpu_to_be16(size);
1794 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1795 return size;
1796}
1797
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001798static int
James Smart4258e982015-12-16 18:11:58 -05001799lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1800 struct lpfc_fdmi_attr_def *ad)
1801{
1802 struct lpfc_hba *phba = vport->phba;
1803 struct lpfc_fdmi_attr_entry *ae;
1804 uint32_t len, size;
1805
1806 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1807 memset(ae, 0, 256);
1808
1809 strncpy(ae->un.AttrString, phba->ModelName,
1810 sizeof(ae->un.AttrString));
1811 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1812 len += (len & 3) ? (4 - (len & 3)) : 4;
1813 size = FOURBYTES + len;
1814 ad->AttrLen = cpu_to_be16(size);
1815 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1816 return size;
1817}
1818
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001819static int
James Smart4258e982015-12-16 18:11:58 -05001820lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1821 struct lpfc_fdmi_attr_def *ad)
1822{
1823 struct lpfc_hba *phba = vport->phba;
1824 struct lpfc_fdmi_attr_entry *ae;
1825 uint32_t len, size;
1826
1827 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1828 memset(ae, 0, 256);
1829
1830 strncpy(ae->un.AttrString, phba->ModelDesc,
1831 sizeof(ae->un.AttrString));
1832 len = strnlen(ae->un.AttrString,
1833 sizeof(ae->un.AttrString));
1834 len += (len & 3) ? (4 - (len & 3)) : 4;
1835 size = FOURBYTES + len;
1836 ad->AttrLen = cpu_to_be16(size);
1837 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1838 return size;
1839}
1840
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001841static int
James Smart4258e982015-12-16 18:11:58 -05001842lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1843 struct lpfc_fdmi_attr_def *ad)
1844{
1845 struct lpfc_hba *phba = vport->phba;
1846 lpfc_vpd_t *vp = &phba->vpd;
1847 struct lpfc_fdmi_attr_entry *ae;
1848 uint32_t i, j, incr, size;
1849
1850 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1851 memset(ae, 0, 256);
1852
1853 /* Convert JEDEC ID to ascii for hardware version */
1854 incr = vp->rev.biuRev;
1855 for (i = 0; i < 8; i++) {
1856 j = (incr & 0xf);
1857 if (j <= 9)
1858 ae->un.AttrString[7 - i] =
1859 (char)((uint8_t) 0x30 +
1860 (uint8_t) j);
1861 else
1862 ae->un.AttrString[7 - i] =
1863 (char)((uint8_t) 0x61 +
1864 (uint8_t) (j - 10));
1865 incr = (incr >> 4);
1866 }
1867 size = FOURBYTES + 8;
1868 ad->AttrLen = cpu_to_be16(size);
1869 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1870 return size;
1871}
1872
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001873static int
James Smart4258e982015-12-16 18:11:58 -05001874lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1875 struct lpfc_fdmi_attr_def *ad)
1876{
1877 struct lpfc_fdmi_attr_entry *ae;
1878 uint32_t len, size;
1879
1880 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1881 memset(ae, 0, 256);
1882
1883 strncpy(ae->un.AttrString, lpfc_release_version,
1884 sizeof(ae->un.AttrString));
1885 len = strnlen(ae->un.AttrString,
1886 sizeof(ae->un.AttrString));
1887 len += (len & 3) ? (4 - (len & 3)) : 4;
1888 size = FOURBYTES + len;
1889 ad->AttrLen = cpu_to_be16(size);
1890 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1891 return size;
1892}
1893
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001894static int
James Smart4258e982015-12-16 18:11:58 -05001895lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1896 struct lpfc_fdmi_attr_def *ad)
1897{
1898 struct lpfc_hba *phba = vport->phba;
1899 struct lpfc_fdmi_attr_entry *ae;
1900 uint32_t len, size;
1901
1902 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1903 memset(ae, 0, 256);
1904
1905 if (phba->sli_rev == LPFC_SLI_REV4)
1906 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1907 else
1908 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1909 sizeof(ae->un.AttrString));
1910 len = strnlen(ae->un.AttrString,
1911 sizeof(ae->un.AttrString));
1912 len += (len & 3) ? (4 - (len & 3)) : 4;
1913 size = FOURBYTES + len;
1914 ad->AttrLen = cpu_to_be16(size);
1915 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1916 return size;
1917}
1918
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001919static int
James Smart4258e982015-12-16 18:11:58 -05001920lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1921 struct lpfc_fdmi_attr_def *ad)
1922{
1923 struct lpfc_hba *phba = vport->phba;
1924 struct lpfc_fdmi_attr_entry *ae;
1925 uint32_t len, size;
1926
1927 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1928 memset(ae, 0, 256);
1929
1930 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1931 len = strnlen(ae->un.AttrString,
1932 sizeof(ae->un.AttrString));
1933 len += (len & 3) ? (4 - (len & 3)) : 4;
1934 size = FOURBYTES + len;
1935 ad->AttrLen = cpu_to_be16(size);
1936 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1937 return size;
1938}
1939
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001940static int
James Smart4258e982015-12-16 18:11:58 -05001941lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1942 struct lpfc_fdmi_attr_def *ad)
1943{
1944 struct lpfc_fdmi_attr_entry *ae;
1945 uint32_t len, size;
1946
1947 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1948 memset(ae, 0, 256);
1949
1950 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1951 init_utsname()->sysname,
1952 init_utsname()->release,
1953 init_utsname()->version);
1954
1955 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1956 len += (len & 3) ? (4 - (len & 3)) : 4;
1957 size = FOURBYTES + len;
1958 ad->AttrLen = cpu_to_be16(size);
1959 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1960 return size;
1961}
1962
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001963static int
James Smart4258e982015-12-16 18:11:58 -05001964lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1965 struct lpfc_fdmi_attr_def *ad)
1966{
1967 struct lpfc_fdmi_attr_entry *ae;
1968 uint32_t size;
1969
1970 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1971
1972 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1973 size = FOURBYTES + sizeof(uint32_t);
1974 ad->AttrLen = cpu_to_be16(size);
1975 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1976 return size;
1977}
1978
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001979static int
James Smart4258e982015-12-16 18:11:58 -05001980lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1981 struct lpfc_fdmi_attr_def *ad)
1982{
1983 struct lpfc_fdmi_attr_entry *ae;
1984 uint32_t len, size;
1985
1986 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1987 memset(ae, 0, 256);
1988
1989 len = lpfc_vport_symbolic_node_name(vport,
1990 ae->un.AttrString, 256);
1991 len += (len & 3) ? (4 - (len & 3)) : 4;
1992 size = FOURBYTES + len;
1993 ad->AttrLen = cpu_to_be16(size);
1994 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1995 return size;
1996}
1997
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08001998static int
James Smart4258e982015-12-16 18:11:58 -05001999lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2000 struct lpfc_fdmi_attr_def *ad)
2001{
2002 struct lpfc_fdmi_attr_entry *ae;
2003 uint32_t size;
2004
2005 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2006
2007 /* Nothing is defined for this currently */
2008 ae->un.AttrInt = cpu_to_be32(0);
2009 size = FOURBYTES + sizeof(uint32_t);
2010 ad->AttrLen = cpu_to_be16(size);
2011 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2012 return size;
2013}
2014
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002015static int
James Smart4258e982015-12-16 18:11:58 -05002016lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2017 struct lpfc_fdmi_attr_def *ad)
2018{
2019 struct lpfc_fdmi_attr_entry *ae;
2020 uint32_t size;
2021
2022 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2023
2024 /* Each driver instance corresponds to a single port */
2025 ae->un.AttrInt = cpu_to_be32(1);
2026 size = FOURBYTES + sizeof(uint32_t);
2027 ad->AttrLen = cpu_to_be16(size);
2028 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2029 return size;
2030}
2031
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002032static int
James Smart4258e982015-12-16 18:11:58 -05002033lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2034 struct lpfc_fdmi_attr_def *ad)
2035{
2036 struct lpfc_fdmi_attr_entry *ae;
2037 uint32_t size;
2038
2039 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2040 memset(ae, 0, sizeof(struct lpfc_name));
2041
2042 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2043 sizeof(struct lpfc_name));
2044 size = FOURBYTES + sizeof(struct lpfc_name);
2045 ad->AttrLen = cpu_to_be16(size);
2046 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2047 return size;
2048}
2049
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002050static int
James Smart4258e982015-12-16 18:11:58 -05002051lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2052 struct lpfc_fdmi_attr_def *ad)
2053{
2054 struct lpfc_hba *phba = vport->phba;
2055 struct lpfc_fdmi_attr_entry *ae;
2056 uint32_t len, size;
2057
2058 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2059 memset(ae, 0, 256);
2060
2061 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2062 len = strnlen(ae->un.AttrString,
2063 sizeof(ae->un.AttrString));
2064 len += (len & 3) ? (4 - (len & 3)) : 4;
2065 size = FOURBYTES + len;
2066 ad->AttrLen = cpu_to_be16(size);
2067 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2068 return size;
2069}
2070
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002071static int
James Smart4258e982015-12-16 18:11:58 -05002072lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2073 struct lpfc_fdmi_attr_def *ad)
2074{
2075 struct lpfc_fdmi_attr_entry *ae;
2076 uint32_t size;
2077
2078 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2079
2080 /* Driver doesn't have access to this information */
2081 ae->un.AttrInt = cpu_to_be32(0);
2082 size = FOURBYTES + sizeof(uint32_t);
2083 ad->AttrLen = cpu_to_be16(size);
2084 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2085 return size;
2086}
2087
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002088static int
James Smart4258e982015-12-16 18:11:58 -05002089lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2090 struct lpfc_fdmi_attr_def *ad)
2091{
2092 struct lpfc_fdmi_attr_entry *ae;
2093 uint32_t len, size;
2094
2095 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2096 memset(ae, 0, 256);
2097
2098 strncpy(ae->un.AttrString, "EMULEX",
2099 sizeof(ae->un.AttrString));
2100 len = strnlen(ae->un.AttrString,
2101 sizeof(ae->un.AttrString));
2102 len += (len & 3) ? (4 - (len & 3)) : 4;
2103 size = FOURBYTES + len;
2104 ad->AttrLen = cpu_to_be16(size);
2105 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2106 return size;
2107}
2108
2109/* Routines for all individual PORT attributes */
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002110static int
James Smart4258e982015-12-16 18:11:58 -05002111lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2112 struct lpfc_fdmi_attr_def *ad)
2113{
2114 struct lpfc_fdmi_attr_entry *ae;
2115 uint32_t size;
2116
2117 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2118 memset(ae, 0, 32);
2119
2120 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2121 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
James Smart82820f02017-05-15 15:20:47 -07002122 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
James Smart4258e982015-12-16 18:11:58 -05002123 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2124 size = FOURBYTES + 32;
2125 ad->AttrLen = cpu_to_be16(size);
2126 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2127 return size;
2128}
2129
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002130static int
James Smart4258e982015-12-16 18:11:58 -05002131lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2132 struct lpfc_fdmi_attr_def *ad)
2133{
2134 struct lpfc_hba *phba = vport->phba;
2135 struct lpfc_fdmi_attr_entry *ae;
2136 uint32_t size;
2137
2138 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2139
2140 ae->un.AttrInt = 0;
James Smarta085e872015-12-16 18:12:02 -05002141 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smartfbd8a6b2018-02-22 08:18:45 -08002142 if (phba->lmt & LMT_64Gb)
2143 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
James Smarta085e872015-12-16 18:12:02 -05002144 if (phba->lmt & LMT_32Gb)
2145 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2146 if (phba->lmt & LMT_16Gb)
2147 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2148 if (phba->lmt & LMT_10Gb)
2149 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2150 if (phba->lmt & LMT_8Gb)
2151 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2152 if (phba->lmt & LMT_4Gb)
2153 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2154 if (phba->lmt & LMT_2Gb)
2155 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2156 if (phba->lmt & LMT_1Gb)
2157 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2158 } else {
2159 /* FCoE links support only one speed */
2160 switch (phba->fc_linkspeed) {
2161 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2162 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2163 break;
2164 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2165 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2166 break;
2167 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2168 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2169 break;
2170 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2171 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2172 break;
2173 }
2174 }
James Smart4258e982015-12-16 18:11:58 -05002175 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2176 size = FOURBYTES + sizeof(uint32_t);
2177 ad->AttrLen = cpu_to_be16(size);
2178 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2179 return size;
2180}
2181
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002182static int
James Smart4258e982015-12-16 18:11:58 -05002183lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2184 struct lpfc_fdmi_attr_def *ad)
2185{
2186 struct lpfc_hba *phba = vport->phba;
2187 struct lpfc_fdmi_attr_entry *ae;
2188 uint32_t size;
2189
2190 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2191
James Smarta085e872015-12-16 18:12:02 -05002192 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2193 switch (phba->fc_linkspeed) {
2194 case LPFC_LINK_SPEED_1GHZ:
2195 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2196 break;
2197 case LPFC_LINK_SPEED_2GHZ:
2198 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2199 break;
2200 case LPFC_LINK_SPEED_4GHZ:
2201 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2202 break;
2203 case LPFC_LINK_SPEED_8GHZ:
2204 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2205 break;
2206 case LPFC_LINK_SPEED_10GHZ:
2207 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2208 break;
2209 case LPFC_LINK_SPEED_16GHZ:
2210 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2211 break;
2212 case LPFC_LINK_SPEED_32GHZ:
2213 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2214 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08002215 case LPFC_LINK_SPEED_64GHZ:
2216 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2217 break;
James Smarta085e872015-12-16 18:12:02 -05002218 default:
2219 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2220 break;
2221 }
2222 } else {
2223 switch (phba->fc_linkspeed) {
2224 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2225 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2226 break;
2227 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2228 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2229 break;
2230 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2231 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2232 break;
2233 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2234 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2235 break;
2236 default:
2237 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2238 break;
2239 }
James Smart4258e982015-12-16 18:11:58 -05002240 }
James Smarta085e872015-12-16 18:12:02 -05002241
James Smart4258e982015-12-16 18:11:58 -05002242 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2243 size = FOURBYTES + sizeof(uint32_t);
2244 ad->AttrLen = cpu_to_be16(size);
2245 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2246 return size;
2247}
2248
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002249static int
James Smart4258e982015-12-16 18:11:58 -05002250lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2251 struct lpfc_fdmi_attr_def *ad)
2252{
2253 struct serv_parm *hsp;
2254 struct lpfc_fdmi_attr_entry *ae;
2255 uint32_t size;
2256
2257 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2258
2259 hsp = (struct serv_parm *)&vport->fc_sparam;
2260 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2261 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2262 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2263 size = FOURBYTES + sizeof(uint32_t);
2264 ad->AttrLen = cpu_to_be16(size);
2265 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2266 return size;
2267}
2268
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002269static int
James Smart4258e982015-12-16 18:11:58 -05002270lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2271 struct lpfc_fdmi_attr_def *ad)
2272{
2273 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2274 struct lpfc_fdmi_attr_entry *ae;
2275 uint32_t len, size;
2276
2277 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2278 memset(ae, 0, 256);
2279
2280 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2281 "/sys/class/scsi_host/host%d", shost->host_no);
2282 len = strnlen((char *)ae->un.AttrString,
2283 sizeof(ae->un.AttrString));
2284 len += (len & 3) ? (4 - (len & 3)) : 4;
2285 size = FOURBYTES + len;
2286 ad->AttrLen = cpu_to_be16(size);
2287 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2288 return size;
2289}
2290
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002291static int
James Smart4258e982015-12-16 18:11:58 -05002292lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2293 struct lpfc_fdmi_attr_def *ad)
2294{
2295 struct lpfc_fdmi_attr_entry *ae;
2296 uint32_t len, size;
2297
2298 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2299 memset(ae, 0, 256);
2300
2301 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2302 init_utsname()->nodename);
2303
2304 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2305 len += (len & 3) ? (4 - (len & 3)) : 4;
2306 size = FOURBYTES + len;
2307 ad->AttrLen = cpu_to_be16(size);
2308 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2309 return size;
2310}
2311
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002312static int
James Smart4258e982015-12-16 18:11:58 -05002313lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2314 struct lpfc_fdmi_attr_def *ad)
2315{
2316 struct lpfc_fdmi_attr_entry *ae;
2317 uint32_t size;
2318
2319 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2320 memset(ae, 0, sizeof(struct lpfc_name));
2321
2322 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2323 sizeof(struct lpfc_name));
2324 size = FOURBYTES + sizeof(struct lpfc_name);
2325 ad->AttrLen = cpu_to_be16(size);
2326 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2327 return size;
2328}
2329
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002330static int
James Smart4258e982015-12-16 18:11:58 -05002331lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2332 struct lpfc_fdmi_attr_def *ad)
2333{
2334 struct lpfc_fdmi_attr_entry *ae;
2335 uint32_t size;
2336
2337 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2338 memset(ae, 0, sizeof(struct lpfc_name));
2339
2340 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2341 sizeof(struct lpfc_name));
2342 size = FOURBYTES + sizeof(struct lpfc_name);
2343 ad->AttrLen = cpu_to_be16(size);
2344 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2345 return size;
2346}
2347
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002348static int
James Smart4258e982015-12-16 18:11:58 -05002349lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2350 struct lpfc_fdmi_attr_def *ad)
2351{
2352 struct lpfc_fdmi_attr_entry *ae;
2353 uint32_t len, size;
2354
2355 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2356 memset(ae, 0, 256);
2357
2358 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2359 len += (len & 3) ? (4 - (len & 3)) : 4;
2360 size = FOURBYTES + len;
2361 ad->AttrLen = cpu_to_be16(size);
2362 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
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_port_type(struct lpfc_vport *vport,
2368 struct lpfc_fdmi_attr_def *ad)
2369{
2370 struct lpfc_hba *phba = vport->phba;
2371 struct lpfc_fdmi_attr_entry *ae;
2372 uint32_t size;
2373
2374 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2375 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2376 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2377 else
2378 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2379 size = FOURBYTES + sizeof(uint32_t);
2380 ad->AttrLen = cpu_to_be16(size);
2381 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2382 return size;
2383}
2384
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002385static int
James Smart4258e982015-12-16 18:11:58 -05002386lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2387 struct lpfc_fdmi_attr_def *ad)
2388{
2389 struct lpfc_fdmi_attr_entry *ae;
2390 uint32_t size;
2391
2392 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2393 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2394 size = FOURBYTES + sizeof(uint32_t);
2395 ad->AttrLen = cpu_to_be16(size);
2396 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2397 return size;
2398}
2399
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002400static int
James Smart4258e982015-12-16 18:11:58 -05002401lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2402 struct lpfc_fdmi_attr_def *ad)
2403{
2404 struct lpfc_fdmi_attr_entry *ae;
2405 uint32_t size;
2406
2407 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2408 memset(ae, 0, sizeof(struct lpfc_name));
2409
2410 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2411 sizeof(struct lpfc_name));
2412 size = FOURBYTES + sizeof(struct lpfc_name);
2413 ad->AttrLen = cpu_to_be16(size);
2414 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2415 return size;
2416}
2417
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002418static int
James Smart4258e982015-12-16 18:11:58 -05002419lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2420 struct lpfc_fdmi_attr_def *ad)
2421{
2422 struct lpfc_fdmi_attr_entry *ae;
2423 uint32_t size;
2424
2425 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2426 memset(ae, 0, 32);
2427
2428 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2429 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2430 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2431 size = FOURBYTES + 32;
2432 ad->AttrLen = cpu_to_be16(size);
2433 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2434 return size;
2435}
2436
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002437static int
James Smart4258e982015-12-16 18:11:58 -05002438lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2439 struct lpfc_fdmi_attr_def *ad)
2440{
2441 struct lpfc_fdmi_attr_entry *ae;
2442 uint32_t size;
2443
2444 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2445 /* Link Up - operational */
2446 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2447 size = FOURBYTES + sizeof(uint32_t);
2448 ad->AttrLen = cpu_to_be16(size);
2449 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2450 return size;
2451}
2452
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002453static int
James Smart4258e982015-12-16 18:11:58 -05002454lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2455 struct lpfc_fdmi_attr_def *ad)
2456{
2457 struct lpfc_fdmi_attr_entry *ae;
2458 uint32_t size;
2459
2460 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2461 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2462 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2463 size = FOURBYTES + sizeof(uint32_t);
2464 ad->AttrLen = cpu_to_be16(size);
2465 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2466 return size;
2467}
2468
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002469static int
James Smart4258e982015-12-16 18:11:58 -05002470lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2471 struct lpfc_fdmi_attr_def *ad)
2472{
2473 struct lpfc_fdmi_attr_entry *ae;
2474 uint32_t size;
2475
2476 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2477 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2478 size = FOURBYTES + sizeof(uint32_t);
2479 ad->AttrLen = cpu_to_be16(size);
2480 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2481 return size;
2482}
2483
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002484static int
James Smart4258e982015-12-16 18:11:58 -05002485lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2486 struct lpfc_fdmi_attr_def *ad)
2487{
2488 struct lpfc_fdmi_attr_entry *ae;
2489 uint32_t len, size;
2490
2491 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2492 memset(ae, 0, 256);
2493
2494 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2495 sizeof(ae->un.AttrString));
2496 len = strnlen(ae->un.AttrString,
2497 sizeof(ae->un.AttrString));
2498 len += (len & 3) ? (4 - (len & 3)) : 4;
2499 size = FOURBYTES + len;
2500 ad->AttrLen = cpu_to_be16(size);
2501 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2502 return size;
2503}
2504
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002505static int
James Smart4258e982015-12-16 18:11:58 -05002506lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2507 struct lpfc_fdmi_attr_def *ad)
2508{
2509 struct lpfc_fdmi_attr_entry *ae;
2510 uint32_t size;
2511
2512 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2513 memset(ae, 0, 256);
2514
2515 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2516 sizeof(struct lpfc_name));
2517 memcpy((((uint8_t *)&ae->un.AttrString) +
2518 sizeof(struct lpfc_name)),
2519 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2520 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2521 ad->AttrLen = cpu_to_be16(size);
2522 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2523 return size;
2524}
2525
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002526static int
James Smart4258e982015-12-16 18:11:58 -05002527lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2528 struct lpfc_fdmi_attr_def *ad)
2529{
2530 struct lpfc_fdmi_attr_entry *ae;
2531 uint32_t len, size;
2532
2533 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2534 memset(ae, 0, 256);
2535
James Smart56204982016-03-31 14:12:32 -07002536 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
James Smart4258e982015-12-16 18:11:58 -05002537 sizeof(ae->un.AttrString));
2538 len = strnlen(ae->un.AttrString,
2539 sizeof(ae->un.AttrString));
2540 len += (len & 3) ? (4 - (len & 3)) : 4;
2541 size = FOURBYTES + len;
2542 ad->AttrLen = cpu_to_be16(size);
2543 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2544 return size;
2545}
2546
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002547static int
James Smart4258e982015-12-16 18:11:58 -05002548lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2549 struct lpfc_fdmi_attr_def *ad)
2550{
2551 struct lpfc_hba *phba = vport->phba;
2552 struct lpfc_fdmi_attr_entry *ae;
2553 uint32_t len, size;
2554
2555 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2556 memset(ae, 0, 256);
2557
2558 strncpy(ae->un.AttrString, phba->ModelName,
2559 sizeof(ae->un.AttrString));
2560 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2561 len += (len & 3) ? (4 - (len & 3)) : 4;
2562 size = FOURBYTES + len;
2563 ad->AttrLen = cpu_to_be16(size);
2564 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2565 return size;
2566}
2567
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002568static int
James Smart4258e982015-12-16 18:11:58 -05002569lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2570 struct lpfc_fdmi_attr_def *ad)
2571{
2572 struct lpfc_fdmi_attr_entry *ae;
2573 uint32_t size;
2574
2575 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2576
2577 /* SRIOV (type 3) is not supported */
2578 if (vport->vpi)
2579 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2580 else
2581 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2582 size = FOURBYTES + sizeof(uint32_t);
2583 ad->AttrLen = cpu_to_be16(size);
2584 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2585 return size;
2586}
2587
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002588static int
James Smart4258e982015-12-16 18:11:58 -05002589lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2590 struct lpfc_fdmi_attr_def *ad)
2591{
2592 struct lpfc_fdmi_attr_entry *ae;
2593 uint32_t size;
2594
2595 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2596 ae->un.AttrInt = cpu_to_be32(0);
2597 size = FOURBYTES + sizeof(uint32_t);
2598 ad->AttrLen = cpu_to_be16(size);
2599 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2600 return size;
2601}
2602
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002603static int
James Smart4258e982015-12-16 18:11:58 -05002604lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2605 struct lpfc_fdmi_attr_def *ad)
2606{
2607 struct lpfc_fdmi_attr_entry *ae;
2608 uint32_t size;
2609
2610 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
James Smart56204982016-03-31 14:12:32 -07002611 ae->un.AttrInt = cpu_to_be32(1);
James Smart4258e982015-12-16 18:11:58 -05002612 size = FOURBYTES + sizeof(uint32_t);
2613 ad->AttrLen = cpu_to_be16(size);
2614 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2615 return size;
2616}
2617
2618/* RHBA attribute jump table */
2619int (*lpfc_fdmi_hba_action[])
2620 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2621 /* Action routine Mask bit Attribute type */
2622 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2623 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2624 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2625 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2626 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2627 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2628 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2629 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2630 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2631 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2632 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2633 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2634 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2635 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2636 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2637 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2638 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2639 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2640};
2641
2642/* RPA / RPRT attribute jump table */
2643int (*lpfc_fdmi_port_action[])
2644 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2645 /* Action routine Mask bit Attribute type */
2646 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2647 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2648 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2649 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2650 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2651 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2652 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2653 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2654 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2655 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2656 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2657 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2658 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2659 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2660 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2661 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2662 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2663 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2664 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2665 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2666 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2667 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2668 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2669};
2670
2671/**
2672 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2673 * @vport: pointer to a host virtual N_Port data structure.
2674 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2675 * cmdcode: FDMI command to send
2676 * mask: Mask of HBA or PORT Attributes to send
2677 *
2678 * Builds and sends a FDMI command using the CT subsystem.
2679 */
2680int
2681lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2682 int cmdcode, uint32_t new_mask)
dea31012005-04-17 16:05:31 -05002683{
James Smart2e0fef82007-06-17 19:56:36 -05002684 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002685 struct lpfc_dmabuf *mp, *bmp;
2686 struct lpfc_sli_ct_request *CtReq;
2687 struct ulp_bde64 *bpl;
James Smart4258e982015-12-16 18:11:58 -05002688 uint32_t bit_pos;
dea31012005-04-17 16:05:31 -05002689 uint32_t size;
James Smart76b2c342015-04-07 15:07:19 -04002690 uint32_t rsp_size;
James Smart4258e982015-12-16 18:11:58 -05002691 uint32_t mask;
James Smart76b2c342015-04-07 15:07:19 -04002692 struct lpfc_fdmi_reg_hba *rh;
2693 struct lpfc_fdmi_port_entry *pe;
2694 struct lpfc_fdmi_reg_portattr *pab = NULL;
2695 struct lpfc_fdmi_attr_block *ab = NULL;
James Smart4258e982015-12-16 18:11:58 -05002696 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2697 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2698 struct lpfc_iocbq *);
dea31012005-04-17 16:05:31 -05002699
James Smart4258e982015-12-16 18:11:58 -05002700 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2701 return 0;
2702
2703 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
dea31012005-04-17 16:05:31 -05002704
2705 /* fill in BDEs for command */
2706 /* Allocate buffer for command payload */
James Smart76b2c342015-04-07 15:07:19 -04002707 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002708 if (!mp)
2709 goto fdmi_cmd_exit;
2710
2711 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2712 if (!mp->virt)
2713 goto fdmi_cmd_free_mp;
2714
2715 /* Allocate buffer for Buffer ptr list */
James Smart76b2c342015-04-07 15:07:19 -04002716 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002717 if (!bmp)
2718 goto fdmi_cmd_free_mpvirt;
2719
2720 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2721 if (!bmp->virt)
2722 goto fdmi_cmd_free_bmp;
2723
2724 INIT_LIST_HEAD(&mp->list);
2725 INIT_LIST_HEAD(&bmp->list);
2726
2727 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04002728 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2729 "0218 FDMI Request Data: x%x x%x x%x\n",
2730 vport->fc_flag, vport->port_state, cmdcode);
James Smart76b2c342015-04-07 15:07:19 -04002731 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
dea31012005-04-17 16:05:31 -05002732
James Smart76b2c342015-04-07 15:07:19 -04002733 /* First populate the CT_IU preamble */
dea31012005-04-17 16:05:31 -05002734 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2735 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2736 CtReq->RevisionId.bits.InId = 0;
2737
2738 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2739 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
James Smart76b2c342015-04-07 15:07:19 -04002740
2741 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2742 rsp_size = LPFC_BPL_SIZE;
dea31012005-04-17 16:05:31 -05002743 size = 0;
2744
James Smart76b2c342015-04-07 15:07:19 -04002745 /* Next fill in the specific FDMI cmd information */
dea31012005-04-17 16:05:31 -05002746 switch (cmdcode) {
James Smart76b2c342015-04-07 15:07:19 -04002747 case SLI_MGMT_RHAT:
dea31012005-04-17 16:05:31 -05002748 case SLI_MGMT_RHBA:
James Smart4258e982015-12-16 18:11:58 -05002749 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2750 /* HBA Identifier */
2751 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2752 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002753
James Smart4258e982015-12-16 18:11:58 -05002754 if (cmdcode == SLI_MGMT_RHBA) {
2755 /* Registered Port List */
2756 /* One entry (port) per adapter */
2757 rh->rpl.EntryCnt = cpu_to_be32(1);
2758 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002759 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002760
James Smart4258e982015-12-16 18:11:58 -05002761 /* point to the HBA attribute block */
2762 size = 2 * sizeof(struct lpfc_name) +
2763 FOURBYTES;
2764 } else {
2765 size = sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002766 }
James Smart4258e982015-12-16 18:11:58 -05002767 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2768 ab->EntryCnt = 0;
2769 size += FOURBYTES;
2770 bit_pos = 0;
2771 if (new_mask)
2772 mask = new_mask;
2773 else
2774 mask = vport->fdmi_hba_mask;
2775
2776 /* Mask will dictate what attributes to build in the request */
2777 while (mask) {
2778 if (mask & 0x1) {
2779 func = lpfc_fdmi_hba_action[bit_pos];
2780 size += func(vport,
2781 (struct lpfc_fdmi_attr_def *)
2782 ((uint8_t *)rh + size));
2783 ab->EntryCnt++;
2784 if ((size + 256) >
2785 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2786 goto hba_out;
2787 }
2788 mask = mask >> 1;
2789 bit_pos++;
2790 }
2791hba_out:
2792 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2793 /* Total size */
2794 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002795 break;
2796
James Smart76b2c342015-04-07 15:07:19 -04002797 case SLI_MGMT_RPRT:
dea31012005-04-17 16:05:31 -05002798 case SLI_MGMT_RPA:
James Smart4258e982015-12-16 18:11:58 -05002799 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2800 if (cmdcode == SLI_MGMT_RPRT) {
2801 rh = (struct lpfc_fdmi_reg_hba *)pab;
2802 /* HBA Identifier */
2803 memcpy(&rh->hi.PortName,
2804 &phba->pport->fc_sparam.portName,
James Smart76b2c342015-04-07 15:07:19 -04002805 sizeof(struct lpfc_name));
James Smart4258e982015-12-16 18:11:58 -05002806 pab = (struct lpfc_fdmi_reg_portattr *)
2807 ((uint8_t *)pab + sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002808 }
James Smart4258e982015-12-16 18:11:58 -05002809
2810 memcpy((uint8_t *)&pab->PortName,
2811 (uint8_t *)&vport->fc_sparam.portName,
2812 sizeof(struct lpfc_name));
2813 size += sizeof(struct lpfc_name) + FOURBYTES;
2814 pab->ab.EntryCnt = 0;
2815 bit_pos = 0;
2816 if (new_mask)
2817 mask = new_mask;
2818 else
2819 mask = vport->fdmi_port_mask;
2820
2821 /* Mask will dictate what attributes to build in the request */
2822 while (mask) {
2823 if (mask & 0x1) {
2824 func = lpfc_fdmi_port_action[bit_pos];
2825 size += func(vport,
2826 (struct lpfc_fdmi_attr_def *)
2827 ((uint8_t *)pab + size));
2828 pab->ab.EntryCnt++;
2829 if ((size + 256) >
2830 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2831 goto port_out;
2832 }
2833 mask = mask >> 1;
2834 bit_pos++;
2835 }
2836port_out:
2837 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2838 /* Total size */
2839 if (cmdcode == SLI_MGMT_RPRT)
2840 size += sizeof(struct lpfc_name);
2841 size = GID_REQUEST_SZ - 4 + size;
dea31012005-04-17 16:05:31 -05002842 break;
2843
James Smart76b2c342015-04-07 15:07:19 -04002844 case SLI_MGMT_GHAT:
2845 case SLI_MGMT_GRPL:
2846 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002847 case SLI_MGMT_DHBA:
James Smart76b2c342015-04-07 15:07:19 -04002848 case SLI_MGMT_DHAT:
2849 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2850 memcpy((uint8_t *)&pe->PortName,
2851 (uint8_t *)&vport->fc_sparam.portName,
2852 sizeof(struct lpfc_name));
2853 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002854 break;
2855
James Smart76b2c342015-04-07 15:07:19 -04002856 case SLI_MGMT_GPAT:
2857 case SLI_MGMT_GPAS:
2858 rsp_size = FC_MAX_NS_RSP;
dea31012005-04-17 16:05:31 -05002859 case SLI_MGMT_DPRT:
James Smart76b2c342015-04-07 15:07:19 -04002860 case SLI_MGMT_DPA:
2861 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2862 memcpy((uint8_t *)&pe->PortName,
2863 (uint8_t *)&vport->fc_sparam.portName,
2864 sizeof(struct lpfc_name));
2865 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
dea31012005-04-17 16:05:31 -05002866 break;
James Smart76b2c342015-04-07 15:07:19 -04002867 case SLI_MGMT_GRHL:
2868 size = GID_REQUEST_SZ - 4;
2869 break;
2870 default:
2871 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2872 "0298 FDMI cmdcode x%x not supported\n",
2873 cmdcode);
2874 goto fdmi_cmd_free_bmpvirt;
dea31012005-04-17 16:05:31 -05002875 }
James Smart76b2c342015-04-07 15:07:19 -04002876 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
dea31012005-04-17 16:05:31 -05002877
James Smart76b2c342015-04-07 15:07:19 -04002878 bpl = (struct ulp_bde64 *)bmp->virt;
2879 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2880 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
dea31012005-04-17 16:05:31 -05002881 bpl->tus.f.bdeFlags = 0;
2882 bpl->tus.f.bdeSize = size;
dea31012005-04-17 16:05:31 -05002883
James Smart76b2c342015-04-07 15:07:19 -04002884 /*
2885 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
James Smarte47c9092008-02-08 18:49:26 -05002886 * to hold ndlp reference for the corresponding callback function.
2887 */
James Smart76b2c342015-04-07 15:07:19 -04002888 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
dea31012005-04-17 16:05:31 -05002889 return 0;
2890
James Smart76b2c342015-04-07 15:07:19 -04002891 /*
2892 * Decrement ndlp reference count to release ndlp reference held
James Smarte47c9092008-02-08 18:49:26 -05002893 * for the failed command's callback function.
2894 */
James Smart51ef4c22007-08-02 11:10:31 -04002895 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002896
James Smart76b2c342015-04-07 15:07:19 -04002897fdmi_cmd_free_bmpvirt:
dea31012005-04-17 16:05:31 -05002898 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2899fdmi_cmd_free_bmp:
2900 kfree(bmp);
2901fdmi_cmd_free_mpvirt:
2902 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2903fdmi_cmd_free_mp:
2904 kfree(mp);
2905fdmi_cmd_exit:
2906 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04002907 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2908 "0244 Issue FDMI request failed Data: x%x\n",
2909 cmdcode);
dea31012005-04-17 16:05:31 -05002910 return 1;
2911}
2912
James Smart92494142011-02-16 12:39:44 -05002913/**
2914 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2915 * @ptr - Context object of the timer.
2916 *
2917 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2918 * the worker thread.
2919 **/
2920void
Kees Cookf22eb4d2017-09-06 20:24:26 -07002921lpfc_delayed_disc_tmo(struct timer_list *t)
James Smart92494142011-02-16 12:39:44 -05002922{
Kees Cookf22eb4d2017-09-06 20:24:26 -07002923 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
James Smart92494142011-02-16 12:39:44 -05002924 struct lpfc_hba *phba = vport->phba;
2925 uint32_t tmo_posted;
2926 unsigned long iflag;
2927
2928 spin_lock_irqsave(&vport->work_port_lock, iflag);
2929 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2930 if (!tmo_posted)
2931 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2932 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2933
2934 if (!tmo_posted)
2935 lpfc_worker_wake_up(phba);
2936 return;
2937}
2938
2939/**
2940 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2941 * handle delayed discovery.
2942 * @vport: pointer to a host virtual N_Port data structure.
2943 *
2944 * This function start nport discovery of the vport.
2945 **/
2946void
2947lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2948{
2949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2950
2951 spin_lock_irq(shost->host_lock);
2952 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2953 spin_unlock_irq(shost->host_lock);
2954 return;
2955 }
2956 vport->fc_flag &= ~FC_DISC_DELAYED;
2957 spin_unlock_irq(shost->host_lock);
2958
2959 lpfc_do_scr_ns_plogi(vport->phba, vport);
2960}
2961
dea31012005-04-17 16:05:31 -05002962void
James Smart2e0fef82007-06-17 19:56:36 -05002963lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05002964{
2965 struct lpfc_sli *psli = &phba->sli;
2966 lpfc_vpd_t *vp = &phba->vpd;
2967 uint32_t b1, b2, b3, b4, i, rev;
2968 char c;
2969 uint32_t *ptr, str[4];
2970 uint8_t *fwname;
2971
James Smartf1126682009-06-10 17:22:44 -04002972 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart6b5151f2012-01-18 16:24:06 -05002973 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
James Smartf1126682009-06-10 17:22:44 -04002974 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04002975 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05002976 rev = vp->rev.sli2FwRev;
2977 else
2978 rev = vp->rev.sli1FwRev;
2979
2980 b1 = (rev & 0x0000f000) >> 12;
2981 b2 = (rev & 0x00000f00) >> 8;
2982 b3 = (rev & 0x000000c0) >> 6;
2983 b4 = (rev & 0x00000030) >> 4;
2984
2985 switch (b4) {
2986 case 0:
2987 c = 'N';
2988 break;
2989 case 1:
2990 c = 'A';
2991 break;
2992 case 2:
2993 c = 'B';
2994 break;
James Smart73d91e52011-10-10 21:32:10 -04002995 case 3:
2996 c = 'X';
2997 break;
dea31012005-04-17 16:05:31 -05002998 default:
2999 c = 0;
3000 break;
3001 }
3002 b4 = (rev & 0x0000000f);
3003
James Smartf4b4c682009-05-22 14:53:12 -04003004 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05003005 fwname = vp->rev.sli2FwName;
3006 else
3007 fwname = vp->rev.sli1FwName;
3008
3009 for (i = 0; i < 16; i++)
3010 if (fwname[i] == 0x20)
3011 fwname[i] = 0;
3012
3013 ptr = (uint32_t*)fwname;
3014
3015 for (i = 0; i < 3; i++)
3016 str[i] = be32_to_cpu(*ptr++);
3017
3018 if (c == 0) {
3019 if (flag)
3020 sprintf(fwrevision, "%d.%d%d (%s)",
3021 b1, b2, b3, (char *)str);
3022 else
3023 sprintf(fwrevision, "%d.%d%d", b1,
3024 b2, b3);
3025 } else {
3026 if (flag)
3027 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3028 b1, b2, b3, c,
3029 b4, (char *)str);
3030 else
3031 sprintf(fwrevision, "%d.%d%d%c%d",
3032 b1, b2, b3, c, b4);
3033 }
3034 } else {
3035 rev = vp->rev.smFwRev;
3036
3037 b1 = (rev & 0xff000000) >> 24;
3038 b2 = (rev & 0x00f00000) >> 20;
3039 b3 = (rev & 0x000f0000) >> 16;
3040 c = (rev & 0x0000ff00) >> 8;
3041 b4 = (rev & 0x000000ff);
3042
Roel Kluind44a6d22010-01-17 16:15:57 +01003043 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05003044 }
3045 return;
3046}