blob: 92441ce610ede4601dd113ee9175f7ef5ebc81e8 [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 Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 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>
28#include <linux/utsname.h>
29
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050031#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040033#include <scsi/scsi_transport_fc.h>
dea31012005-04-17 16:05:31 -050034
35#include "lpfc_hw.h"
36#include "lpfc_sli.h"
37#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
42#include "lpfc_version.h"
James Smart92d7f7b2007-06-17 19:56:38 -050043#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050044#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050045
46#define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
47 * incapable of reporting */
48#define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
49#define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
50#define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
51#define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
52#define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
53#define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
54
55#define FOURBYTES 4
56
57
58static char *lpfc_release_version = LPFC_DRIVER_VERSION;
59
James Smarted957682007-06-17 19:56:37 -050060static void
61lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050062 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050063{
James Smarted957682007-06-17 19:56:37 -050064 if (!mp) {
James Smart9c2face2008-01-11 01:53:18 -050065 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
66 "0146 Ignoring unsolicted CT No HBQ "
67 "status = x%x\n",
68 piocbq->iocb.ulpStatus);
James Smarted957682007-06-17 19:56:37 -050069 }
James Smart9c2face2008-01-11 01:53:18 -050070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
71 "0145 Ignoring unsolicted CT HBQ Size:%d "
72 "status = x%x\n",
73 size, piocbq->iocb.ulpStatus);
74}
75
76static void
77lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
78 struct lpfc_dmabuf *mp, uint32_t size)
79{
80 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
James Smarted957682007-06-17 19:56:37 -050081}
82
dea31012005-04-17 16:05:31 -050083void
James Smart2e0fef82007-06-17 19:56:36 -050084lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
85 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -050086{
James Smart92d7f7b2007-06-17 19:56:38 -050087
James Smarted957682007-06-17 19:56:37 -050088 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -050089 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -050090 int i;
91 struct lpfc_iocbq *iocbq;
92 dma_addr_t paddr;
93 uint32_t size;
James Smart9c2face2008-01-11 01:53:18 -050094 struct list_head head;
95 struct lpfc_dmabuf *bdeBuf;
James Smart92d7f7b2007-06-17 19:56:38 -050096
97 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
98 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
99 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
100 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500101 /* Not enough posted buffers; Try posting more buffers */
102 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500103 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart9c2face2008-01-11 01:53:18 -0500104 lpfc_post_buffer(phba, pring, 2, 1);
dea31012005-04-17 16:05:31 -0500105 return;
106 }
107
108 /* If there are no BDEs associated with this IOCB,
109 * there is nothing to do.
110 */
111 if (icmd->ulpBdeCount == 0)
112 return;
113
James Smarted957682007-06-17 19:56:37 -0500114 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart9c2face2008-01-11 01:53:18 -0500115 INIT_LIST_HEAD(&head);
116 list_add_tail(&head, &piocbq->list);
117 list_for_each_entry(iocbq, &head, list) {
James Smarted957682007-06-17 19:56:37 -0500118 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500119 if (icmd->ulpBdeCount == 0)
James Smarted957682007-06-17 19:56:37 -0500120 continue;
James Smart9c2face2008-01-11 01:53:18 -0500121 bdeBuf = iocbq->context2;
122 iocbq->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -0500123 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart9c2face2008-01-11 01:53:18 -0500124 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
125 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500126 if (icmd->ulpBdeCount == 2) {
James Smart9c2face2008-01-11 01:53:18 -0500127 bdeBuf = iocbq->context3;
128 iocbq->context3 = NULL;
129 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
130 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
131 size);
132 lpfc_in_buf_free(phba, bdeBuf);
James Smarted957682007-06-17 19:56:37 -0500133 }
dea31012005-04-17 16:05:31 -0500134 }
James Smart9c2face2008-01-11 01:53:18 -0500135 list_del(&head);
James Smarted957682007-06-17 19:56:37 -0500136 } else {
137 struct lpfc_iocbq *next;
dea31012005-04-17 16:05:31 -0500138
James Smarted957682007-06-17 19:56:37 -0500139 list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
140 icmd = &iocbq->iocb;
James Smart9c2face2008-01-11 01:53:18 -0500141 if (icmd->ulpBdeCount == 0)
142 lpfc_ct_unsol_buffer(phba, piocbq, NULL, 0);
James Smarted957682007-06-17 19:56:37 -0500143 for (i = 0; i < icmd->ulpBdeCount; i++) {
144 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
145 icmd->un.cont64[i].addrLow);
146 mp = lpfc_sli_ringpostbuf_get(phba, pring,
147 paddr);
148 size = icmd->un.cont64[i].tus.f.bdeSize;
149 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500150 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500151 }
152 list_del(&iocbq->list);
153 lpfc_sli_release_iocbq(phba, iocbq);
James Smart9c2face2008-01-11 01:53:18 -0500154 lpfc_post_buffer(phba, pring, i, 1);
dea31012005-04-17 16:05:31 -0500155 }
dea31012005-04-17 16:05:31 -0500156 }
dea31012005-04-17 16:05:31 -0500157}
158
159static void
James Smart2e0fef82007-06-17 19:56:36 -0500160lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500161{
162 struct lpfc_dmabuf *mlast, *next_mlast;
163
164 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
165 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
166 list_del(&mlast->list);
167 kfree(mlast);
168 }
169 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
170 kfree(mlist);
171 return;
172}
173
174static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500175lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500176 uint32_t size, int *entries)
177{
178 struct lpfc_dmabuf *mlist = NULL;
179 struct lpfc_dmabuf *mp;
180 int cnt, i = 0;
181
James Smart09372822008-01-11 01:52:54 -0500182 /* We get chunks of FCELSSIZE */
dea31012005-04-17 16:05:31 -0500183 cnt = size > FCELSSIZE ? FCELSSIZE: size;
184
185 while (size) {
186 /* Allocate buffer for rsp payload */
187 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
188 if (!mp) {
189 if (mlist)
190 lpfc_free_ct_rsp(phba, mlist);
191 return NULL;
192 }
193
194 INIT_LIST_HEAD(&mp->list);
195
James Smart92d7f7b2007-06-17 19:56:38 -0500196 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
197 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500198 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
199 else
200 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
201
202 if (!mp->virt) {
203 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700204 if (mlist)
205 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500206 return NULL;
207 }
208
209 /* Queue it to a linked list */
210 if (!mlist)
211 mlist = mp;
212 else
213 list_add_tail(&mp->list, &mlist->list);
214
215 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
216 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500217 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
218 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500219 bpl->tus.f.bdeSize = (uint16_t) cnt;
220 bpl->tus.w = le32_to_cpu(bpl->tus.w);
221 bpl++;
222
223 i++;
224 size -= cnt;
225 }
226
227 *entries = i;
228 return mlist;
229}
230
James Smart858c9f62007-06-17 19:56:39 -0500231int
232lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
233{
234 struct lpfc_dmabuf *buf_ptr;
235
James Smart51ef4c22007-08-02 11:10:31 -0400236 if (ctiocb->context_un.ndlp) {
237 lpfc_nlp_put(ctiocb->context_un.ndlp);
238 ctiocb->context_un.ndlp = NULL;
239 }
James Smart858c9f62007-06-17 19:56:39 -0500240 if (ctiocb->context1) {
241 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
242 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
243 kfree(buf_ptr);
244 ctiocb->context1 = NULL;
245 }
246 if (ctiocb->context2) {
247 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
248 ctiocb->context2 = NULL;
249 }
250
251 if (ctiocb->context3) {
252 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
253 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
254 kfree(buf_ptr);
255 ctiocb->context1 = NULL;
256 }
257 lpfc_sli_release_iocbq(phba, ctiocb);
258 return 0;
259}
260
dea31012005-04-17 16:05:31 -0500261static int
James Smart2e0fef82007-06-17 19:56:36 -0500262lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500263 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
264 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
265 struct lpfc_iocbq *),
266 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500267 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500268{
James Smart2e0fef82007-06-17 19:56:36 -0500269 struct lpfc_hba *phba = vport->phba;
270 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500271 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500272 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400273 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500274 int rc;
dea31012005-04-17 16:05:31 -0500275
276 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400277 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500278
279 if (geniocb == NULL)
280 return 1;
dea31012005-04-17 16:05:31 -0500281
282 icmd = &geniocb->iocb;
283 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
284 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
285 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
286 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
287 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
288
289 if (usr_flg)
290 geniocb->context3 = NULL;
291 else
292 geniocb->context3 = (uint8_t *) bmp;
293
294 /* Save for completion so we can release these resources */
295 geniocb->context1 = (uint8_t *) inp;
296 geniocb->context2 = (uint8_t *) outp;
James Smart51ef4c22007-08-02 11:10:31 -0400297 geniocb->context_un.ndlp = ndlp;
dea31012005-04-17 16:05:31 -0500298
299 /* Fill in payload, bp points to frame payload */
300 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
301
302 /* Fill in rest of iocb */
303 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
304 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
305 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
306 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
307
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500308 if (!tmo) {
309 /* FC spec states we need 3 * ratov for CT requests */
310 tmo = (3 * phba->fc_ratov);
311 }
dea31012005-04-17 16:05:31 -0500312 icmd->ulpTimeout = tmo;
313 icmd->ulpBdeCount = 1;
314 icmd->ulpLe = 1;
315 icmd->ulpClass = CLASS3;
316 icmd->ulpContext = ndlp->nlp_rpi;
317
James Smart92d7f7b2007-06-17 19:56:38 -0500318 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
319 /* For GEN_REQUEST64_CR, use the RPI */
320 icmd->ulpCt_h = 0;
321 icmd->ulpCt_l = 0;
322 }
323
dea31012005-04-17 16:05:31 -0500324 /* Issue GEN REQ IOCB for NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400325 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
326 "0119 Issue GEN REQ IOCB to NPORT x%x "
327 "Data: x%x x%x\n",
328 ndlp->nlp_DID, icmd->ulpIoTag,
329 vport->port_state);
dea31012005-04-17 16:05:31 -0500330 geniocb->iocb_cmpl = cmpl;
331 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500332 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500333 geniocb->retry = retry;
334 rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
335
336 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500337 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500338 return 1;
339 }
dea31012005-04-17 16:05:31 -0500340
341 return 0;
342}
343
344static int
James Smart2e0fef82007-06-17 19:56:36 -0500345lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500346 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
347 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
348 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500349 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500350{
James Smart2e0fef82007-06-17 19:56:36 -0500351 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500352 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
353 struct lpfc_dmabuf *outmp;
354 int cnt = 0, status;
355 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
356 CommandResponse.bits.CmdRsp;
357
358 bpl++; /* Skip past ct request */
359
360 /* Put buffer(s) for ct rsp in bpl */
361 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
362 if (!outmp)
363 return -ENOMEM;
364
James Smart2e0fef82007-06-17 19:56:36 -0500365 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart92d7f7b2007-06-17 19:56:38 -0500366 cnt+1, 0, retry);
dea31012005-04-17 16:05:31 -0500367 if (status) {
368 lpfc_free_ct_rsp(phba, outmp);
369 return -ENOMEM;
370 }
371 return 0;
372}
373
James Smart549e55c2007-08-02 11:09:51 -0400374struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -0500375lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
James Smart92d7f7b2007-06-17 19:56:38 -0500376 struct lpfc_vport *vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400377 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -0500378
James Smart549e55c2007-08-02 11:09:51 -0400379 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500380 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -0400381 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
382 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500383 return vport_curr;
James Smart549e55c2007-08-02 11:09:51 -0400384 }
James Smart92d7f7b2007-06-17 19:56:38 -0500385 }
James Smart549e55c2007-08-02 11:09:51 -0400386 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -0500387 return NULL;
388}
389
dea31012005-04-17 16:05:31 -0500390static int
James Smart2e0fef82007-06-17 19:56:36 -0500391lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500392{
James Smart2e0fef82007-06-17 19:56:36 -0500393 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500394 struct lpfc_sli_ct_request *Response =
395 (struct lpfc_sli_ct_request *) mp->virt;
396 struct lpfc_nodelist *ndlp = NULL;
397 struct lpfc_dmabuf *mlast, *next_mp;
398 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500399 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500400 int Cnt;
401 struct list_head head;
402
James Smart2e0fef82007-06-17 19:56:36 -0500403 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500404 vport->num_disc_nodes = 0;
James Smart0ff10d42008-01-11 01:52:36 -0500405 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -0500406
dea31012005-04-17 16:05:31 -0500407
408 list_add_tail(&head, &mp->list);
409 list_for_each_entry_safe(mp, next_mp, &head, list) {
410 mlast = mp;
411
James Smart7054a602007-04-25 09:52:34 -0400412 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
413
dea31012005-04-17 16:05:31 -0500414 Size -= Cnt;
415
James Smart1dcb58e2007-04-25 09:51:30 -0400416 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500417 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400418 } else
dea31012005-04-17 16:05:31 -0500419 Cnt -= 16; /* subtract length of CT header */
420
421 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400422 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500423 /* Get next DID from NameServer List */
424 CTentry = *ctptr++;
425 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500426
dea31012005-04-17 16:05:31 -0500427 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500428
429 /*
430 * Check for rscn processing or not
431 * To conserve rpi's, filter out addresses for other
432 * vports on the same physical HBAs.
433 */
434 if ((Did != vport->fc_myDID) &&
435 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
James Smart3de2a652007-08-02 11:09:59 -0400436 vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500437 if ((vport->port_type != LPFC_NPIV_PORT) ||
James Smart98c9ea52007-10-27 13:37:33 -0400438 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
James Smart3de2a652007-08-02 11:09:59 -0400439 (!vport->cfg_restrict_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500440 ndlp = lpfc_setup_disc_node(vport, Did);
441 if (ndlp) {
James Smart858c9f62007-06-17 19:56:39 -0500442 lpfc_debugfs_disc_trc(vport,
443 LPFC_DISC_TRC_CT,
444 "Parse GID_FTrsp: "
445 "did:x%x flg:x%x x%x",
446 Did, ndlp->nlp_flag,
447 vport->fc_flag);
448
James Smarte8b62012007-08-02 11:10:09 -0400449 lpfc_printf_vlog(vport,
450 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500451 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400452 "0238 Process "
James Smart92d7f7b2007-06-17 19:56:38 -0500453 "x%x NameServer Rsp"
454 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400455 Did, ndlp->nlp_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500456 vport->fc_flag,
457 vport->fc_rscn_id_cnt);
458 } else {
James Smart858c9f62007-06-17 19:56:39 -0500459 lpfc_debugfs_disc_trc(vport,
460 LPFC_DISC_TRC_CT,
461 "Skip1 GID_FTrsp: "
462 "did:x%x flg:x%x cnt:%d",
463 Did, vport->fc_flag,
464 vport->fc_rscn_id_cnt);
465
James Smarte8b62012007-08-02 11:10:09 -0400466 lpfc_printf_vlog(vport,
467 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500468 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400469 "0239 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500470 "NameServer Rsp Data: "
471 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400472 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500473 vport->fc_rscn_id_cnt);
474 }
475
476 } else {
477 if (!(vport->fc_flag & FC_RSCN_MODE) ||
478 (lpfc_rscn_payload_check(vport, Did))) {
James Smart858c9f62007-06-17 19:56:39 -0500479 lpfc_debugfs_disc_trc(vport,
480 LPFC_DISC_TRC_CT,
481 "Query GID_FTrsp: "
482 "did:x%x flg:x%x cnt:%d",
483 Did, vport->fc_flag,
484 vport->fc_rscn_id_cnt);
485
James Smart0ff10d42008-01-11 01:52:36 -0500486 /* This NPortID was previously
487 * a FCP target, * Don't even
488 * bother to send GFF_ID.
489 */
490 ndlp = lpfc_findnode_did(vport,
491 Did);
492 if (ndlp && (ndlp->nlp_type &
493 NLP_FCP_TARGET))
494 lpfc_setup_disc_node
495 (vport, Did);
496 else if (lpfc_ns_cmd(vport,
James Smart92d7f7b2007-06-17 19:56:38 -0500497 SLI_CTNS_GFF_ID,
498 0, Did) == 0)
499 vport->num_disc_nodes++;
500 }
501 else {
James Smart858c9f62007-06-17 19:56:39 -0500502 lpfc_debugfs_disc_trc(vport,
503 LPFC_DISC_TRC_CT,
504 "Skip2 GID_FTrsp: "
505 "did:x%x flg:x%x cnt:%d",
506 Did, vport->fc_flag,
507 vport->fc_rscn_id_cnt);
508
James Smarte8b62012007-08-02 11:10:09 -0400509 lpfc_printf_vlog(vport,
510 KERN_INFO,
James Smart92d7f7b2007-06-17 19:56:38 -0500511 LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400512 "0245 Skip x%x "
James Smart92d7f7b2007-06-17 19:56:38 -0500513 "NameServer Rsp Data: "
514 "x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400515 Did, vport->fc_flag,
James Smart92d7f7b2007-06-17 19:56:38 -0500516 vport->fc_rscn_id_cnt);
517 }
518 }
dea31012005-04-17 16:05:31 -0500519 }
dea31012005-04-17 16:05:31 -0500520 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
521 goto nsout1;
522 Cnt -= sizeof (uint32_t);
523 }
524 ctptr = NULL;
525
526 }
527
528nsout1:
529 list_del(&head);
dea31012005-04-17 16:05:31 -0500530 return 0;
531}
532
dea31012005-04-17 16:05:31 -0500533static void
James Smart2e0fef82007-06-17 19:56:36 -0500534lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
535 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500536{
James Smart2e0fef82007-06-17 19:56:36 -0500537 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500539 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500540 struct lpfc_dmabuf *bmp;
dea31012005-04-17 16:05:31 -0500541 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500542 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400543 struct lpfc_nodelist *ndlp;
James Smart0ff10d42008-01-11 01:52:36 -0500544 int rc, retry;
dea31012005-04-17 16:05:31 -0500545
James Smart51ef4c22007-08-02 11:10:31 -0400546 /* First save ndlp, before we overwrite it */
547 ndlp = cmdiocb->context_un.ndlp;
548
dea31012005-04-17 16:05:31 -0500549 /* we pass cmdiocb to state machine which needs rspiocb as well */
550 cmdiocb->context_un.rsp_iocb = rspiocb;
551
dea31012005-04-17 16:05:31 -0500552 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
553 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
James Smart858c9f62007-06-17 19:56:39 -0500554 irsp = &rspiocb->iocb;
555
556 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
557 "GID_FT cmpl: status:x%x/x%x rtry:%d",
558 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500559
James Smart92d7f7b2007-06-17 19:56:38 -0500560 /* Don't bother processing response if vport is being torn down. */
561 if (vport->load_flag & FC_UNLOADING)
562 goto out;
563
James Smart858c9f62007-06-17 19:56:39 -0500564 if (lpfc_els_chk_latt(vport) || lpfc_error_lost_link(irsp)) {
James Smarte8b62012007-08-02 11:10:09 -0400565 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
566 "0216 Link event during NS query\n");
James Smart858c9f62007-06-17 19:56:39 -0500567 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
568 goto out;
569 }
570
571 if (irsp->ulpStatus) {
dea31012005-04-17 16:05:31 -0500572 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500573 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
James Smart0ff10d42008-01-11 01:52:36 -0500574 retry = 1;
575 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
576 switch (irsp->un.ulpWord[4]) {
577 case IOERR_NO_RESOURCES:
578 /* We don't increment the retry
579 * count for this case.
580 */
581 break;
582 case IOERR_LINK_DOWN:
583 case IOERR_SLI_ABORTED:
584 case IOERR_SLI_DOWN:
585 retry = 0;
586 break;
587 default:
588 vport->fc_ns_retry++;
589 }
590 }
591 else
James Smart858c9f62007-06-17 19:56:39 -0500592 vport->fc_ns_retry++;
James Smart0ff10d42008-01-11 01:52:36 -0500593
594 if (retry) {
595 /* CT command is being retried */
596 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
James Smart92d7f7b2007-06-17 19:56:38 -0500597 vport->fc_ns_retry, 0);
James Smart0ff10d42008-01-11 01:52:36 -0500598 if (rc == 0) {
599 /* success */
600 goto out;
601 }
602 }
James Smart92d7f7b2007-06-17 19:56:38 -0500603 }
James Smart92d7f7b2007-06-17 19:56:38 -0500604 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400605 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
606 "0257 GID_FT Query error: 0x%x 0x%x\n",
607 irsp->ulpStatus, vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500608 } else {
609 /* Good status, continue checking */
610 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
611 if (CTrsp->CommandResponse.bits.CmdRsp ==
612 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
James Smarte8b62012007-08-02 11:10:09 -0400613 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
614 "0208 NameServer Rsp Data: x%x\n",
615 vport->fc_flag);
James Smart2e0fef82007-06-17 19:56:36 -0500616 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500617 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
618 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
619 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
620 /* NameServer Rsp Error */
James Smarta58cbd52007-08-02 11:09:43 -0400621 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
622 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
James Smarte8b62012007-08-02 11:10:09 -0400623 lpfc_printf_vlog(vport, KERN_INFO,
624 LOG_DISCOVERY,
625 "0269 No NameServer Entries "
James Smarta58cbd52007-08-02 11:09:43 -0400626 "Data: x%x x%x x%x x%x\n",
James Smarta58cbd52007-08-02 11:09:43 -0400627 CTrsp->CommandResponse.bits.CmdRsp,
628 (uint32_t) CTrsp->ReasonCode,
629 (uint32_t) CTrsp->Explanation,
630 vport->fc_flag);
631
632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
633 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
634 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
635 (uint32_t) CTrsp->ReasonCode,
636 (uint32_t) CTrsp->Explanation);
James Smarte8b62012007-08-02 11:10:09 -0400637 } else {
638 lpfc_printf_vlog(vport, KERN_INFO,
639 LOG_DISCOVERY,
640 "0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500641 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500642 CTrsp->CommandResponse.bits.CmdRsp,
643 (uint32_t) CTrsp->ReasonCode,
644 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500645 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500646
James Smarta58cbd52007-08-02 11:09:43 -0400647 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
James Smart858c9f62007-06-17 19:56:39 -0500648 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
649 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
650 (uint32_t) CTrsp->ReasonCode,
651 (uint32_t) CTrsp->Explanation);
James Smarta58cbd52007-08-02 11:09:43 -0400652 }
653
James Smart858c9f62007-06-17 19:56:39 -0500654
dea31012005-04-17 16:05:31 -0500655 } else {
656 /* NameServer Rsp Error */
James Smarte8b62012007-08-02 11:10:09 -0400657 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
658 "0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500659 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500660 CTrsp->CommandResponse.bits.CmdRsp,
661 (uint32_t) CTrsp->ReasonCode,
662 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500663 vport->fc_flag);
James Smart858c9f62007-06-17 19:56:39 -0500664
665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
666 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
667 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
668 (uint32_t) CTrsp->ReasonCode,
669 (uint32_t) CTrsp->Explanation);
dea31012005-04-17 16:05:31 -0500670 }
671 }
672 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500673 if (vport->num_disc_nodes == 0) {
674 /*
675 * The driver has cycled through all Nports in the RSCN payload.
676 * Complete the handling by cleaning up and marking the
677 * current driver state.
678 */
679 if (vport->port_state >= LPFC_DISC_AUTH) {
680 if (vport->fc_flag & FC_RSCN_MODE) {
681 lpfc_els_flush_rscn(vport);
682 spin_lock_irq(shost->host_lock);
683 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
684 spin_unlock_irq(shost->host_lock);
685 }
686 else
687 lpfc_els_flush_rscn(vport);
688 }
689
690 lpfc_disc_start(vport);
691 }
dea31012005-04-17 16:05:31 -0500692out:
James Smart51ef4c22007-08-02 11:10:31 -0400693 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500694 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500695 return;
696}
697
James Smart311464e2007-08-02 11:10:37 -0400698static void
James Smart92d7f7b2007-06-17 19:56:38 -0500699lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
700 struct lpfc_iocbq *rspiocb)
701{
702 struct lpfc_vport *vport = cmdiocb->vport;
703 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
704 IOCB_t *irsp = &rspiocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500705 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
706 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
707 struct lpfc_sli_ct_request *CTrsp;
James Smart0ff10d42008-01-11 01:52:36 -0500708 int did, rc, retry;
James Smart92d7f7b2007-06-17 19:56:38 -0500709 uint8_t fbits;
710 struct lpfc_nodelist *ndlp;
711
712 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
713 did = be32_to_cpu(did);
714
James Smart858c9f62007-06-17 19:56:39 -0500715 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
716 "GFF_ID cmpl: status:x%x/x%x did:x%x",
717 irsp->ulpStatus, irsp->un.ulpWord[4], did);
718
James Smart92d7f7b2007-06-17 19:56:38 -0500719 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
720 /* Good status, continue checking */
721 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
722 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
723
724 if (CTrsp->CommandResponse.bits.CmdRsp ==
725 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
726 if ((fbits & FC4_FEATURE_INIT) &&
727 !(fbits & FC4_FEATURE_TARGET)) {
James Smarte8b62012007-08-02 11:10:09 -0400728 lpfc_printf_vlog(vport, KERN_INFO,
729 LOG_DISCOVERY,
730 "0270 Skip x%x GFF "
731 "NameServer Rsp Data: (init) "
732 "x%x x%x\n", did, fbits,
733 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500734 goto out;
735 }
736 }
737 }
James Smart858c9f62007-06-17 19:56:39 -0500738 else {
James Smart0ff10d42008-01-11 01:52:36 -0500739 /* Check for retry */
740 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
741 retry = 1;
742 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
743 switch (irsp->un.ulpWord[4]) {
744 case IOERR_NO_RESOURCES:
745 /* We don't increment the retry
746 * count for this case.
747 */
748 break;
749 case IOERR_LINK_DOWN:
750 case IOERR_SLI_ABORTED:
751 case IOERR_SLI_DOWN:
752 retry = 0;
753 break;
754 default:
755 cmdiocb->retry++;
756 }
757 }
758 else
759 cmdiocb->retry++;
760
761 if (retry) {
762 /* CT command is being retried */
763 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
764 cmdiocb->retry, did);
765 if (rc == 0) {
766 /* success */
767 lpfc_ct_free_iocb(phba, cmdiocb);
768 return;
769 }
770 }
771 }
James Smarte8b62012007-08-02 11:10:09 -0400772 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
773 "0267 NameServer GFF Rsp "
774 "x%x Error (%d %d) Data: x%x x%x\n",
775 did, irsp->ulpStatus, irsp->un.ulpWord[4],
776 vport->fc_flag, vport->fc_rscn_id_cnt)
James Smart858c9f62007-06-17 19:56:39 -0500777 }
778
James Smart92d7f7b2007-06-17 19:56:38 -0500779 /* This is a target port, unregistered port, or the GFF_ID failed */
780 ndlp = lpfc_setup_disc_node(vport, did);
781 if (ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400782 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
783 "0242 Process x%x GFF "
784 "NameServer Rsp Data: x%x x%x x%x\n",
785 did, ndlp->nlp_flag, vport->fc_flag,
786 vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500787 } else {
James Smarte8b62012007-08-02 11:10:09 -0400788 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
789 "0243 Skip x%x GFF "
790 "NameServer Rsp Data: x%x x%x\n", did,
791 vport->fc_flag, vport->fc_rscn_id_cnt);
James Smart92d7f7b2007-06-17 19:56:38 -0500792 }
793out:
794 /* Link up / RSCN discovery */
795 if (vport->num_disc_nodes)
796 vport->num_disc_nodes--;
797 if (vport->num_disc_nodes == 0) {
798 /*
799 * The driver has cycled through all Nports in the RSCN payload.
800 * Complete the handling by cleaning up and marking the
801 * current driver state.
802 */
803 if (vport->port_state >= LPFC_DISC_AUTH) {
804 if (vport->fc_flag & FC_RSCN_MODE) {
805 lpfc_els_flush_rscn(vport);
806 spin_lock_irq(shost->host_lock);
807 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
808 spin_unlock_irq(shost->host_lock);
809 }
810 else
811 lpfc_els_flush_rscn(vport);
812 }
813 lpfc_disc_start(vport);
814 }
James Smart858c9f62007-06-17 19:56:39 -0500815 lpfc_ct_free_iocb(phba, cmdiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500816 return;
817}
818
819
dea31012005-04-17 16:05:31 -0500820static void
James Smart7ee5d432007-10-27 13:37:17 -0400821lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
822 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500823{
James Smart92d7f7b2007-06-17 19:56:38 -0500824 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500825 struct lpfc_dmabuf *inp;
826 struct lpfc_dmabuf *outp;
827 IOCB_t *irsp;
828 struct lpfc_sli_ct_request *CTrsp;
James Smart51ef4c22007-08-02 11:10:31 -0400829 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500830 int cmdcode, rc;
831 uint8_t retry;
James Smart858c9f62007-06-17 19:56:39 -0500832 uint32_t latt;
dea31012005-04-17 16:05:31 -0500833
James Smart51ef4c22007-08-02 11:10:31 -0400834 /* First save ndlp, before we overwrite it */
835 ndlp = cmdiocb->context_un.ndlp;
836
dea31012005-04-17 16:05:31 -0500837 /* we pass cmdiocb to state machine which needs rspiocb as well */
838 cmdiocb->context_un.rsp_iocb = rspiocb;
839
840 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
841 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -0500842 irsp = &rspiocb->iocb;
843
James Smart92d7f7b2007-06-17 19:56:38 -0500844 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
845 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500846 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
847
James Smart858c9f62007-06-17 19:56:39 -0500848 latt = lpfc_els_chk_latt(vport);
849
850 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
James Smarte8b62012007-08-02 11:10:09 -0400851 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smart7ee5d432007-10-27 13:37:17 -0400852 "0209 CT Request completes, latt %d, "
James Smarte8b62012007-08-02 11:10:09 -0400853 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
854 latt, irsp->ulpStatus,
855 CTrsp->CommandResponse.bits.CmdRsp,
856 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500857
James Smart858c9f62007-06-17 19:56:39 -0500858 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
859 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
860 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
861
James Smart92d7f7b2007-06-17 19:56:38 -0500862 if (irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -0400863 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
864 "0268 NS cmd %x Error (%d %d)\n",
865 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -0500866
James Smart92d7f7b2007-06-17 19:56:38 -0500867 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
868 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
869 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
870 goto out;
871
872 retry = cmdiocb->retry;
873 if (retry >= LPFC_MAX_NS_RETRY)
874 goto out;
875
876 retry++;
James Smarte8b62012007-08-02 11:10:09 -0400877 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
878 "0216 Retrying NS cmd %x\n", cmdcode);
James Smart92d7f7b2007-06-17 19:56:38 -0500879 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
880 if (rc == 0)
881 goto out;
882 }
883
884out:
James Smart51ef4c22007-08-02 11:10:31 -0400885 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
James Smart858c9f62007-06-17 19:56:39 -0500886 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500887 return;
888}
889
890static void
James Smart7ee5d432007-10-27 13:37:17 -0400891lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
892 struct lpfc_iocbq *rspiocb)
893{
894 IOCB_t *irsp = &rspiocb->iocb;
895 struct lpfc_vport *vport = cmdiocb->vport;
896
James Smart98c9ea52007-10-27 13:37:33 -0400897 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
898 struct lpfc_dmabuf *outp;
899 struct lpfc_sli_ct_request *CTrsp;
900
901 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
902 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
903 if (CTrsp->CommandResponse.bits.CmdRsp ==
904 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
905 vport->ct_flags |= FC_CT_RFT_ID;
906 }
James Smart7ee5d432007-10-27 13:37:17 -0400907 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
908 return;
909}
910
911static void
James Smart2e0fef82007-06-17 19:56:36 -0500912lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
913 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500914{
James Smart7ee5d432007-10-27 13:37:17 -0400915 IOCB_t *irsp = &rspiocb->iocb;
916 struct lpfc_vport *vport = cmdiocb->vport;
917
James Smart98c9ea52007-10-27 13:37:33 -0400918 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
919 struct lpfc_dmabuf *outp;
920 struct lpfc_sli_ct_request *CTrsp;
921
922 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
923 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
924 if (CTrsp->CommandResponse.bits.CmdRsp ==
925 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
926 vport->ct_flags |= FC_CT_RNN_ID;
927 }
James Smart7ee5d432007-10-27 13:37:17 -0400928 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500929 return;
930}
931
932static void
James Smart92d7f7b2007-06-17 19:56:38 -0500933lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
934 struct lpfc_iocbq *rspiocb)
935{
James Smart7ee5d432007-10-27 13:37:17 -0400936 IOCB_t *irsp = &rspiocb->iocb;
937 struct lpfc_vport *vport = cmdiocb->vport;
938
James Smart98c9ea52007-10-27 13:37:33 -0400939 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
940 struct lpfc_dmabuf *outp;
941 struct lpfc_sli_ct_request *CTrsp;
942
943 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
944 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
945 if (CTrsp->CommandResponse.bits.CmdRsp ==
946 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
947 vport->ct_flags |= FC_CT_RSPN_ID;
948 }
James Smart7ee5d432007-10-27 13:37:17 -0400949 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500950 return;
951}
952
953static void
James Smart2e0fef82007-06-17 19:56:36 -0500954lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
955 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500956{
James Smart7ee5d432007-10-27 13:37:17 -0400957 IOCB_t *irsp = &rspiocb->iocb;
958 struct lpfc_vport *vport = cmdiocb->vport;
959
James Smart98c9ea52007-10-27 13:37:33 -0400960 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
961 struct lpfc_dmabuf *outp;
962 struct lpfc_sli_ct_request *CTrsp;
963
964 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
965 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
966 if (CTrsp->CommandResponse.bits.CmdRsp ==
967 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
968 vport->ct_flags |= FC_CT_RSNN_NN;
969 }
James Smart7ee5d432007-10-27 13:37:17 -0400970 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
971 return;
972}
973
974static void
975lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
976 struct lpfc_iocbq *rspiocb)
977{
978 struct lpfc_vport *vport = cmdiocb->vport;
979
980 /* even if it fails we will act as though it succeeded. */
981 vport->ct_flags = 0;
982 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea31012005-04-17 16:05:31 -0500983 return;
984}
985
James Smart2fb9bd82006-12-02 13:33:57 -0500986static void
James Smart92d7f7b2007-06-17 19:56:38 -0500987lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
988 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -0500989{
James Smart92d7f7b2007-06-17 19:56:38 -0500990 IOCB_t *irsp = &rspiocb->iocb;
991 struct lpfc_vport *vport = cmdiocb->vport;
992
James Smart98c9ea52007-10-27 13:37:33 -0400993 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
994 struct lpfc_dmabuf *outp;
995 struct lpfc_sli_ct_request *CTrsp;
996
997 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
998 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
999 if (CTrsp->CommandResponse.bits.CmdRsp ==
1000 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1001 vport->ct_flags |= FC_CT_RFF_ID;
1002 }
James Smart7ee5d432007-10-27 13:37:17 -04001003 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
James Smart2fb9bd82006-12-02 13:33:57 -05001004 return;
1005}
1006
James Smart311464e2007-08-02 11:10:37 -04001007static int
James Smart92d7f7b2007-06-17 19:56:38 -05001008lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1009 size_t size)
1010{
1011 int n;
1012 uint8_t *wwn = vport->phba->wwpn;
1013
1014 n = snprintf(symbol, size,
1015 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1016 wwn[0], wwn[1], wwn[2], wwn[3],
1017 wwn[4], wwn[5], wwn[6], wwn[7]);
1018
1019 if (vport->port_type == LPFC_PHYSICAL_PORT)
1020 return n;
1021
1022 if (n < size)
1023 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1024
1025 if (n < size && vport->vname)
1026 n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
1027 return n;
1028}
1029
1030int
1031lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1032 size_t size)
dea31012005-04-17 16:05:31 -05001033{
1034 char fwrev[16];
James Smart92d7f7b2007-06-17 19:56:38 -05001035 int n;
dea31012005-04-17 16:05:31 -05001036
James Smart92d7f7b2007-06-17 19:56:38 -05001037 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -05001038
James Smart92d7f7b2007-06-17 19:56:38 -05001039 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1040 vport->phba->ModelName, fwrev, lpfc_release_version);
1041 return n;
dea31012005-04-17 16:05:31 -05001042}
1043
1044/*
1045 * lpfc_ns_cmd
1046 * Description:
1047 * Issue Cmd to NameServer
1048 * SLI_CTNS_GID_FT
1049 * LI_CTNS_RFT_ID
1050 */
1051int
James Smart92d7f7b2007-06-17 19:56:38 -05001052lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1053 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -05001054{
James Smart92d7f7b2007-06-17 19:56:38 -05001055 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001056 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001057 struct lpfc_dmabuf *mp, *bmp;
1058 struct lpfc_sli_ct_request *CtReq;
1059 struct ulp_bde64 *bpl;
1060 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1061 struct lpfc_iocbq *) = NULL;
1062 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -05001063 size_t size;
James Smart858c9f62007-06-17 19:56:39 -05001064 int rc = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001065
1066 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart858c9f62007-06-17 19:56:39 -05001067 if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1068 rc=1;
1069 goto ns_cmd_exit;
1070 }
dea31012005-04-17 16:05:31 -05001071
1072 /* fill in BDEs for command */
1073 /* Allocate buffer for command payload */
1074 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001075 if (!mp) {
1076 rc=2;
dea31012005-04-17 16:05:31 -05001077 goto ns_cmd_exit;
James Smart858c9f62007-06-17 19:56:39 -05001078 }
dea31012005-04-17 16:05:31 -05001079
1080 INIT_LIST_HEAD(&mp->list);
1081 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001082 if (!mp->virt) {
1083 rc=3;
dea31012005-04-17 16:05:31 -05001084 goto ns_cmd_free_mp;
James Smart858c9f62007-06-17 19:56:39 -05001085 }
dea31012005-04-17 16:05:31 -05001086
1087 /* Allocate buffer for Buffer ptr list */
1088 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
James Smart858c9f62007-06-17 19:56:39 -05001089 if (!bmp) {
1090 rc=4;
dea31012005-04-17 16:05:31 -05001091 goto ns_cmd_free_mpvirt;
James Smart858c9f62007-06-17 19:56:39 -05001092 }
dea31012005-04-17 16:05:31 -05001093
1094 INIT_LIST_HEAD(&bmp->list);
1095 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
James Smart858c9f62007-06-17 19:56:39 -05001096 if (!bmp->virt) {
1097 rc=5;
dea31012005-04-17 16:05:31 -05001098 goto ns_cmd_free_bmp;
James Smart858c9f62007-06-17 19:56:39 -05001099 }
dea31012005-04-17 16:05:31 -05001100
1101 /* NameServer Req */
James Smarte8b62012007-08-02 11:10:09 -04001102 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1103 "0236 NameServer Req Data: x%x x%x x%x\n",
1104 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001105
1106 bpl = (struct ulp_bde64 *) bmp->virt;
1107 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -05001108 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1109 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001110 bpl->tus.f.bdeFlags = 0;
1111 if (cmdcode == SLI_CTNS_GID_FT)
1112 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001113 else if (cmdcode == SLI_CTNS_GFF_ID)
1114 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001115 else if (cmdcode == SLI_CTNS_RFT_ID)
1116 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1117 else if (cmdcode == SLI_CTNS_RNN_ID)
1118 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -05001119 else if (cmdcode == SLI_CTNS_RSPN_ID)
1120 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001121 else if (cmdcode == SLI_CTNS_RSNN_NN)
1122 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart7ee5d432007-10-27 13:37:17 -04001123 else if (cmdcode == SLI_CTNS_DA_ID)
1124 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -05001125 else if (cmdcode == SLI_CTNS_RFF_ID)
1126 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -05001127 else
1128 bpl->tus.f.bdeSize = 0;
1129 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1130
1131 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1132 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1133 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1134 CtReq->RevisionId.bits.InId = 0;
1135 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1136 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1137 CtReq->CommandResponse.bits.Size = 0;
1138 switch (cmdcode) {
1139 case SLI_CTNS_GID_FT:
1140 CtReq->CommandResponse.bits.CmdRsp =
1141 be16_to_cpu(SLI_CTNS_GID_FT);
1142 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -05001143 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -05001144 vport->port_state = LPFC_NS_QRY;
1145 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001146 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1147 rsp_size = FC_MAX_NS_RSP;
1148 break;
1149
James Smart92d7f7b2007-06-17 19:56:38 -05001150 case SLI_CTNS_GFF_ID:
1151 CtReq->CommandResponse.bits.CmdRsp =
1152 be16_to_cpu(SLI_CTNS_GFF_ID);
James Smart09372822008-01-11 01:52:54 -05001153 CtReq->un.gff.PortId = cpu_to_be32(context);
James Smart92d7f7b2007-06-17 19:56:38 -05001154 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1155 break;
1156
dea31012005-04-17 16:05:31 -05001157 case SLI_CTNS_RFT_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001158 vport->ct_flags &= ~FC_CT_RFT_ID;
dea31012005-04-17 16:05:31 -05001159 CtReq->CommandResponse.bits.CmdRsp =
1160 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart09372822008-01-11 01:52:54 -05001161 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001162 CtReq->un.rft.fcpReg = 1;
1163 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1164 break;
1165
1166 case SLI_CTNS_RNN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001167 vport->ct_flags &= ~FC_CT_RNN_ID;
dea31012005-04-17 16:05:31 -05001168 CtReq->CommandResponse.bits.CmdRsp =
1169 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart09372822008-01-11 01:52:54 -05001170 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart2e0fef82007-06-17 19:56:36 -05001171 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001172 sizeof (struct lpfc_name));
1173 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1174 break;
1175
James Smart92d7f7b2007-06-17 19:56:38 -05001176 case SLI_CTNS_RSPN_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001177 vport->ct_flags &= ~FC_CT_RSPN_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001178 CtReq->CommandResponse.bits.CmdRsp =
1179 be16_to_cpu(SLI_CTNS_RSPN_ID);
James Smart09372822008-01-11 01:52:54 -05001180 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001181 size = sizeof(CtReq->un.rspn.symbname);
1182 CtReq->un.rspn.len =
1183 lpfc_vport_symbolic_port_name(vport,
1184 CtReq->un.rspn.symbname, size);
1185 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1186 break;
dea31012005-04-17 16:05:31 -05001187 case SLI_CTNS_RSNN_NN:
James Smart7ee5d432007-10-27 13:37:17 -04001188 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea31012005-04-17 16:05:31 -05001189 CtReq->CommandResponse.bits.CmdRsp =
1190 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -05001191 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05001192 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -05001193 size = sizeof(CtReq->un.rsnn.symbname);
1194 CtReq->un.rsnn.len =
1195 lpfc_vport_symbolic_node_name(vport,
1196 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -05001197 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1198 break;
James Smart7ee5d432007-10-27 13:37:17 -04001199 case SLI_CTNS_DA_ID:
1200 /* Implement DA_ID Nameserver request */
1201 CtReq->CommandResponse.bits.CmdRsp =
1202 be16_to_cpu(SLI_CTNS_DA_ID);
James Smart09372822008-01-11 01:52:54 -05001203 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
James Smart7ee5d432007-10-27 13:37:17 -04001204 cmpl = lpfc_cmpl_ct_cmd_da_id;
1205 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001206 case SLI_CTNS_RFF_ID:
James Smart7ee5d432007-10-27 13:37:17 -04001207 vport->ct_flags &= ~FC_CT_RFF_ID;
James Smart92d7f7b2007-06-17 19:56:38 -05001208 CtReq->CommandResponse.bits.CmdRsp =
1209 be16_to_cpu(SLI_CTNS_RFF_ID);
James Smart09372822008-01-11 01:52:54 -05001210 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);;
James Smart92d7f7b2007-06-17 19:56:38 -05001211 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1212 CtReq->un.rff.type_code = FC_FCP_DATA;
1213 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1214 break;
dea31012005-04-17 16:05:31 -05001215 }
James Smart51ef4c22007-08-02 11:10:31 -04001216 lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001217
James Smart858c9f62007-06-17 19:56:39 -05001218 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea31012005-04-17 16:05:31 -05001219 /* On success, The cmpl function will free the buffers */
James Smart858c9f62007-06-17 19:56:39 -05001220 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1221 "Issue CT cmd: cmd:x%x did:x%x",
1222 cmdcode, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05001223 return 0;
James Smart858c9f62007-06-17 19:56:39 -05001224 }
dea31012005-04-17 16:05:31 -05001225
James Smart858c9f62007-06-17 19:56:39 -05001226 rc=6;
James Smart51ef4c22007-08-02 11:10:31 -04001227 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001228 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1229ns_cmd_free_bmp:
1230 kfree(bmp);
1231ns_cmd_free_mpvirt:
1232 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1233ns_cmd_free_mp:
1234 kfree(mp);
1235ns_cmd_exit:
James Smarte8b62012007-08-02 11:10:09 -04001236 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1237 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1238 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05001239 return 1;
1240}
1241
1242static void
James Smart2e0fef82007-06-17 19:56:36 -05001243lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1244 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -05001245{
dea31012005-04-17 16:05:31 -05001246 struct lpfc_dmabuf *inp = cmdiocb->context1;
1247 struct lpfc_dmabuf *outp = cmdiocb->context2;
1248 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1249 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1250 struct lpfc_nodelist *ndlp;
1251 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1252 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001253 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05001254 IOCB_t *irsp = &rspiocb->iocb;
1255 uint32_t latt;
1256
1257 latt = lpfc_els_chk_latt(vport);
1258
1259 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1260 "FDMI cmpl: status:x%x/x%x latt:%d",
1261 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1262
1263 if (latt || irsp->ulpStatus) {
James Smarte8b62012007-08-02 11:10:09 -04001264 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1265 "0229 FDMI cmd %04x failed, latt = %d "
1266 "ulpStatus: x%x, rid x%x\n",
1267 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1268 irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05001269 lpfc_ct_free_iocb(phba, cmdiocb);
1270 return;
1271 }
dea31012005-04-17 16:05:31 -05001272
James Smart2e0fef82007-06-17 19:56:36 -05001273 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001274 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1275 /* FDMI rsp failed */
James Smarte8b62012007-08-02 11:10:09 -04001276 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1277 "0220 FDMI rsp failed Data: x%x\n",
1278 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001279 }
1280
1281 switch (be16_to_cpu(fdmi_cmd)) {
1282 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001283 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001284 break;
1285
1286 case SLI_MGMT_RPA:
1287 break;
1288
1289 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001290 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001291 break;
1292
1293 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001294 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001295 break;
1296 }
James Smart858c9f62007-06-17 19:56:39 -05001297 lpfc_ct_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001298 return;
1299}
James Smart2e0fef82007-06-17 19:56:36 -05001300
dea31012005-04-17 16:05:31 -05001301int
James Smart2e0fef82007-06-17 19:56:36 -05001302lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001303{
James Smart2e0fef82007-06-17 19:56:36 -05001304 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001305 struct lpfc_dmabuf *mp, *bmp;
1306 struct lpfc_sli_ct_request *CtReq;
1307 struct ulp_bde64 *bpl;
1308 uint32_t size;
1309 REG_HBA *rh;
1310 PORT_ENTRY *pe;
1311 REG_PORT_ATTRIBUTE *pab;
1312 ATTRIBUTE_BLOCK *ab;
1313 ATTRIBUTE_ENTRY *ae;
1314 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1315 struct lpfc_iocbq *);
1316
1317
1318 /* fill in BDEs for command */
1319 /* Allocate buffer for command payload */
1320 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1321 if (!mp)
1322 goto fdmi_cmd_exit;
1323
1324 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1325 if (!mp->virt)
1326 goto fdmi_cmd_free_mp;
1327
1328 /* Allocate buffer for Buffer ptr list */
1329 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1330 if (!bmp)
1331 goto fdmi_cmd_free_mpvirt;
1332
1333 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1334 if (!bmp->virt)
1335 goto fdmi_cmd_free_bmp;
1336
1337 INIT_LIST_HEAD(&mp->list);
1338 INIT_LIST_HEAD(&bmp->list);
1339
1340 /* FDMI request */
James Smarte8b62012007-08-02 11:10:09 -04001341 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1342 "0218 FDMI Request Data: x%x x%x x%x\n",
1343 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001344 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1345
1346 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1347 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1348 CtReq->RevisionId.bits.InId = 0;
1349
1350 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1351 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1352 size = 0;
1353
1354 switch (cmdcode) {
1355 case SLI_MGMT_RHBA:
1356 {
1357 lpfc_vpd_t *vp = &phba->vpd;
1358 uint32_t i, j, incr;
1359 int len;
1360
1361 CtReq->CommandResponse.bits.CmdRsp =
1362 be16_to_cpu(SLI_MGMT_RHBA);
1363 CtReq->CommandResponse.bits.Size = 0;
1364 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001365 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001366 sizeof (struct lpfc_name));
1367 /* One entry (port) per adapter */
1368 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001369 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001370 sizeof (struct lpfc_name));
1371
1372 /* point to the HBA attribute block */
1373 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1374 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1375 ab->EntryCnt = 0;
1376
1377 /* Point to the beginning of the first HBA attribute
1378 entry */
1379 /* #1 HBA attribute entry */
1380 size += FOURBYTES;
1381 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1382 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1383 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1384 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001385 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001386 sizeof (struct lpfc_name));
1387 ab->EntryCnt++;
1388 size += FOURBYTES + sizeof (struct lpfc_name);
1389
1390 /* #2 HBA attribute entry */
1391 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1392 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1393 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1394 len = strlen(ae->un.Manufacturer);
1395 len += (len & 3) ? (4 - (len & 3)) : 4;
1396 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1397 ab->EntryCnt++;
1398 size += FOURBYTES + len;
1399
1400 /* #3 HBA attribute entry */
1401 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1402 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1403 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1404 len = strlen(ae->un.SerialNumber);
1405 len += (len & 3) ? (4 - (len & 3)) : 4;
1406 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1407 ab->EntryCnt++;
1408 size += FOURBYTES + len;
1409
1410 /* #4 HBA attribute entry */
1411 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1412 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1413 strcpy(ae->un.Model, phba->ModelName);
1414 len = strlen(ae->un.Model);
1415 len += (len & 3) ? (4 - (len & 3)) : 4;
1416 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1417 ab->EntryCnt++;
1418 size += FOURBYTES + len;
1419
1420 /* #5 HBA attribute entry */
1421 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1422 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1423 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1424 len = strlen(ae->un.ModelDescription);
1425 len += (len & 3) ? (4 - (len & 3)) : 4;
1426 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1427 ab->EntryCnt++;
1428 size += FOURBYTES + len;
1429
1430 /* #6 HBA attribute entry */
1431 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1432 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1433 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1434 /* Convert JEDEC ID to ascii for hardware version */
1435 incr = vp->rev.biuRev;
1436 for (i = 0; i < 8; i++) {
1437 j = (incr & 0xf);
1438 if (j <= 9)
1439 ae->un.HardwareVersion[7 - i] =
1440 (char)((uint8_t) 0x30 +
1441 (uint8_t) j);
1442 else
1443 ae->un.HardwareVersion[7 - i] =
1444 (char)((uint8_t) 0x61 +
1445 (uint8_t) (j - 10));
1446 incr = (incr >> 4);
1447 }
1448 ab->EntryCnt++;
1449 size += FOURBYTES + 8;
1450
1451 /* #7 HBA attribute entry */
1452 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1453 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1454 strcpy(ae->un.DriverVersion, lpfc_release_version);
1455 len = strlen(ae->un.DriverVersion);
1456 len += (len & 3) ? (4 - (len & 3)) : 4;
1457 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1458 ab->EntryCnt++;
1459 size += FOURBYTES + len;
1460
1461 /* #8 HBA attribute entry */
1462 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1463 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1464 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1465 len = strlen(ae->un.OptionROMVersion);
1466 len += (len & 3) ? (4 - (len & 3)) : 4;
1467 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1468 ab->EntryCnt++;
1469 size += FOURBYTES + len;
1470
1471 /* #9 HBA attribute entry */
1472 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1473 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1474 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1475 1);
1476 len = strlen(ae->un.FirmwareVersion);
1477 len += (len & 3) ? (4 - (len & 3)) : 4;
1478 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1479 ab->EntryCnt++;
1480 size += FOURBYTES + len;
1481
1482 /* #10 HBA attribute entry */
1483 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1484 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1485 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001486 init_utsname()->sysname,
1487 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001488 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001489 len = strlen(ae->un.OsNameVersion);
1490 len += (len & 3) ? (4 - (len & 3)) : 4;
1491 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1492 ab->EntryCnt++;
1493 size += FOURBYTES + len;
1494
1495 /* #11 HBA attribute entry */
1496 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1497 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1498 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1499 ae->un.MaxCTPayloadLen = (65 * 4096);
1500 ab->EntryCnt++;
1501 size += FOURBYTES + 4;
1502
1503 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1504 /* Total size */
1505 size = GID_REQUEST_SZ - 4 + size;
1506 }
1507 break;
1508
1509 case SLI_MGMT_RPA:
1510 {
1511 lpfc_vpd_t *vp;
1512 struct serv_parm *hsp;
1513 int len;
1514
1515 vp = &phba->vpd;
1516
1517 CtReq->CommandResponse.bits.CmdRsp =
1518 be16_to_cpu(SLI_MGMT_RPA);
1519 CtReq->CommandResponse.bits.Size = 0;
1520 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1521 size = sizeof (struct lpfc_name) + FOURBYTES;
1522 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001523 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001524 sizeof (struct lpfc_name));
1525 pab->ab.EntryCnt = 0;
1526
1527 /* #1 Port attribute entry */
1528 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1529 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1530 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1531 ae->un.SupportFC4Types[2] = 1;
1532 ae->un.SupportFC4Types[7] = 1;
1533 pab->ab.EntryCnt++;
1534 size += FOURBYTES + 32;
1535
1536 /* #2 Port attribute entry */
1537 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1538 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1539 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001540
1541 ae->un.SupportSpeed = 0;
1542 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001543 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001544 if (phba->lmt & LMT_8Gb)
1545 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1546 if (phba->lmt & LMT_4Gb)
1547 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1548 if (phba->lmt & LMT_2Gb)
1549 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1550 if (phba->lmt & LMT_1Gb)
1551 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1552
dea31012005-04-17 16:05:31 -05001553 pab->ab.EntryCnt++;
1554 size += FOURBYTES + 4;
1555
1556 /* #3 Port attribute entry */
1557 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1558 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1559 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1560 switch(phba->fc_linkspeed) {
1561 case LA_1GHZ_LINK:
1562 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1563 break;
1564 case LA_2GHZ_LINK:
1565 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1566 break;
1567 case LA_4GHZ_LINK:
1568 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1569 break;
James Smartb87eab32007-04-25 09:53:28 -04001570 case LA_8GHZ_LINK:
1571 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1572 break;
dea31012005-04-17 16:05:31 -05001573 default:
1574 ae->un.PortSpeed =
1575 HBA_PORTSPEED_UNKNOWN;
1576 break;
1577 }
1578 pab->ab.EntryCnt++;
1579 size += FOURBYTES + 4;
1580
1581 /* #4 Port attribute entry */
1582 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1583 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1584 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001585 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001586 ae->un.MaxFrameSize =
1587 (((uint32_t) hsp->cmn.
1588 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1589 bbRcvSizeLsb;
1590 pab->ab.EntryCnt++;
1591 size += FOURBYTES + 4;
1592
1593 /* #5 Port attribute entry */
1594 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1595 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1596 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1597 len = strlen((char *)ae->un.OsDeviceName);
1598 len += (len & 3) ? (4 - (len & 3)) : 4;
1599 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1600 pab->ab.EntryCnt++;
1601 size += FOURBYTES + len;
1602
James Smart3de2a652007-08-02 11:09:59 -04001603 if (vport->cfg_fdmi_on == 2) {
dea31012005-04-17 16:05:31 -05001604 /* #6 Port attribute entry */
1605 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1606 size);
1607 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1608 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001609 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001610 len = strlen(ae->un.HostName);
1611 len += (len & 3) ? (4 - (len & 3)) : 4;
1612 ae->ad.bits.AttrLen =
1613 be16_to_cpu(FOURBYTES + len);
1614 pab->ab.EntryCnt++;
1615 size += FOURBYTES + len;
1616 }
1617
1618 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1619 /* Total size */
1620 size = GID_REQUEST_SZ - 4 + size;
1621 }
1622 break;
1623
1624 case SLI_MGMT_DHBA:
1625 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1626 CtReq->CommandResponse.bits.Size = 0;
1627 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1628 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001629 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001630 sizeof (struct lpfc_name));
1631 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1632 break;
1633
1634 case SLI_MGMT_DPRT:
1635 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1636 CtReq->CommandResponse.bits.Size = 0;
1637 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1638 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001639 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001640 sizeof (struct lpfc_name));
1641 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1642 break;
1643 }
1644
1645 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001646 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1647 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001648 bpl->tus.f.bdeFlags = 0;
1649 bpl->tus.f.bdeSize = size;
1650 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1651
1652 cmpl = lpfc_cmpl_ct_cmd_fdmi;
James Smart51ef4c22007-08-02 11:10:31 -04001653 lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001654
James Smart92d7f7b2007-06-17 19:56:38 -05001655 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001656 return 0;
1657
James Smart51ef4c22007-08-02 11:10:31 -04001658 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001659 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1660fdmi_cmd_free_bmp:
1661 kfree(bmp);
1662fdmi_cmd_free_mpvirt:
1663 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1664fdmi_cmd_free_mp:
1665 kfree(mp);
1666fdmi_cmd_exit:
1667 /* Issue FDMI request failed */
James Smarte8b62012007-08-02 11:10:09 -04001668 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1669 "0244 Issue FDMI request failed Data: x%x\n",
1670 cmdcode);
dea31012005-04-17 16:05:31 -05001671 return 1;
1672}
1673
1674void
1675lpfc_fdmi_tmo(unsigned long ptr)
1676{
James Smart2e0fef82007-06-17 19:56:36 -05001677 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1678 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001679 unsigned long iflag;
1680
James Smart2e0fef82007-06-17 19:56:36 -05001681 spin_lock_irqsave(&vport->work_port_lock, iflag);
1682 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1683 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05001684 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1685
1686 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001687 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001688 lpfc_worker_wake_up(phba);
1689 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001690 }
James Smart92d7f7b2007-06-17 19:56:38 -05001691 else
1692 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05001693}
1694
1695void
James Smart2e0fef82007-06-17 19:56:36 -05001696lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001697{
1698 struct lpfc_nodelist *ndlp;
1699
James Smart2e0fef82007-06-17 19:56:36 -05001700 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001701 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001702 if (init_utsname()->nodename[0] != '\0')
1703 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1704 else
1705 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001706 }
dea31012005-04-17 16:05:31 -05001707 return;
1708}
1709
dea31012005-04-17 16:05:31 -05001710void
James Smart2e0fef82007-06-17 19:56:36 -05001711lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001712{
1713 struct lpfc_sli *psli = &phba->sli;
1714 lpfc_vpd_t *vp = &phba->vpd;
1715 uint32_t b1, b2, b3, b4, i, rev;
1716 char c;
1717 uint32_t *ptr, str[4];
1718 uint8_t *fwname;
1719
1720 if (vp->rev.rBit) {
1721 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1722 rev = vp->rev.sli2FwRev;
1723 else
1724 rev = vp->rev.sli1FwRev;
1725
1726 b1 = (rev & 0x0000f000) >> 12;
1727 b2 = (rev & 0x00000f00) >> 8;
1728 b3 = (rev & 0x000000c0) >> 6;
1729 b4 = (rev & 0x00000030) >> 4;
1730
1731 switch (b4) {
1732 case 0:
1733 c = 'N';
1734 break;
1735 case 1:
1736 c = 'A';
1737 break;
1738 case 2:
1739 c = 'B';
1740 break;
1741 default:
1742 c = 0;
1743 break;
1744 }
1745 b4 = (rev & 0x0000000f);
1746
1747 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1748 fwname = vp->rev.sli2FwName;
1749 else
1750 fwname = vp->rev.sli1FwName;
1751
1752 for (i = 0; i < 16; i++)
1753 if (fwname[i] == 0x20)
1754 fwname[i] = 0;
1755
1756 ptr = (uint32_t*)fwname;
1757
1758 for (i = 0; i < 3; i++)
1759 str[i] = be32_to_cpu(*ptr++);
1760
1761 if (c == 0) {
1762 if (flag)
1763 sprintf(fwrevision, "%d.%d%d (%s)",
1764 b1, b2, b3, (char *)str);
1765 else
1766 sprintf(fwrevision, "%d.%d%d", b1,
1767 b2, b3);
1768 } else {
1769 if (flag)
1770 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1771 b1, b2, b3, c,
1772 b4, (char *)str);
1773 else
1774 sprintf(fwrevision, "%d.%d%d%c%d",
1775 b1, b2, b3, c, b4);
1776 }
1777 } else {
1778 rev = vp->rev.smFwRev;
1779
1780 b1 = (rev & 0xff000000) >> 24;
1781 b2 = (rev & 0x00f00000) >> 20;
1782 b3 = (rev & 0x000f0000) >> 16;
1783 c = (rev & 0x0000ff00) >> 8;
1784 b4 = (rev & 0x000000ff);
1785
1786 if (flag)
1787 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1788 b2, b3, c, b4);
1789 else
1790 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1791 b2, b3, c, b4);
1792 }
1793 return;
1794}