blob: 7bff3a19af56880dba0fdca4e203676d52c4e916 [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 Smart4fede782010-01-26 23:08:55 -05004 * Copyright (C) 2004-2010 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
dea31012005-04-17 16:05:31 -050019 *******************************************************************/
20
21/*
James Smart09372822008-01-11 01:52:54 -050022 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
dea31012005-04-17 16:05:31 -050023 */
24
25#include <linux/blkdev.h>
26#include <linux/pci.h>
27#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050029#include <linux/utsname.h>
30
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040034#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040035#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050036
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_crtn.h"
47#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050048#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050049#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050050
James Smart76a95d72010-11-20 23:11:48 -050051/* FDMI Port Speed definitions */
52#define HBA_PORTSPEED_1GBIT 0x0001 /* 1 GBit/sec */
53#define HBA_PORTSPEED_2GBIT 0x0002 /* 2 GBit/sec */
54#define HBA_PORTSPEED_4GBIT 0x0008 /* 4 GBit/sec */
55#define HBA_PORTSPEED_10GBIT 0x0004 /* 10 GBit/sec */
56#define HBA_PORTSPEED_8GBIT 0x0010 /* 8 GBit/sec */
57#define HBA_PORTSPEED_16GBIT 0x0020 /* 16 GBit/sec */
58#define HBA_PORTSPEED_UNKNOWN 0x0800 /* Unknown */
dea31012005-04-17 16:05:31 -050059
60#define FOURBYTES 4
61
62
63static char *lpfc_release_version = LPFC_DRIVER_VERSION;
64
James Smarted957682007-06-17 19:56:37 -050065static void
66lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050067 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050068{
James Smarted957682007-06-17 19:56:37 -050069 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart97eab632008-04-07 10:16:05 -040071 "0146 Ignoring unsolicited CT No HBQ "
James Smart9c2face2008-01-11 01:53:18 -050072 "status = x%x\n",
73 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050074 }
James Smart9c2face2008-01-11 01:53:18 -050075 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
76 "0145 Ignoring unsolicted CT HBQ Size:%d "
77 "status = x%x\n",
78 size, piocbq->iocb.ulpStatus);
79}
80
81static void
82lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
83 struct lpfc_dmabuf *mp, uint32_t size)
84{
85 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -050086}
87
dea31012005-04-17 16:05:31 -050088void
James Smart2e0fef82007-06-17 19:56:36 -050089lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
90 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -050091{
James Smarted957682007-06-17 19:56:37 -050092 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -050093 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -050094 int i;
95 struct lpfc_iocbq *iocbq;
96 dma_addr_t paddr;
97 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -050098 struct list_head head;
99 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -0500100
James Smart4fede782010-01-26 23:08:55 -0500101 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
102 return;
James Smartf1c3b0f2009-07-19 10:01:32 -0400103
James Smart92d7f7b2007-06-17 19:56:38 -0500104 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
105 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
106 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400107 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
108 IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500109 /* Not enough posted buffers; Try posting more buffers */
110 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500111 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -0400112 lpfc_post_buffer(phba, pring, 2);
dea31012005-04-17 16:05:31 -0500113 return;
114 }
115
116 /* If there are no BDEs associated with this IOCB,
117 * there is nothing to do.
118 */
119 if (icmd->ulpBdeCount == 0)
120 return;
121
James Smarted957682007-06-17 19:56:37 -0500122 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500123 INIT_LIST_HEAD(&head);
124 list_add_tail(&head, &piocbq->list);
125 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500126 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500127 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500128 continue;
James Smart9c2face2008-01-11 01:53:18 -0500129 bdeBuf = iocbq->context2;
130 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500131 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500132 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
133 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500134 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500135 bdeBuf = iocbq->context3;
136 iocbq->context3 = NULL;
137 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
138 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
139 size);
140 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500141 }
dea31012005-04-17 16:05:31 -0500142 }
James Smart9c2face2008-01-11 01:53:18 -0500143 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500144 } else {
James Smartd7c255b2008-08-24 21:50:00 -0400145 INIT_LIST_HEAD(&head);
146 list_add_tail(&head, &piocbq->list);
147 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500148 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500149 if (icmd->ulpBdeCount == 0)
James Smartd7c255b2008-08-24 21:50:00 -0400150 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500151 for (i = 0; i < icmd->ulpBdeCount; i++) {
152 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
153 icmd->un.cont64[i].addrLow);
154 mp = lpfc_sli_ringpostbuf_get(phba, pring,
155 paddr);
156 size = icmd->un.cont64[i].tus.f.bdeSize;
James Smartd7c255b2008-08-24 21:50:00 -0400157 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500158 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500159 }
James Smart495a7142008-06-14 22:52:59 -0400160 lpfc_post_buffer(phba, pring, i);
dea31012005-04-17 16:05:31 -0500161 }
James Smartd7c255b2008-08-24 21:50:00 -0400162 list_del(&head);
dea31012005-04-17 16:05:31 -0500163 }
dea31012005-04-17 16:05:31 -0500164}
165
James Smart6669f9b2009-10-02 15:16:45 -0400166/**
James Smart6dd9e312013-01-03 15:43:37 -0500167 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
James Smart6669f9b2009-10-02 15:16:45 -0400168 * @phba: Pointer to HBA context object.
James Smart6dd9e312013-01-03 15:43:37 -0500169 * @dmabuf: pointer to a dmabuf that describes the FC sequence
James Smart6669f9b2009-10-02 15:16:45 -0400170 *
James Smart6dd9e312013-01-03 15:43:37 -0500171 * This function serves as the upper level protocol abort handler for CT
172 * protocol.
173 *
174 * Return 1 if abort has been handled, 0 otherwise.
James Smart6669f9b2009-10-02 15:16:45 -0400175 **/
James Smart6dd9e312013-01-03 15:43:37 -0500176int
177lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
James Smart6669f9b2009-10-02 15:16:45 -0400178{
James Smart6dd9e312013-01-03 15:43:37 -0500179 int handled;
James Smart6669f9b2009-10-02 15:16:45 -0400180
James Smart6dd9e312013-01-03 15:43:37 -0500181 /* CT upper level goes through BSG */
182 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
James Smart6669f9b2009-10-02 15:16:45 -0400183
James Smart6dd9e312013-01-03 15:43:37 -0500184 return handled;
James Smart6669f9b2009-10-02 15:16:45 -0400185}
186
dea31012005-04-17 16:05:31 -0500187static void
James Smart2e0fef82007-06-17 19:56:36 -0500188lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500189{
190 struct lpfc_dmabuf *mlast, *next_mlast;
191
192 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
193 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
194 list_del(&mlast->list);
195 kfree(mlast);
196 }
197 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
198 kfree(mlist);
199 return;
200}
201
202static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500203lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500204 uint32_t size, int *entries)
205{
206 struct lpfc_dmabuf *mlist = NULL;
207 struct lpfc_dmabuf *mp;
208 int cnt, i = 0;
209
James Smart09372822008-01-11 01:52:54 -0500210 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500211 cnt = size > FCELSSIZE ? FCELSSIZE: size;
212
213 while (size) {
214 /* Allocate buffer for rsp payload */
215 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
216 if (!mp) {
217 if (mlist)
218 lpfc_free_ct_rsp(phba, mlist);
219 return NULL;
220 }
221
222 INIT_LIST_HEAD(&mp->list);
223
James Smart92d7f7b2007-06-17 19:56:38 -0500224 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
225 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500226 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
227 else
228 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
229
230 if (!mp->virt) {
231 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700232 if (mlist)
233 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500234 return NULL;
235 }
236
237 /* Queue it to a linked list */
238 if (!mlist)
239 mlist = mp;
240 else
241 list_add_tail(&mp->list, &mlist->list);
242
James Smart34b02dc2008-08-24 21:49:55 -0400243 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
dea31012005-04-17 16:05:31 -0500244 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500245 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
246 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500247 bpl->tus.f.bdeSize = (uint16_t) cnt;
248 bpl->tus.w = le32_to_cpu(bpl->tus.w);
249 bpl++;
250
251 i++;
252 size -= cnt;
253 }
254
255 *entries = i;
256 return mlist;
257}
258
James Smart858c9f62007-06-17 19:56:39 -0500259int
260lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
261{
262 struct lpfc_dmabuf *buf_ptr;
263
James Smart51ef4c22007-08-02 11:10:31 -0400264 if (ctiocb->context_un.ndlp) {
265 lpfc_nlp_put(ctiocb->context_un.ndlp);
266 ctiocb->context_un.ndlp = NULL;
267 }
James Smart858c9f62007-06-17 19:56:39 -0500268 if (ctiocb->context1) {
269 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
270 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
271 kfree(buf_ptr);
272 ctiocb->context1 = NULL;
273 }
274 if (ctiocb->context2) {
275 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
276 ctiocb->context2 = NULL;
277 }
278
279 if (ctiocb->context3) {
280 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
281 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
282 kfree(buf_ptr);
283 ctiocb->context1 = NULL;
284 }
285 lpfc_sli_release_iocbq(phba, ctiocb);
286 return 0;
287}
288
dea31012005-04-17 16:05:31 -0500289static int
James Smart2e0fef82007-06-17 19:56:36 -0500290lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500291 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
292 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
293 struct lpfc_iocbq *),
294 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500295 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500296{
James Smart2e0fef82007-06-17 19:56:36 -0500297 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500298 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400299 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500300 int rc;
dea31012005-04-17 16:05:31 -0500301
302 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400303 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500304
305 if (geniocb == NULL)
306 return 1;
dea31012005-04-17 16:05:31 -0500307
308 icmd = &geniocb->iocb;
309 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
310 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
311 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400312 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
dea31012005-04-17 16:05:31 -0500313 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
314
315 if (usr_flg)
316 geniocb->context3 = NULL;
317 else
318 geniocb->context3 = (uint8_t *) bmp;
319
320 /* Save for completion so we can release these resources */
321 geniocb->context1 = (uint8_t *) inp;
322 geniocb->context2 = (uint8_t *) outp;
James Smarte47c9092008-02-08 18:49:26 -0500323 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500324
325 /* Fill in payload, bp points to frame payload */
326 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
327
328 /* Fill in rest of iocb */
329 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
330 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
James Smart6a9c52c2009-10-02 15:16:51 -0400331 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
332 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
dea31012005-04-17 16:05:31 -0500333
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500334 if (!tmo) {
335 /* FC spec states we need 3 * ratov for CT requests */
336 tmo = (3 * phba->fc_ratov);
337 }
dea31012005-04-17 16:05:31 -0500338 icmd->ulpTimeout = tmo;
339 icmd->ulpBdeCount = 1;
340 icmd->ulpLe = 1;
341 icmd->ulpClass = CLASS3;
342 icmd->ulpContext = ndlp->nlp_rpi;
James Smart6d368e52011-05-24 11:44:12 -0400343 if (phba->sli_rev == LPFC_SLI_REV4)
344 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
dea31012005-04-17 16:05:31 -0500345
James Smart92d7f7b2007-06-17 19:56:38 -0500346 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
347 /* For GEN_REQUEST64_CR, use the RPI */
348 icmd->ulpCt_h = 0;
349 icmd->ulpCt_l = 0;
350 }
351
dea31012005-04-17 16:05:31 -0500352 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400353 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
354 "0119 Issue GEN REQ IOCB to NPORT x%x "
355 "Data: x%x x%x\n",
356 ndlp->nlp_DID, icmd->ulpIoTag,
357 vport->port_state);
dea31012005-04-17 16:05:31 -0500358 geniocb->iocb_cmpl = cmpl;
359 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500360 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500361 geniocb->retry = retry;
James Smart3772a992009-05-22 14:50:54 -0400362 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -0500363
364 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500365 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500366 return 1;
367 }
dea31012005-04-17 16:05:31 -0500368
369 return 0;
370}
371
372static int
James Smart2e0fef82007-06-17 19:56:36 -0500373lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500374 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
375 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
376 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500377 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500378{
James Smart2e0fef82007-06-17 19:56:36 -0500379 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500380 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
381 struct lpfc_dmabuf *outmp;
382 int cnt = 0, status;
383 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
384 CommandResponse.bits.CmdRsp;
385
386 bpl++; /* Skip past ct request */
387
388 /* Put buffer(s) for ct rsp in bpl */
389 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
390 if (!outmp)
391 return -ENOMEM;
James Smart6a9c52c2009-10-02 15:16:51 -0400392 /*
393 * Form the CT IOCB. The total number of BDEs in this IOCB
394 * is the single command plus response count from
395 * lpfc_alloc_ct_rsp.
396 */
397 cnt += 1;
James Smart2e0fef82007-06-17 19:56:36 -0500398 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart6a9c52c2009-10-02 15:16:51 -0400399 cnt, 0, retry);
dea31012005-04-17 16:05:31 -0500400 if (status) {
401 lpfc_free_ct_rsp(phba, outmp);
402 return -ENOMEM;
403 }
404 return 0;
405}
406
James Smart549e55c2007-08-02 11:09:51 -0400407struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500408lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500409 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400410 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500411
James Smart549e55c2007-08-02 11:09:51 -0400412 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500413 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400414 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
415 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500416 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400417 }
James Smart92d7f7b2007-06-17 19:56:38 -0500418 }
James Smart549e55c2007-08-02 11:09:51 -0400419 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500420 return NULL;
421}
422
dea31012005-04-17 16:05:31 -0500423static int
James Smart2e0fef82007-06-17 19:56:36 -0500424lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500425{
James Smart2e0fef82007-06-17 19:56:36 -0500426 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500427 struct lpfc_sli_ct_request *Response =
428 (struct lpfc_sli_ct_request *) mp->virt;
429 struct lpfc_nodelist *ndlp = NULL;
430 struct lpfc_dmabuf *mlast, *next_mp;
431 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500432 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500433 int Cnt;
434 struct list_head head;
435
James Smart2e0fef82007-06-17 19:56:36 -0500436 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500437 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500438 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500439
dea31012005-04-17 16:05:31 -0500440
441 list_add_tail(&head, &mp->list);
442 list_for_each_entry_safe(mp, next_mp, &head, list) {
443 mlast = mp;
444
James Smart7054a602007-04-25 09:52:34 -0400445 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
446
dea31012005-04-17 16:05:31 -0500447 Size -= Cnt;
448
James Smart1dcb58e2007-04-25 09:51:30 -0400449 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500450 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400451 } else
dea31012005-04-17 16:05:31 -0500452 Cnt -= 16; /* subtract length of CT header */
453
454 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400455 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500456 /* Get next DID from NameServer List */
457 CTentry = *ctptr++;
458 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500459
dea31012005-04-17 16:05:31 -0500460 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500461
462 /*
463 * Check for rscn processing or not
464 * To conserve rpi's, filter out addresses for other
465 * vports on the same physical HBAs.
466 */
467 if ((Did != vport->fc_myDID) &&
468 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400469 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500470 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart98c9ea52007-10-27 13:37:33 -0400471 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
James Smart3de2a652007-08-02 11:09:59 -0400472 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500473 ndlp = lpfc_setup_disc_node(vport, Did);
James Smart58da1ff2008-04-07 10:15:56 -0400474 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart858c9f62007-06-17 19:56:39 -0500475 lpfc_debugfs_disc_trc(vport,
476 LPFC_DISC_TRC_CT,
477 "Parse GID_FTrsp: "
478 "did:x%x flg:x%x x%x",
479 Did, ndlp->nlp_flag,
480 vport->fc_flag);
481
James Smarte8b62012007-08-02 11:10:09 -0400482 lpfc_printf_vlog(vport,
483 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500484 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400485 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500486 "x%x NameServer Rsp"
487 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400488 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500489 vport->fc_flag,
490 vport->fc_rscn_id_cnt);
491 } else {
James Smart858c9f62007-06-17 19:56:39 -0500492 lpfc_debugfs_disc_trc(vport,
493 LPFC_DISC_TRC_CT,
494 "Skip1 GID_FTrsp: "
495 "did:x%x flg:x%x cnt:%d",
496 Did, vport->fc_flag,
497 vport->fc_rscn_id_cnt);
498
James Smarte8b62012007-08-02 11:10:09 -0400499 lpfc_printf_vlog(vport,
500 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500501 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400502 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500503 "NameServer Rsp Data: "
504 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400505 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500506 vport->fc_rscn_id_cnt);
507 }
508
509 } else {
510 if (!(vport->fc_flag & FC_RSCN_MODE) ||
511 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500512 lpfc_debugfs_disc_trc(vport,
513 LPFC_DISC_TRC_CT,
514 "Query GID_FTrsp: "
515 "did:x%x flg:x%x cnt:%d",
516 Did, vport->fc_flag,
517 vport->fc_rscn_id_cnt);
518
James Smart0ff10d42008-01-11 01:52:36 -0500519 /* This NPortID was previously
520 * a FCP target, * Don't even
521 * bother to send GFF_ID.
522 */
523 ndlp = lpfc_findnode_did(vport,
524 Did);
James Smarte47c9092008-02-08 18:49:26 -0500525 if (ndlp &&
526 NLP_CHK_NODE_ACT(ndlp)
527 && (ndlp->nlp_type &
528 NLP_FCP_TARGET))
James Smart0ff10d42008-01-11 01:52:36 -0500529 lpfc_setup_disc_node
530 (vport, Did);
531 else if (lpfc_ns_cmd(vport,
James Smart92d7f7b2007-06-17 19:56:38 -0500532 SLI_CTNS_GFF_ID,
533 0, Did) == 0)
534 vport->num_disc_nodes++;
James Smart6a9c52c2009-10-02 15:16:51 -0400535 else
536 lpfc_setup_disc_node
537 (vport, Did);
James Smart92d7f7b2007-06-17 19:56:38 -0500538 }
539 else {
James Smart858c9f62007-06-17 19:56:39 -0500540 lpfc_debugfs_disc_trc(vport,
541 LPFC_DISC_TRC_CT,
542 "Skip2 GID_FTrsp: "
543 "did:x%x flg:x%x cnt:%d",
544 Did, vport->fc_flag,
545 vport->fc_rscn_id_cnt);
546
James Smarte8b62012007-08-02 11:10:09 -0400547 lpfc_printf_vlog(vport,
548 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500549 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400550 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500551 "NameServer Rsp Data: "
552 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400553 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500554 vport->fc_rscn_id_cnt);
555 }
556 }
dea31012005-04-17 16:05:31 -0500557 }
dea31012005-04-17 16:05:31 -0500558 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
559 goto nsout1;
560 Cnt -= sizeof (uint32_t);
561 }
562 ctptr = NULL;
563
564 }
565
566nsout1:
567 list_del(&head);
dea31012005-04-17 16:05:31 -0500568 return 0;
569}
570
dea31012005-04-17 16:05:31 -0500571static void
James Smart2e0fef82007-06-17 19:56:36 -0500572lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
573 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500574{
James Smart2e0fef82007-06-17 19:56:36 -0500575 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500576 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500577 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500578 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500579 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500580 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400581 struct lpfc_nodelist *ndlp;
James Smart58da1ff2008-04-07 10:15:56 -0400582 int rc;
dea31012005-04-17 16:05:31 -0500583
James Smart51ef4c22007-08-02 11:10:31 -0400584 /* First save ndlp, before we overwrite it */
585 ndlp = cmdiocb->context_un.ndlp;
586
dea31012005-04-17 16:05:31 -0500587 /* we pass cmdiocb to state machine which needs rspiocb as well */
588 cmdiocb->context_un.rsp_iocb = rspiocb;
589
dea31012005-04-17 16:05:31 -0500590 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
591 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500592 irsp = &rspiocb->iocb;
593
594 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
595 "GID_FT cmpl: status:x%x/x%x rtry:%d",
596 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500597
James Smart92d7f7b2007-06-17 19:56:38 -0500598 /* Don't bother processing response if vport is being torn down. */
James Smarteada2722008-12-04 22:39:13 -0500599 if (vport->load_flag & FC_UNLOADING) {
600 if (vport->fc_flag & FC_RSCN_MODE)
601 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500602 goto out;
James Smarteada2722008-12-04 22:39:13 -0500603 }
James Smart92d7f7b2007-06-17 19:56:38 -0500604
James Smart58da1ff2008-04-07 10:15:56 -0400605 if (lpfc_els_chk_latt(vport)) {
James Smarte8b62012007-08-02 11:10:09 -0400606 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
607 "0216 Link event during NS query\n");
James Smarteada2722008-12-04 22:39:13 -0500608 if (vport->fc_flag & FC_RSCN_MODE)
609 lpfc_els_flush_rscn(vport);
James Smart858c9f62007-06-17 19:56:39 -0500610 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
611 goto out;
612 }
James Smart58da1ff2008-04-07 10:15:56 -0400613 if (lpfc_error_lost_link(irsp)) {
614 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
615 "0226 NS query failed due to link event\n");
James Smarteada2722008-12-04 22:39:13 -0500616 if (vport->fc_flag & FC_RSCN_MODE)
617 lpfc_els_flush_rscn(vport);
James Smart58da1ff2008-04-07 10:15:56 -0400618 goto out;
619 }
James Smart858c9f62007-06-17 19:56:39 -0500620 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500621 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500622 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart58da1ff2008-04-07 10:15:56 -0400623 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
James Smartedb22f02012-10-31 14:45:21 -0400624 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
James Smarte3d2b802012-08-14 14:25:43 -0400625 IOERR_NO_RESOURCES)
James Smart858c9f62007-06-17 19:56:39 -0500626 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500627
James Smart58da1ff2008-04-07 10:15:56 -0400628 /* CT command is being retried */
629 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smart92d7f7b2007-06-17 19:56:38 -0500630 vport->fc_ns_retry, 0);
James Smart58da1ff2008-04-07 10:15:56 -0400631 if (rc == 0)
632 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -0500633 }
James Smarteada2722008-12-04 22:39:13 -0500634 if (vport->fc_flag & FC_RSCN_MODE)
635 lpfc_els_flush_rscn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500636 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400637 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
638 "0257 GID_FT Query error: 0x%x 0x%x\n",
639 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500640 } else {
641 /* Good status, continue checking */
642 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
643 if (CTrsp->CommandResponse.bits.CmdRsp ==
644 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400645 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
646 "0208 NameServer Rsp Data: x%x\n",
647 vport->fc_flag);
James Smart2e0fef82007-06-17 19:56:36 -0500648 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500649 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
650 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
651 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
652 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400653 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
654 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400655 lpfc_printf_vlog(vport, KERN_INFO,
656 LOG_DISCOVERY,
657 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400658 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400659 CTrsp->CommandResponse.bits.CmdRsp,
660 (uint32_t) CTrsp->ReasonCode,
661 (uint32_t) CTrsp->Explanation,
662 vport->fc_flag);
663
664 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
665 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
666 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
667 (uint32_t) CTrsp->ReasonCode,
668 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400669 } else {
670 lpfc_printf_vlog(vport, KERN_INFO,
671 LOG_DISCOVERY,
672 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500673 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500674 CTrsp->CommandResponse.bits.CmdRsp,
675 (uint32_t) CTrsp->ReasonCode,
676 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500677 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500678
James Smarta58cbd52007-08-02 11:09:43 -0400679 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500680 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
681 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
682 (uint32_t) CTrsp->ReasonCode,
683 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400684 }
685
James Smart858c9f62007-06-17 19:56:39 -0500686
dea31012005-04-17 16:05:31 -0500687 } else {
688 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400689 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
690 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500691 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500692 CTrsp->CommandResponse.bits.CmdRsp,
693 (uint32_t) CTrsp->ReasonCode,
694 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500695 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500696
697 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
698 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
699 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
700 (uint32_t) CTrsp->ReasonCode,
701 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500702 }
703 }
704 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500705 if (vport->num_disc_nodes == 0) {
706 /*
707 * The driver has cycled through all Nports in the RSCN payload.
708 * Complete the handling by cleaning up and marking the
709 * current driver state.
710 */
711 if (vport->port_state >= LPFC_DISC_AUTH) {
712 if (vport->fc_flag & FC_RSCN_MODE) {
713 lpfc_els_flush_rscn(vport);
714 spin_lock_irq(shost->host_lock);
715 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
716 spin_unlock_irq(shost->host_lock);
717 }
718 else
719 lpfc_els_flush_rscn(vport);
720 }
721
722 lpfc_disc_start(vport);
723 }
dea31012005-04-17 16:05:31 -0500724out:
James Smart51ef4c22007-08-02 11:10:31 -0400725 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500726 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500727 return;
728}
729
James Smart311464e2007-08-02 11:10:37 -0400730static void
James Smart92d7f7b2007-06-17 19:56:38 -0500731lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
732 struct lpfc_iocbq *rspiocb)
733{
734 struct lpfc_vport *vport = cmdiocb->vport;
735 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
736 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500737 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
738 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
739 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500740 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500741 uint8_t fbits;
742 struct lpfc_nodelist *ndlp;
743
744 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
745 did = be32_to_cpu(did);
746
James Smart858c9f62007-06-17 19:56:39 -0500747 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
748 "GFF_ID cmpl: status:x%x/x%x did:x%x",
749 irsp->ulpStatus, irsp->un.ulpWord[4], did);
750
James Smart92d7f7b2007-06-17 19:56:38 -0500751 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
752 /* Good status, continue checking */
753 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
754 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
755
756 if (CTrsp->CommandResponse.bits.CmdRsp ==
757 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
758 if ((fbits & FC4_FEATURE_INIT) &&
759 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400760 lpfc_printf_vlog(vport, KERN_INFO,
761 LOG_DISCOVERY,
762 "0270 Skip x%x GFF "
763 "NameServer Rsp Data: (init) "
764 "x%x x%x\n", did, fbits,
765 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500766 goto out;
767 }
768 }
769 }
James Smart858c9f62007-06-17 19:56:39 -0500770 else {
James Smart0ff10d42008-01-11 01:52:36 -0500771 /* Check for retry */
772 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
773 retry = 1;
774 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
James Smarte3d2b802012-08-14 14:25:43 -0400775 switch ((irsp->un.ulpWord[4] &
776 IOERR_PARAM_MASK)) {
777
James Smart0ff10d42008-01-11 01:52:36 -0500778 case IOERR_NO_RESOURCES:
779 /* We don't increment the retry
780 * count for this case.
781 */
782 break;
783 case IOERR_LINK_DOWN:
784 case IOERR_SLI_ABORTED:
785 case IOERR_SLI_DOWN:
786 retry = 0;
787 break;
788 default:
789 cmdiocb->retry++;
790 }
791 }
792 else
793 cmdiocb->retry++;
794
795 if (retry) {
796 /* CT command is being retried */
797 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
798 cmdiocb->retry, did);
799 if (rc == 0) {
800 /* success */
801 lpfc_ct_free_iocb(phba, cmdiocb);
802 return;
803 }
804 }
805 }
James Smarte8b62012007-08-02 11:10:09 -0400806 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
807 "0267 NameServer GFF Rsp "
808 "x%x Error (%d %d) Data: x%x x%x\n",
809 did, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart7f5f3d02008-02-08 18:50:14 -0500810 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500811 }
812
James Smart92d7f7b2007-06-17 19:56:38 -0500813 /* This is a target port, unregistered port, or the GFF_ID failed */
814 ndlp = lpfc_setup_disc_node(vport, did);
James Smart58da1ff2008-04-07 10:15:56 -0400815 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400816 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
817 "0242 Process x%x GFF "
818 "NameServer Rsp Data: x%x x%x x%x\n",
819 did, ndlp->nlp_flag, vport->fc_flag,
820 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500821 } else {
James Smarte8b62012007-08-02 11:10:09 -0400822 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
823 "0243 Skip x%x GFF "
824 "NameServer Rsp Data: x%x x%x\n", did,
825 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500826 }
827out:
828 /* Link up / RSCN discovery */
829 if (vport->num_disc_nodes)
830 vport->num_disc_nodes--;
831 if (vport->num_disc_nodes == 0) {
832 /*
833 * The driver has cycled through all Nports in the RSCN payload.
834 * Complete the handling by cleaning up and marking the
835 * current driver state.
836 */
837 if (vport->port_state >= LPFC_DISC_AUTH) {
838 if (vport->fc_flag & FC_RSCN_MODE) {
839 lpfc_els_flush_rscn(vport);
840 spin_lock_irq(shost->host_lock);
841 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
842 spin_unlock_irq(shost->host_lock);
843 }
844 else
845 lpfc_els_flush_rscn(vport);
846 }
847 lpfc_disc_start(vport);
848 }
James Smart858c9f62007-06-17 19:56:39 -0500849 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500850 return;
851}
852
853
dea31012005-04-17 16:05:31 -0500854static void
James Smart7ee5d432007-10-27 13:37:17 -0400855lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
856 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500857{
James Smart92d7f7b2007-06-17 19:56:38 -0500858 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500859 struct lpfc_dmabuf *inp;
860 struct lpfc_dmabuf *outp;
861 IOCB_t *irsp;
862 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400863 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500864 int cmdcode, rc;
865 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500866 uint32_t latt;
dea31012005-04-17 16:05:31 -0500867
James Smart51ef4c22007-08-02 11:10:31 -0400868 /* First save ndlp, before we overwrite it */
869 ndlp = cmdiocb->context_un.ndlp;
870
dea31012005-04-17 16:05:31 -0500871 /* we pass cmdiocb to state machine which needs rspiocb as well */
872 cmdiocb->context_un.rsp_iocb = rspiocb;
873
874 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
875 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500876 irsp = &rspiocb->iocb;
877
James Smart92d7f7b2007-06-17 19:56:38 -0500878 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
879 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500880 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
881
James Smart858c9f62007-06-17 19:56:39 -0500882 latt = lpfc_els_chk_latt(vport);
883
884 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400885 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400886 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400887 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
888 latt, irsp->ulpStatus,
889 CTrsp->CommandResponse.bits.CmdRsp,
890 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500891
James Smart858c9f62007-06-17 19:56:39 -0500892 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
893 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
894 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
895
James Smart92d7f7b2007-06-17 19:56:38 -0500896 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400897 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
898 "0268 NS cmd %x Error (%d %d)\n",
899 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500900
James Smart92d7f7b2007-06-17 19:56:38 -0500901 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400902 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
903 IOERR_SLI_DOWN) ||
904 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
905 IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -0500906 goto out;
907
908 retry = cmdiocb->retry;
909 if (retry >= LPFC_MAX_NS_RETRY)
910 goto out;
911
912 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400913 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -0400914 "0250 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500915 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
916 if (rc == 0)
917 goto out;
918 }
919
920out:
James Smart51ef4c22007-08-02 11:10:31 -0400921 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500922 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500923 return;
924}
925
926static void
James Smart7ee5d432007-10-27 13:37:17 -0400927lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
928 struct lpfc_iocbq *rspiocb)
929{
930 IOCB_t *irsp = &rspiocb->iocb;
931 struct lpfc_vport *vport = cmdiocb->vport;
932
James Smart98c9ea52007-10-27 13:37:33 -0400933 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
934 struct lpfc_dmabuf *outp;
935 struct lpfc_sli_ct_request *CTrsp;
936
937 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
938 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
939 if (CTrsp->CommandResponse.bits.CmdRsp ==
940 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
941 vport->ct_flags |= FC_CT_RFT_ID;
942 }
James Smart7ee5d432007-10-27 13:37:17 -0400943 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
944 return;
945}
946
947static void
James Smart2e0fef82007-06-17 19:56:36 -0500948lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
949 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500950{
James Smart7ee5d432007-10-27 13:37:17 -0400951 IOCB_t *irsp = &rspiocb->iocb;
952 struct lpfc_vport *vport = cmdiocb->vport;
953
James Smart98c9ea52007-10-27 13:37:33 -0400954 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
955 struct lpfc_dmabuf *outp;
956 struct lpfc_sli_ct_request *CTrsp;
957
958 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
959 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
960 if (CTrsp->CommandResponse.bits.CmdRsp ==
961 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
962 vport->ct_flags |= FC_CT_RNN_ID;
963 }
James Smart7ee5d432007-10-27 13:37:17 -0400964 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500965 return;
966}
967
968static void
James Smart92d7f7b2007-06-17 19:56:38 -0500969lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
970 struct lpfc_iocbq *rspiocb)
971{
James Smart7ee5d432007-10-27 13:37:17 -0400972 IOCB_t *irsp = &rspiocb->iocb;
973 struct lpfc_vport *vport = cmdiocb->vport;
974
James Smart98c9ea52007-10-27 13:37:33 -0400975 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
976 struct lpfc_dmabuf *outp;
977 struct lpfc_sli_ct_request *CTrsp;
978
979 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
980 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
981 if (CTrsp->CommandResponse.bits.CmdRsp ==
982 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
983 vport->ct_flags |= FC_CT_RSPN_ID;
984 }
James Smart7ee5d432007-10-27 13:37:17 -0400985 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500986 return;
987}
988
989static void
James Smart2e0fef82007-06-17 19:56:36 -0500990lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
991 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500992{
James Smart7ee5d432007-10-27 13:37:17 -0400993 IOCB_t *irsp = &rspiocb->iocb;
994 struct lpfc_vport *vport = cmdiocb->vport;
995
James Smart98c9ea52007-10-27 13:37:33 -0400996 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
997 struct lpfc_dmabuf *outp;
998 struct lpfc_sli_ct_request *CTrsp;
999
1000 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1001 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1002 if (CTrsp->CommandResponse.bits.CmdRsp ==
1003 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1004 vport->ct_flags |= FC_CT_RSNN_NN;
1005 }
James Smart7ee5d432007-10-27 13:37:17 -04001006 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1007 return;
1008}
1009
1010static void
1011lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1012 struct lpfc_iocbq *rspiocb)
1013{
1014 struct lpfc_vport *vport = cmdiocb->vport;
1015
1016 /* even if it fails we will act as though it succeeded. */
1017 vport->ct_flags = 0;
1018 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -05001019 return;
1020}
1021
James Smart2fb9bd82006-12-02 13:33:57 -05001022static void
James Smart92d7f7b2007-06-17 19:56:38 -05001023lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1024 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -05001025{
James Smart92d7f7b2007-06-17 19:56:38 -05001026 IOCB_t *irsp = &rspiocb->iocb;
1027 struct lpfc_vport *vport = cmdiocb->vport;
1028
James Smart98c9ea52007-10-27 13:37:33 -04001029 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1030 struct lpfc_dmabuf *outp;
1031 struct lpfc_sli_ct_request *CTrsp;
1032
1033 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1034 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1035 if (CTrsp->CommandResponse.bits.CmdRsp ==
1036 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1037 vport->ct_flags |= FC_CT_RFF_ID;
1038 }
James Smart7ee5d432007-10-27 13:37:17 -04001039 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001040 return;
1041}
1042
James Smart495a7142008-06-14 22:52:59 -04001043int
James Smart92d7f7b2007-06-17 19:56:38 -05001044lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1045 size_t size)
1046{
1047 int n;
1048 uint8_t *wwn = vport->phba->wwpn;
1049
1050 n = snprintf(symbol, size,
1051 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1052 wwn[0], wwn[1], wwn[2], wwn[3],
1053 wwn[4], wwn[5], wwn[6], wwn[7]);
1054
1055 if (vport->port_type == LPFC_PHYSICAL_PORT)
1056 return n;
1057
1058 if (n < size)
1059 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1060
James Smarteada2722008-12-04 22:39:13 -05001061 if (n < size &&
1062 strlen(vport->fc_vport->symbolic_name))
1063 n += snprintf(symbol + n, size - n, " VName-%s",
1064 vport->fc_vport->symbolic_name);
James Smart92d7f7b2007-06-17 19:56:38 -05001065 return n;
1066}
1067
1068int
1069lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1070 size_t size)
dea31012005-04-17 16:05:31 -05001071{
James Smart6b5151f2012-01-18 16:24:06 -05001072 char fwrev[FW_REV_STR_SIZE];
James Smart92d7f7b2007-06-17 19:56:38 -05001073 int n;
dea31012005-04-17 16:05:31 -05001074
James Smart92d7f7b2007-06-17 19:56:38 -05001075 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001076
James Smart92d7f7b2007-06-17 19:56:38 -05001077 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1078 vport->phba->ModelName, fwrev, lpfc_release_version);
1079 return n;
dea31012005-04-17 16:05:31 -05001080}
1081
1082/*
1083 * lpfc_ns_cmd
1084 * Description:
1085 * Issue Cmd to NameServer
1086 * SLI_CTNS_GID_FT
1087 * LI_CTNS_RFT_ID
1088 */
1089int
James Smart92d7f7b2007-06-17 19:56:38 -05001090lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1091 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001092{
James Smart92d7f7b2007-06-17 19:56:38 -05001093 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001094 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001095 struct lpfc_dmabuf *mp, *bmp;
1096 struct lpfc_sli_ct_request *CtReq;
1097 struct ulp_bde64 *bpl;
1098 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1099 struct lpfc_iocbq *) = NULL;
1100 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001101 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001102 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001103
1104 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05001105 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1106 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
James Smart858c9f62007-06-17 19:56:39 -05001107 rc=1;
1108 goto ns_cmd_exit;
1109 }
dea31012005-04-17 16:05:31 -05001110
1111 /* fill in BDEs for command */
1112 /* Allocate buffer for command payload */
1113 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001114 if (!mp) {
1115 rc=2;
dea31012005-04-17 16:05:31 -05001116 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001117 }
dea31012005-04-17 16:05:31 -05001118
1119 INIT_LIST_HEAD(&mp->list);
1120 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001121 if (!mp->virt) {
1122 rc=3;
dea31012005-04-17 16:05:31 -05001123 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001124 }
dea31012005-04-17 16:05:31 -05001125
1126 /* Allocate buffer for Buffer ptr list */
1127 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001128 if (!bmp) {
1129 rc=4;
dea31012005-04-17 16:05:31 -05001130 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001131 }
dea31012005-04-17 16:05:31 -05001132
1133 INIT_LIST_HEAD(&bmp->list);
1134 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001135 if (!bmp->virt) {
1136 rc=5;
dea31012005-04-17 16:05:31 -05001137 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001138 }
dea31012005-04-17 16:05:31 -05001139
1140 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001141 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1142 "0236 NameServer Req Data: x%x x%x x%x\n",
1143 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001144
1145 bpl = (struct ulp_bde64 *) bmp->virt;
1146 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001147 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1148 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001149 bpl->tus.f.bdeFlags = 0;
1150 if (cmdcode == SLI_CTNS_GID_FT)
1151 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001152 else if (cmdcode == SLI_CTNS_GFF_ID)
1153 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001154 else if (cmdcode == SLI_CTNS_RFT_ID)
1155 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1156 else if (cmdcode == SLI_CTNS_RNN_ID)
1157 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001158 else if (cmdcode == SLI_CTNS_RSPN_ID)
1159 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001160 else if (cmdcode == SLI_CTNS_RSNN_NN)
1161 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001162 else if (cmdcode == SLI_CTNS_DA_ID)
1163 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001164 else if (cmdcode == SLI_CTNS_RFF_ID)
1165 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001166 else
1167 bpl->tus.f.bdeSize = 0;
1168 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1169
1170 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1171 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1172 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1173 CtReq->RevisionId.bits.InId = 0;
1174 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1175 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1176 CtReq->CommandResponse.bits.Size = 0;
1177 switch (cmdcode) {
1178 case SLI_CTNS_GID_FT:
1179 CtReq->CommandResponse.bits.CmdRsp =
1180 be16_to_cpu(SLI_CTNS_GID_FT);
1181 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001182 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001183 vport->port_state = LPFC_NS_QRY;
1184 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001185 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1186 rsp_size = FC_MAX_NS_RSP;
1187 break;
1188
James Smart92d7f7b2007-06-17 19:56:38 -05001189 case SLI_CTNS_GFF_ID:
1190 CtReq->CommandResponse.bits.CmdRsp =
1191 be16_to_cpu(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001192 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001193 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1194 break;
1195
dea31012005-04-17 16:05:31 -05001196 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001197 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001198 CtReq->CommandResponse.bits.CmdRsp =
1199 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001200 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001201 CtReq->un.rft.fcpReg = 1;
1202 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1203 break;
1204
1205 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001206 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001207 CtReq->CommandResponse.bits.CmdRsp =
1208 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001209 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001210 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001211 sizeof (struct lpfc_name));
1212 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1213 break;
1214
James Smart92d7f7b2007-06-17 19:56:38 -05001215 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001216 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001217 CtReq->CommandResponse.bits.CmdRsp =
1218 be16_to_cpu(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001219 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001220 size = sizeof(CtReq->un.rspn.symbname);
1221 CtReq->un.rspn.len =
1222 lpfc_vport_symbolic_port_name(vport,
1223 CtReq->un.rspn.symbname, size);
1224 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1225 break;
dea31012005-04-17 16:05:31 -05001226 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001227 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001228 CtReq->CommandResponse.bits.CmdRsp =
1229 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001230 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001231 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001232 size = sizeof(CtReq->un.rsnn.symbname);
1233 CtReq->un.rsnn.len =
1234 lpfc_vport_symbolic_node_name(vport,
1235 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001236 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1237 break;
James Smart7ee5d432007-10-27 13:37:17 -04001238 case SLI_CTNS_DA_ID:
1239 /* Implement DA_ID Nameserver request */
1240 CtReq->CommandResponse.bits.CmdRsp =
1241 be16_to_cpu(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001242 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001243 cmpl = lpfc_cmpl_ct_cmd_da_id;
1244 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001245 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001246 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001247 CtReq->CommandResponse.bits.CmdRsp =
1248 be16_to_cpu(SLI_CTNS_RFF_ID);
Joe Perchesa419aef2009-08-18 11:18:35 -07001249 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001250 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
James Smart6a9c52c2009-10-02 15:16:51 -04001251 CtReq->un.rff.type_code = FC_TYPE_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001252 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1253 break;
dea31012005-04-17 16:05:31 -05001254 }
James Smarte47c9092008-02-08 18:49:26 -05001255 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1256 * to hold ndlp reference for the corresponding callback function.
1257 */
James Smart858c9f62007-06-17 19:56:39 -05001258 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001259 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001260 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1261 "Issue CT cmd: cmd:x%x did:x%x",
1262 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001263 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001264 }
James Smart858c9f62007-06-17 19:56:39 -05001265 rc=6;
James Smarte47c9092008-02-08 18:49:26 -05001266
1267 /* Decrement ndlp reference count to release ndlp reference held
1268 * for the failed command's callback function.
1269 */
James Smart51ef4c22007-08-02 11:10:31 -04001270 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001271
dea31012005-04-17 16:05:31 -05001272 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1273ns_cmd_free_bmp:
1274 kfree(bmp);
1275ns_cmd_free_mpvirt:
1276 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1277ns_cmd_free_mp:
1278 kfree(mp);
1279ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001280 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1281 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1282 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001283 return 1;
1284}
1285
1286static void
James Smart2e0fef82007-06-17 19:56:36 -05001287lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1288 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001289{
dea31012005-04-17 16:05:31 -05001290 struct lpfc_dmabuf *inp = cmdiocb->context1;
1291 struct lpfc_dmabuf *outp = cmdiocb->context2;
1292 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1293 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1294 struct lpfc_nodelist *ndlp;
1295 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1296 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001297 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001298 IOCB_t *irsp = &rspiocb->iocb;
1299 uint32_t latt;
1300
1301 latt = lpfc_els_chk_latt(vport);
1302
1303 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1304 "FDMI cmpl: status:x%x/x%x latt:%d",
1305 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1306
1307 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001308 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1309 "0229 FDMI cmd %04x failed, latt = %d "
1310 "ulpStatus: x%x, rid x%x\n",
1311 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1312 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001313 lpfc_ct_free_iocb(phba, cmdiocb);
1314 return;
1315 }
dea31012005-04-17 16:05:31 -05001316
James Smart2e0fef82007-06-17 19:56:36 -05001317 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001318 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1319 goto fail_out;
1320
dea31012005-04-17 16:05:31 -05001321 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1322 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001323 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1324 "0220 FDMI rsp failed Data: x%x\n",
1325 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001326 }
1327
1328 switch (be16_to_cpu(fdmi_cmd)) {
1329 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001330 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001331 break;
1332
1333 case SLI_MGMT_RPA:
1334 break;
1335
1336 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001337 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001338 break;
1339
1340 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001341 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001342 break;
1343 }
James Smarte47c9092008-02-08 18:49:26 -05001344
1345fail_out:
James Smart858c9f62007-06-17 19:56:39 -05001346 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001347 return;
1348}
James Smart2e0fef82007-06-17 19:56:36 -05001349
dea31012005-04-17 16:05:31 -05001350int
James Smart2e0fef82007-06-17 19:56:36 -05001351lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001352{
James Smart2e0fef82007-06-17 19:56:36 -05001353 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001354 struct lpfc_dmabuf *mp, *bmp;
1355 struct lpfc_sli_ct_request *CtReq;
1356 struct ulp_bde64 *bpl;
1357 uint32_t size;
1358 REG_HBA *rh;
1359 PORT_ENTRY *pe;
1360 REG_PORT_ATTRIBUTE *pab;
1361 ATTRIBUTE_BLOCK *ab;
1362 ATTRIBUTE_ENTRY *ae;
1363 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1364 struct lpfc_iocbq *);
1365
1366
1367 /* fill in BDEs for command */
1368 /* Allocate buffer for command payload */
1369 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1370 if (!mp)
1371 goto fdmi_cmd_exit;
1372
1373 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1374 if (!mp->virt)
1375 goto fdmi_cmd_free_mp;
1376
1377 /* Allocate buffer for Buffer ptr list */
1378 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1379 if (!bmp)
1380 goto fdmi_cmd_free_mpvirt;
1381
1382 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1383 if (!bmp->virt)
1384 goto fdmi_cmd_free_bmp;
1385
1386 INIT_LIST_HEAD(&mp->list);
1387 INIT_LIST_HEAD(&bmp->list);
1388
1389 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001390 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1391 "0218 FDMI Request Data: x%x x%x x%x\n",
1392 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001393 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1394
1395 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1396 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1397 CtReq->RevisionId.bits.InId = 0;
1398
1399 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1400 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1401 size = 0;
1402
1403 switch (cmdcode) {
1404 case SLI_MGMT_RHBA:
1405 {
1406 lpfc_vpd_t *vp = &phba->vpd;
1407 uint32_t i, j, incr;
1408 int len;
1409
1410 CtReq->CommandResponse.bits.CmdRsp =
1411 be16_to_cpu(SLI_MGMT_RHBA);
1412 CtReq->CommandResponse.bits.Size = 0;
1413 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001414 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001415 sizeof (struct lpfc_name));
1416 /* One entry (port) per adapter */
1417 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001418 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001419 sizeof (struct lpfc_name));
1420
1421 /* point to the HBA attribute block */
1422 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1423 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1424 ab->EntryCnt = 0;
1425
1426 /* Point to the beginning of the first HBA attribute
1427 entry */
1428 /* #1 HBA attribute entry */
1429 size += FOURBYTES;
1430 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1431 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1432 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1433 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001434 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001435 sizeof (struct lpfc_name));
1436 ab->EntryCnt++;
1437 size += FOURBYTES + sizeof (struct lpfc_name);
1438
1439 /* #2 HBA attribute entry */
1440 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1441 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1442 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1443 len = strlen(ae->un.Manufacturer);
1444 len += (len & 3) ? (4 - (len & 3)) : 4;
1445 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1446 ab->EntryCnt++;
1447 size += FOURBYTES + len;
1448
1449 /* #3 HBA attribute entry */
1450 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1451 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1452 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1453 len = strlen(ae->un.SerialNumber);
1454 len += (len & 3) ? (4 - (len & 3)) : 4;
1455 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1456 ab->EntryCnt++;
1457 size += FOURBYTES + len;
1458
1459 /* #4 HBA attribute entry */
1460 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1461 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1462 strcpy(ae->un.Model, phba->ModelName);
1463 len = strlen(ae->un.Model);
1464 len += (len & 3) ? (4 - (len & 3)) : 4;
1465 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1466 ab->EntryCnt++;
1467 size += FOURBYTES + len;
1468
1469 /* #5 HBA attribute entry */
1470 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1471 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1472 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1473 len = strlen(ae->un.ModelDescription);
1474 len += (len & 3) ? (4 - (len & 3)) : 4;
1475 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1476 ab->EntryCnt++;
1477 size += FOURBYTES + len;
1478
1479 /* #6 HBA attribute entry */
1480 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1481 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1482 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1483 /* Convert JEDEC ID to ascii for hardware version */
1484 incr = vp->rev.biuRev;
1485 for (i = 0; i < 8; i++) {
1486 j = (incr & 0xf);
1487 if (j <= 9)
1488 ae->un.HardwareVersion[7 - i] =
1489 (char)((uint8_t) 0x30 +
1490 (uint8_t) j);
1491 else
1492 ae->un.HardwareVersion[7 - i] =
1493 (char)((uint8_t) 0x61 +
1494 (uint8_t) (j - 10));
1495 incr = (incr >> 4);
1496 }
1497 ab->EntryCnt++;
1498 size += FOURBYTES + 8;
1499
1500 /* #7 HBA attribute entry */
1501 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1502 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1503 strcpy(ae->un.DriverVersion, lpfc_release_version);
1504 len = strlen(ae->un.DriverVersion);
1505 len += (len & 3) ? (4 - (len & 3)) : 4;
1506 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1507 ab->EntryCnt++;
1508 size += FOURBYTES + len;
1509
1510 /* #8 HBA attribute entry */
1511 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1512 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1513 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1514 len = strlen(ae->un.OptionROMVersion);
1515 len += (len & 3) ? (4 - (len & 3)) : 4;
1516 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1517 ab->EntryCnt++;
1518 size += FOURBYTES + len;
1519
1520 /* #9 HBA attribute entry */
1521 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1522 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1523 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1524 1);
1525 len = strlen(ae->un.FirmwareVersion);
1526 len += (len & 3) ? (4 - (len & 3)) : 4;
1527 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1528 ab->EntryCnt++;
1529 size += FOURBYTES + len;
1530
1531 /* #10 HBA attribute entry */
1532 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1533 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1534 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001535 init_utsname()->sysname,
1536 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001537 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001538 len = strlen(ae->un.OsNameVersion);
1539 len += (len & 3) ? (4 - (len & 3)) : 4;
1540 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1541 ab->EntryCnt++;
1542 size += FOURBYTES + len;
1543
1544 /* #11 HBA attribute entry */
1545 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1546 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1547 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1548 ae->un.MaxCTPayloadLen = (65 * 4096);
1549 ab->EntryCnt++;
1550 size += FOURBYTES + 4;
1551
1552 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1553 /* Total size */
1554 size = GID_REQUEST_SZ - 4 + size;
1555 }
1556 break;
1557
1558 case SLI_MGMT_RPA:
1559 {
1560 lpfc_vpd_t *vp;
1561 struct serv_parm *hsp;
1562 int len;
1563
1564 vp = &phba->vpd;
1565
1566 CtReq->CommandResponse.bits.CmdRsp =
1567 be16_to_cpu(SLI_MGMT_RPA);
1568 CtReq->CommandResponse.bits.Size = 0;
1569 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1570 size = sizeof (struct lpfc_name) + FOURBYTES;
1571 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001572 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001573 sizeof (struct lpfc_name));
1574 pab->ab.EntryCnt = 0;
1575
1576 /* #1 Port attribute entry */
1577 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1578 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1579 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1580 ae->un.SupportFC4Types[2] = 1;
1581 ae->un.SupportFC4Types[7] = 1;
1582 pab->ab.EntryCnt++;
1583 size += FOURBYTES + 32;
1584
1585 /* #2 Port attribute entry */
1586 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1587 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1588 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001589
1590 ae->un.SupportSpeed = 0;
James Smart76a95d72010-11-20 23:11:48 -05001591 if (phba->lmt & LMT_16Gb)
1592 ae->un.SupportSpeed |= HBA_PORTSPEED_16GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001593 if (phba->lmt & LMT_10Gb)
James Smart76a95d72010-11-20 23:11:48 -05001594 ae->un.SupportSpeed |= HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001595 if (phba->lmt & LMT_8Gb)
1596 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1597 if (phba->lmt & LMT_4Gb)
1598 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1599 if (phba->lmt & LMT_2Gb)
1600 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1601 if (phba->lmt & LMT_1Gb)
1602 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1603
dea31012005-04-17 16:05:31 -05001604 pab->ab.EntryCnt++;
1605 size += FOURBYTES + 4;
1606
1607 /* #3 Port attribute entry */
1608 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1609 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1610 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1611 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05001612 case LPFC_LINK_SPEED_1GHZ:
1613 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05001614 break;
James Smart76a95d72010-11-20 23:11:48 -05001615 case LPFC_LINK_SPEED_2GHZ:
1616 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05001617 break;
James Smart76a95d72010-11-20 23:11:48 -05001618 case LPFC_LINK_SPEED_4GHZ:
1619 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05001620 break;
James Smart76a95d72010-11-20 23:11:48 -05001621 case LPFC_LINK_SPEED_8GHZ:
1622 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04001623 break;
James Smart76a95d72010-11-20 23:11:48 -05001624 case LPFC_LINK_SPEED_10GHZ:
1625 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04001626 break;
James Smart76a95d72010-11-20 23:11:48 -05001627 case LPFC_LINK_SPEED_16GHZ:
1628 ae->un.PortSpeed = HBA_PORTSPEED_16GBIT;
1629 break;
1630 default:
1631 ae->un.PortSpeed = HBA_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05001632 break;
1633 }
1634 pab->ab.EntryCnt++;
1635 size += FOURBYTES + 4;
1636
1637 /* #4 Port attribute entry */
1638 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1639 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1640 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001641 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001642 ae->un.MaxFrameSize =
1643 (((uint32_t) hsp->cmn.
1644 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1645 bbRcvSizeLsb;
1646 pab->ab.EntryCnt++;
1647 size += FOURBYTES + 4;
1648
1649 /* #5 Port attribute entry */
1650 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1651 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1652 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1653 len = strlen((char *)ae->un.OsDeviceName);
1654 len += (len & 3) ? (4 - (len & 3)) : 4;
1655 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1656 pab->ab.EntryCnt++;
1657 size += FOURBYTES + len;
1658
James Smart3de2a652007-08-02 11:09:59 -04001659 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001660 /* #6 Port attribute entry */
1661 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1662 size);
1663 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1664 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001665 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001666 len = strlen(ae->un.HostName);
1667 len += (len & 3) ? (4 - (len & 3)) : 4;
1668 ae->ad.bits.AttrLen =
1669 be16_to_cpu(FOURBYTES + len);
1670 pab->ab.EntryCnt++;
1671 size += FOURBYTES + len;
1672 }
1673
1674 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1675 /* Total size */
1676 size = GID_REQUEST_SZ - 4 + size;
1677 }
1678 break;
1679
1680 case SLI_MGMT_DHBA:
1681 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1682 CtReq->CommandResponse.bits.Size = 0;
1683 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1684 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001685 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001686 sizeof (struct lpfc_name));
1687 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1688 break;
1689
1690 case SLI_MGMT_DPRT:
1691 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1692 CtReq->CommandResponse.bits.Size = 0;
1693 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1694 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001695 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001696 sizeof (struct lpfc_name));
1697 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1698 break;
1699 }
1700
1701 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001702 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1703 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001704 bpl->tus.f.bdeFlags = 0;
1705 bpl->tus.f.bdeSize = size;
1706 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1707
1708 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1709
James Smarte47c9092008-02-08 18:49:26 -05001710 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1711 * to hold ndlp reference for the corresponding callback function.
1712 */
James Smart92d7f7b2007-06-17 19:56:38 -05001713 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001714 return 0;
1715
James Smarte47c9092008-02-08 18:49:26 -05001716 /* Decrement ndlp reference count to release ndlp reference held
1717 * for the failed command's callback function.
1718 */
James Smart51ef4c22007-08-02 11:10:31 -04001719 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001720
dea31012005-04-17 16:05:31 -05001721 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1722fdmi_cmd_free_bmp:
1723 kfree(bmp);
1724fdmi_cmd_free_mpvirt:
1725 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1726fdmi_cmd_free_mp:
1727 kfree(mp);
1728fdmi_cmd_exit:
1729 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001730 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1731 "0244 Issue FDMI request failed Data: x%x\n",
1732 cmdcode);
dea31012005-04-17 16:05:31 -05001733 return 1;
1734}
1735
James Smart92494142011-02-16 12:39:44 -05001736/**
1737 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
1738 * @ptr - Context object of the timer.
1739 *
1740 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
1741 * the worker thread.
1742 **/
1743void
1744lpfc_delayed_disc_tmo(unsigned long ptr)
1745{
1746 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1747 struct lpfc_hba *phba = vport->phba;
1748 uint32_t tmo_posted;
1749 unsigned long iflag;
1750
1751 spin_lock_irqsave(&vport->work_port_lock, iflag);
1752 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
1753 if (!tmo_posted)
1754 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
1755 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1756
1757 if (!tmo_posted)
1758 lpfc_worker_wake_up(phba);
1759 return;
1760}
1761
1762/**
1763 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
1764 * handle delayed discovery.
1765 * @vport: pointer to a host virtual N_Port data structure.
1766 *
1767 * This function start nport discovery of the vport.
1768 **/
1769void
1770lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
1771{
1772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1773
1774 spin_lock_irq(shost->host_lock);
1775 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
1776 spin_unlock_irq(shost->host_lock);
1777 return;
1778 }
1779 vport->fc_flag &= ~FC_DISC_DELAYED;
1780 spin_unlock_irq(shost->host_lock);
1781
1782 lpfc_do_scr_ns_plogi(vport->phba, vport);
1783}
1784
dea31012005-04-17 16:05:31 -05001785void
1786lpfc_fdmi_tmo(unsigned long ptr)
1787{
James Smart2e0fef82007-06-17 19:56:36 -05001788 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1789 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001790 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05001791 unsigned long iflag;
1792
James Smart2e0fef82007-06-17 19:56:36 -05001793 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001794 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1795 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05001796 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04001797 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001798
James Smart5e9d9b82008-06-14 22:52:53 -04001799 if (!tmo_posted)
1800 lpfc_worker_wake_up(phba);
1801 return;
dea31012005-04-17 16:05:31 -05001802}
1803
1804void
James Smart2e0fef82007-06-17 19:56:36 -05001805lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001806{
1807 struct lpfc_nodelist *ndlp;
1808
James Smart2e0fef82007-06-17 19:56:36 -05001809 ndlp = lpfc_findnode_did(vport, FDMI_DID);
James Smarte47c9092008-02-08 18:49:26 -05001810 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001811 if (init_utsname()->nodename[0] != '\0')
1812 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1813 else
1814 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001815 }
dea31012005-04-17 16:05:31 -05001816 return;
1817}
1818
dea31012005-04-17 16:05:31 -05001819void
James Smart2e0fef82007-06-17 19:56:36 -05001820lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001821{
1822 struct lpfc_sli *psli = &phba->sli;
1823 lpfc_vpd_t *vp = &phba->vpd;
1824 uint32_t b1, b2, b3, b4, i, rev;
1825 char c;
1826 uint32_t *ptr, str[4];
1827 uint8_t *fwname;
1828
James Smartf1126682009-06-10 17:22:44 -04001829 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart6b5151f2012-01-18 16:24:06 -05001830 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
James Smartf1126682009-06-10 17:22:44 -04001831 else if (vp->rev.rBit) {
James Smartf4b4c682009-05-22 14:53:12 -04001832 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001833 rev = vp->rev.sli2FwRev;
1834 else
1835 rev = vp->rev.sli1FwRev;
1836
1837 b1 = (rev & 0x0000f000) >> 12;
1838 b2 = (rev & 0x00000f00) >> 8;
1839 b3 = (rev & 0x000000c0) >> 6;
1840 b4 = (rev & 0x00000030) >> 4;
1841
1842 switch (b4) {
1843 case 0:
1844 c = 'N';
1845 break;
1846 case 1:
1847 c = 'A';
1848 break;
1849 case 2:
1850 c = 'B';
1851 break;
James Smart73d91e52011-10-10 21:32:10 -04001852 case 3:
1853 c = 'X';
1854 break;
dea31012005-04-17 16:05:31 -05001855 default:
1856 c = 0;
1857 break;
1858 }
1859 b4 = (rev & 0x0000000f);
1860
James Smartf4b4c682009-05-22 14:53:12 -04001861 if (psli->sli_flag & LPFC_SLI_ACTIVE)
dea31012005-04-17 16:05:31 -05001862 fwname = vp->rev.sli2FwName;
1863 else
1864 fwname = vp->rev.sli1FwName;
1865
1866 for (i = 0; i < 16; i++)
1867 if (fwname[i] == 0x20)
1868 fwname[i] = 0;
1869
1870 ptr = (uint32_t*)fwname;
1871
1872 for (i = 0; i < 3; i++)
1873 str[i] = be32_to_cpu(*ptr++);
1874
1875 if (c == 0) {
1876 if (flag)
1877 sprintf(fwrevision, "%d.%d%d (%s)",
1878 b1, b2, b3, (char *)str);
1879 else
1880 sprintf(fwrevision, "%d.%d%d", b1,
1881 b2, b3);
1882 } else {
1883 if (flag)
1884 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1885 b1, b2, b3, c,
1886 b4, (char *)str);
1887 else
1888 sprintf(fwrevision, "%d.%d%d%c%d",
1889 b1, b2, b3, c, b4);
1890 }
1891 } else {
1892 rev = vp->rev.smFwRev;
1893
1894 b1 = (rev & 0xff000000) >> 24;
1895 b2 = (rev & 0x00f00000) >> 20;
1896 b3 = (rev & 0x000f0000) >> 16;
1897 c = (rev & 0x0000ff00) >> 8;
1898 b4 = (rev & 0x000000ff);
1899
Roel Kluind44a6d22010-01-17 16:15:57 +01001900 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
dea31012005-04-17 16:05:31 -05001901 }
1902 return;
1903}