blob: 5584f395314c741ad9713e06750540afe7ab8923 [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/*
dea31012005-04-17 16:05:31 -050022 * Fibre Channel SCSI LAN Device Driver CT support
23 */
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"
dea31012005-04-17 16:05:31 -050044
45#define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
46 * incapable of reporting */
47#define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
48#define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
49#define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
50#define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
51#define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
52#define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
53
54#define FOURBYTES 4
55
56
57static char *lpfc_release_version = LPFC_DRIVER_VERSION;
58
59/*
60 * lpfc_ct_unsol_event
61 */
James Smarted957682007-06-17 19:56:37 -050062static void
63lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
64 struct lpfc_dmabuf *mp, uint32_t size)
65{
66 if (!mp) {
67 printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
68 "piocbq = %p, status = x%x, mp = %p, size = %d\n",
69 __FUNCTION__, __LINE__,
70 piocbq, piocbq->iocb.ulpStatus, mp, size);
71 }
72
73 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
74 "buffer = %p, size = %d, status = x%x\n",
75 __FUNCTION__, __LINE__,
76 piocbq, mp, size,
77 piocbq->iocb.ulpStatus);
James Smart92d7f7b2007-06-17 19:56:38 -050078
James Smarted957682007-06-17 19:56:37 -050079}
80
81static void
82lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
James Smart92d7f7b2007-06-17 19:56:38 -050083 struct lpfc_dmabuf *mp, uint32_t size)
James Smarted957682007-06-17 19:56:37 -050084{
James Smarted957682007-06-17 19:56:37 -050085 if (!mp) {
86 printk(KERN_ERR "%s (%d): Unsolited CT, no "
87 "HBQ buffer, piocbq = %p, status = x%x\n",
88 __FUNCTION__, __LINE__,
89 piocbq, piocbq->iocb.ulpStatus);
90 } else {
91 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
92 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
93 "piocbq = %p, buffer = %p, size = %d, "
94 "status = x%x\n",
95 __FUNCTION__, __LINE__,
96 piocbq, mp, size, piocbq->iocb.ulpStatus);
97 }
98}
99
dea31012005-04-17 16:05:31 -0500100void
James Smart2e0fef82007-06-17 19:56:36 -0500101lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
102 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -0500103{
James Smart92d7f7b2007-06-17 19:56:38 -0500104
James Smarted957682007-06-17 19:56:37 -0500105 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -0500106 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -0500107 int i;
108 struct lpfc_iocbq *iocbq;
109 dma_addr_t paddr;
110 uint32_t size;
James Smart92d7f7b2007-06-17 19:56:38 -0500111 struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
112 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
dea31012005-04-17 16:05:31 -0500113
James Smart92d7f7b2007-06-17 19:56:38 -0500114 piocbq->context2 = NULL;
115 piocbq->context3 = NULL;
116
117 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
118 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
119 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
120 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500121 /* Not enough posted buffers; Try posting more buffers */
122 phba->fc_stat.NoRcvBuf++;
James Smart92d7f7b2007-06-17 19:56:38 -0500123 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -0500124 lpfc_post_buffer(phba, pring, 0, 1);
dea31012005-04-17 16:05:31 -0500125 return;
126 }
127
128 /* If there are no BDEs associated with this IOCB,
129 * there is nothing to do.
130 */
131 if (icmd->ulpBdeCount == 0)
132 return;
133
James Smarted957682007-06-17 19:56:37 -0500134 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
135 list_for_each_entry(iocbq, &piocbq->list, list) {
136 icmd = &iocbq->iocb;
137 if (icmd->ulpBdeCount == 0) {
138 printk(KERN_ERR "%s (%d): Unsolited CT, no "
139 "BDE, iocbq = %p, status = x%x\n",
140 __FUNCTION__, __LINE__,
141 iocbq, iocbq->iocb.ulpStatus);
142 continue;
dea31012005-04-17 16:05:31 -0500143 }
144
James Smarted957682007-06-17 19:56:37 -0500145 size = icmd->un.cont64[0].tus.f.bdeSize;
James Smart92d7f7b2007-06-17 19:56:38 -0500146 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf1, size);
147 lpfc_in_buf_free(phba, bdeBuf1);
James Smarted957682007-06-17 19:56:37 -0500148 if (icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -0500149 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf2,
James Smarted957682007-06-17 19:56:37 -0500150 size);
James Smart92d7f7b2007-06-17 19:56:38 -0500151 lpfc_in_buf_free(phba, bdeBuf2);
James Smarted957682007-06-17 19:56:37 -0500152 }
dea31012005-04-17 16:05:31 -0500153 }
James Smarted957682007-06-17 19:56:37 -0500154 } else {
155 struct lpfc_iocbq *next;
dea31012005-04-17 16:05:31 -0500156
James Smarted957682007-06-17 19:56:37 -0500157 list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
158 icmd = &iocbq->iocb;
159 if (icmd->ulpBdeCount == 0) {
160 printk(KERN_ERR "%s (%d): Unsolited CT, no "
161 "BDE, iocbq = %p, status = x%x\n",
162 __FUNCTION__, __LINE__,
163 iocbq, iocbq->iocb.ulpStatus);
164 continue;
165 }
dea31012005-04-17 16:05:31 -0500166
James Smarted957682007-06-17 19:56:37 -0500167 for (i = 0; i < icmd->ulpBdeCount; i++) {
168 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
169 icmd->un.cont64[i].addrLow);
170 mp = lpfc_sli_ringpostbuf_get(phba, pring,
171 paddr);
172 size = icmd->un.cont64[i].tus.f.bdeSize;
173 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
James Smart92d7f7b2007-06-17 19:56:38 -0500174 lpfc_in_buf_free(phba, mp);
James Smarted957682007-06-17 19:56:37 -0500175 }
176 list_del(&iocbq->list);
177 lpfc_sli_release_iocbq(phba, iocbq);
dea31012005-04-17 16:05:31 -0500178 }
dea31012005-04-17 16:05:31 -0500179 }
dea31012005-04-17 16:05:31 -0500180}
181
182static void
James Smart2e0fef82007-06-17 19:56:36 -0500183lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500184{
185 struct lpfc_dmabuf *mlast, *next_mlast;
186
187 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
188 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
189 list_del(&mlast->list);
190 kfree(mlast);
191 }
192 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
193 kfree(mlist);
194 return;
195}
196
197static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500198lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500199 uint32_t size, int *entries)
200{
201 struct lpfc_dmabuf *mlist = NULL;
202 struct lpfc_dmabuf *mp;
203 int cnt, i = 0;
204
205 /* We get chucks of FCELSSIZE */
206 cnt = size > FCELSSIZE ? FCELSSIZE: size;
207
208 while (size) {
209 /* Allocate buffer for rsp payload */
210 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
211 if (!mp) {
212 if (mlist)
213 lpfc_free_ct_rsp(phba, mlist);
214 return NULL;
215 }
216
217 INIT_LIST_HEAD(&mp->list);
218
James Smart92d7f7b2007-06-17 19:56:38 -0500219 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
220 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea31012005-04-17 16:05:31 -0500221 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
222 else
223 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
224
225 if (!mp->virt) {
226 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700227 if (mlist)
228 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500229 return NULL;
230 }
231
232 /* Queue it to a linked list */
233 if (!mlist)
234 mlist = mp;
235 else
236 list_add_tail(&mp->list, &mlist->list);
237
238 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
239 /* build buffer ptr list for IOCB */
James Smart92d7f7b2007-06-17 19:56:38 -0500240 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
241 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea31012005-04-17 16:05:31 -0500242 bpl->tus.f.bdeSize = (uint16_t) cnt;
243 bpl->tus.w = le32_to_cpu(bpl->tus.w);
244 bpl++;
245
246 i++;
247 size -= cnt;
248 }
249
250 *entries = i;
251 return mlist;
252}
253
254static int
James Smart2e0fef82007-06-17 19:56:36 -0500255lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500256 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
257 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
258 struct lpfc_iocbq *),
259 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
James Smart92d7f7b2007-06-17 19:56:38 -0500260 uint32_t tmo, uint8_t retry)
dea31012005-04-17 16:05:31 -0500261{
James Smart2e0fef82007-06-17 19:56:36 -0500262 struct lpfc_hba *phba = vport->phba;
263 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500264 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500265 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400266 struct lpfc_iocbq *geniocb;
James Smart92d7f7b2007-06-17 19:56:38 -0500267 int rc;
dea31012005-04-17 16:05:31 -0500268
269 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400270 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500271
272 if (geniocb == NULL)
273 return 1;
dea31012005-04-17 16:05:31 -0500274
275 icmd = &geniocb->iocb;
276 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
277 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
278 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
279 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
280 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
281
282 if (usr_flg)
283 geniocb->context3 = NULL;
284 else
285 geniocb->context3 = (uint8_t *) bmp;
286
287 /* Save for completion so we can release these resources */
288 geniocb->context1 = (uint8_t *) inp;
289 geniocb->context2 = (uint8_t *) outp;
290
291 /* Fill in payload, bp points to frame payload */
292 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
293
294 /* Fill in rest of iocb */
295 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
296 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
297 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
298 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
299
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500300 if (!tmo) {
301 /* FC spec states we need 3 * ratov for CT requests */
302 tmo = (3 * phba->fc_ratov);
303 }
dea31012005-04-17 16:05:31 -0500304 icmd->ulpTimeout = tmo;
305 icmd->ulpBdeCount = 1;
306 icmd->ulpLe = 1;
307 icmd->ulpClass = CLASS3;
308 icmd->ulpContext = ndlp->nlp_rpi;
309
James Smart92d7f7b2007-06-17 19:56:38 -0500310 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
311 /* For GEN_REQUEST64_CR, use the RPI */
312 icmd->ulpCt_h = 0;
313 icmd->ulpCt_l = 0;
314 }
315
dea31012005-04-17 16:05:31 -0500316 /* Issue GEN REQ IOCB for NPORT <did> */
317 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -0500318 "%d (%d):0119 Issue GEN REQ IOCB to NPORT x%x "
319 "Data: x%x x%x\n", phba->brd_no, vport->vpi,
320 ndlp->nlp_DID, icmd->ulpIoTag,
321 vport->port_state);
dea31012005-04-17 16:05:31 -0500322 geniocb->iocb_cmpl = cmpl;
323 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500324 geniocb->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500325 geniocb->retry = retry;
326 rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
327
328 if (rc == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500329 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500330 return 1;
331 }
dea31012005-04-17 16:05:31 -0500332
333 return 0;
334}
335
336static int
James Smart2e0fef82007-06-17 19:56:36 -0500337lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500338 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
339 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
340 struct lpfc_iocbq *),
James Smart92d7f7b2007-06-17 19:56:38 -0500341 uint32_t rsp_size, uint8_t retry)
dea31012005-04-17 16:05:31 -0500342{
James Smart2e0fef82007-06-17 19:56:36 -0500343 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500344 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
345 struct lpfc_dmabuf *outmp;
346 int cnt = 0, status;
347 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
348 CommandResponse.bits.CmdRsp;
349
350 bpl++; /* Skip past ct request */
351
352 /* Put buffer(s) for ct rsp in bpl */
353 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
354 if (!outmp)
355 return -ENOMEM;
356
James Smart2e0fef82007-06-17 19:56:36 -0500357 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
James Smart92d7f7b2007-06-17 19:56:38 -0500358 cnt+1, 0, retry);
dea31012005-04-17 16:05:31 -0500359 if (status) {
360 lpfc_free_ct_rsp(phba, outmp);
361 return -ENOMEM;
362 }
363 return 0;
364}
365
James Smart92d7f7b2007-06-17 19:56:38 -0500366static struct lpfc_vport *
367lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
368
369 struct lpfc_vport *vport_curr;
370
371 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
372 if ((vport_curr->fc_myDID) &&
373 (vport_curr->fc_myDID == did))
374 return vport_curr;
375 }
376
377 return NULL;
378}
379
dea31012005-04-17 16:05:31 -0500380static int
James Smart2e0fef82007-06-17 19:56:36 -0500381lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500382{
James Smart2e0fef82007-06-17 19:56:36 -0500383 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500384 struct lpfc_sli_ct_request *Response =
385 (struct lpfc_sli_ct_request *) mp->virt;
386 struct lpfc_nodelist *ndlp = NULL;
387 struct lpfc_dmabuf *mlast, *next_mp;
388 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500389 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500390 int Cnt;
391 struct list_head head;
392
James Smart2e0fef82007-06-17 19:56:36 -0500393 lpfc_set_disctmo(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500394 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -0500395
dea31012005-04-17 16:05:31 -0500396
397 list_add_tail(&head, &mp->list);
398 list_for_each_entry_safe(mp, next_mp, &head, list) {
399 mlast = mp;
400
James Smart7054a602007-04-25 09:52:34 -0400401 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
402
dea31012005-04-17 16:05:31 -0500403 Size -= Cnt;
404
James Smart1dcb58e2007-04-25 09:51:30 -0400405 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500406 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400407 } else
dea31012005-04-17 16:05:31 -0500408 Cnt -= 16; /* subtract length of CT header */
409
410 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400411 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500412 /* Get next DID from NameServer List */
413 CTentry = *ctptr++;
414 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
James Smart92d7f7b2007-06-17 19:56:38 -0500415
dea31012005-04-17 16:05:31 -0500416 ndlp = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500417
418 /*
419 * Check for rscn processing or not
420 * To conserve rpi's, filter out addresses for other
421 * vports on the same physical HBAs.
422 */
423 if ((Did != vport->fc_myDID) &&
424 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
425 phba->cfg_peer_port_login)) {
426 if ((vport->port_type != LPFC_NPIV_PORT) ||
427 (vport->fc_flag & FC_RFF_NOT_SUPPORTED) ||
428 (!phba->cfg_vport_restrict_login)) {
429 ndlp = lpfc_setup_disc_node(vport, Did);
430 if (ndlp) {
431 lpfc_printf_log(phba, KERN_INFO,
432 LOG_DISCOVERY,
433 "%d (%d):0238 Process "
434 "x%x NameServer Rsp"
435 "Data: x%x x%x x%x\n",
436 phba->brd_no,
437 vport->vpi, Did,
438 ndlp->nlp_flag,
439 vport->fc_flag,
440 vport->fc_rscn_id_cnt);
441 } else {
442 lpfc_printf_log(phba, KERN_INFO,
443 LOG_DISCOVERY,
444 "%d (%d):0239 Skip x%x "
445 "NameServer Rsp Data: "
446 "x%x x%x\n",
447 phba->brd_no,
448 vport->vpi, Did,
449 vport->fc_flag,
450 vport->fc_rscn_id_cnt);
451 }
452
453 } else {
454 if (!(vport->fc_flag & FC_RSCN_MODE) ||
455 (lpfc_rscn_payload_check(vport, Did))) {
456 if (lpfc_ns_cmd(vport,
457 SLI_CTNS_GFF_ID,
458 0, Did) == 0)
459 vport->num_disc_nodes++;
460 }
461 else {
462 lpfc_printf_log(phba, KERN_INFO,
463 LOG_DISCOVERY,
464 "%d (%d):0245 Skip x%x "
465 "NameServer Rsp Data: "
466 "x%x x%x\n",
467 phba->brd_no,
468 vport->vpi, Did,
469 vport->fc_flag,
470 vport->fc_rscn_id_cnt);
471 }
472 }
dea31012005-04-17 16:05:31 -0500473 }
dea31012005-04-17 16:05:31 -0500474 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
475 goto nsout1;
476 Cnt -= sizeof (uint32_t);
477 }
478 ctptr = NULL;
479
480 }
481
482nsout1:
483 list_del(&head);
dea31012005-04-17 16:05:31 -0500484 return 0;
485}
486
dea31012005-04-17 16:05:31 -0500487static void
James Smart2e0fef82007-06-17 19:56:36 -0500488lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
489 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500490{
James Smart2e0fef82007-06-17 19:56:36 -0500491 struct lpfc_vport *vport = cmdiocb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -0500492 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500493 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500494 struct lpfc_dmabuf *bmp;
495 struct lpfc_dmabuf *inp;
496 struct lpfc_dmabuf *outp;
dea31012005-04-17 16:05:31 -0500497 struct lpfc_sli_ct_request *CTrsp;
James Smart2e0fef82007-06-17 19:56:36 -0500498 int rc;
dea31012005-04-17 16:05:31 -0500499
dea31012005-04-17 16:05:31 -0500500 /* we pass cmdiocb to state machine which needs rspiocb as well */
501 cmdiocb->context_un.rsp_iocb = rspiocb;
502
503 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
504 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
505 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
506
James Smart92d7f7b2007-06-17 19:56:38 -0500507 /* Don't bother processing response if vport is being torn down. */
508 if (vport->load_flag & FC_UNLOADING)
509 goto out;
510
dea31012005-04-17 16:05:31 -0500511 irsp = &rspiocb->iocb;
512 if (irsp->ulpStatus) {
513 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
514 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
James Smart2e0fef82007-06-17 19:56:36 -0500515 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
James Smart92d7f7b2007-06-17 19:56:38 -0500516 goto err1;
dea31012005-04-17 16:05:31 -0500517
518 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500519 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
520 vport->fc_ns_retry++;
dea31012005-04-17 16:05:31 -0500521 /* CT command is being retried */
James Smart92d7f7b2007-06-17 19:56:38 -0500522 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
523 vport->fc_ns_retry, 0);
524 if (rc == 0)
525 goto out;
526 }
527err1:
528 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
529 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
530 "%d (%d):0257 GID_FT Query error: 0x%x 0x%x\n",
531 phba->brd_no, vport->vpi, irsp->ulpStatus,
532 vport->fc_ns_retry);
dea31012005-04-17 16:05:31 -0500533 } else {
534 /* Good status, continue checking */
535 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
536 if (CTrsp->CommandResponse.bits.CmdRsp ==
537 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500538 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500539 "%d (%d):0208 NameServer Rsp "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500540 "Data: x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500541 phba->brd_no, vport->vpi,
James Smart2e0fef82007-06-17 19:56:36 -0500542 vport->fc_flag);
543 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500544 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
545 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
546 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
547 /* NameServer Rsp Error */
548 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500549 "%d (%d):0240 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500550 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500551 phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -0500552 CTrsp->CommandResponse.bits.CmdRsp,
553 (uint32_t) CTrsp->ReasonCode,
554 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500555 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500556 } else {
557 /* NameServer Rsp Error */
James Smart92d7f7b2007-06-17 19:56:38 -0500558 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
559 "%d (%d):0241 NameServer Rsp Error "
dea31012005-04-17 16:05:31 -0500560 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500561 phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -0500562 CTrsp->CommandResponse.bits.CmdRsp,
563 (uint32_t) CTrsp->ReasonCode,
564 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500565 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500566 }
567 }
568 /* Link up / RSCN discovery */
James Smart92d7f7b2007-06-17 19:56:38 -0500569 if (vport->num_disc_nodes == 0) {
570 /*
571 * The driver has cycled through all Nports in the RSCN payload.
572 * Complete the handling by cleaning up and marking the
573 * current driver state.
574 */
575 if (vport->port_state >= LPFC_DISC_AUTH) {
576 if (vport->fc_flag & FC_RSCN_MODE) {
577 lpfc_els_flush_rscn(vport);
578 spin_lock_irq(shost->host_lock);
579 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
580 spin_unlock_irq(shost->host_lock);
581 }
582 else
583 lpfc_els_flush_rscn(vport);
584 }
585
586 lpfc_disc_start(vport);
587 }
dea31012005-04-17 16:05:31 -0500588out:
589 lpfc_free_ct_rsp(phba, outp);
590 lpfc_mbuf_free(phba, inp->virt, inp->phys);
591 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
592 kfree(inp);
593 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500594 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500595 return;
596}
597
James Smart92d7f7b2007-06-17 19:56:38 -0500598void
599lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
600 struct lpfc_iocbq *rspiocb)
601{
602 struct lpfc_vport *vport = cmdiocb->vport;
603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
604 IOCB_t *irsp = &rspiocb->iocb;
605 struct lpfc_dmabuf *bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
606 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
607 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
608 struct lpfc_sli_ct_request *CTrsp;
609 int did;
610 uint8_t fbits;
611 struct lpfc_nodelist *ndlp;
612
613 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
614 did = be32_to_cpu(did);
615
616 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
617 /* Good status, continue checking */
618 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
619 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
620
621 if (CTrsp->CommandResponse.bits.CmdRsp ==
622 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
623 if ((fbits & FC4_FEATURE_INIT) &&
624 !(fbits & FC4_FEATURE_TARGET)) {
625 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
626 "%d (%d):0245 Skip x%x GFF "
627 "NameServer Rsp Data: (init) "
628 "x%x x%x\n", phba->brd_no,
629 vport->vpi, did, fbits,
630 vport->fc_rscn_id_cnt);
631 goto out;
632 }
633 }
634 }
635 /* This is a target port, unregistered port, or the GFF_ID failed */
636 ndlp = lpfc_setup_disc_node(vport, did);
637 if (ndlp) {
638 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
639 "%d (%d):0242 Process x%x GFF "
640 "NameServer Rsp Data: x%x x%x x%x\n",
641 phba->brd_no, vport->vpi,
642 did, ndlp->nlp_flag, vport->fc_flag,
643 vport->fc_rscn_id_cnt);
644 } else {
645 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
646 "%d (%d):0243 Skip x%x GFF "
647 "NameServer Rsp Data: x%x x%x\n",
648 phba->brd_no, vport->vpi, did,
649 vport->fc_flag, vport->fc_rscn_id_cnt);
650 }
651out:
652 /* Link up / RSCN discovery */
653 if (vport->num_disc_nodes)
654 vport->num_disc_nodes--;
655 if (vport->num_disc_nodes == 0) {
656 /*
657 * The driver has cycled through all Nports in the RSCN payload.
658 * Complete the handling by cleaning up and marking the
659 * current driver state.
660 */
661 if (vport->port_state >= LPFC_DISC_AUTH) {
662 if (vport->fc_flag & FC_RSCN_MODE) {
663 lpfc_els_flush_rscn(vport);
664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
666 spin_unlock_irq(shost->host_lock);
667 }
668 else
669 lpfc_els_flush_rscn(vport);
670 }
671 lpfc_disc_start(vport);
672 }
673
674 lpfc_free_ct_rsp(phba, outp);
675 lpfc_mbuf_free(phba, inp->virt, inp->phys);
676 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
677 kfree(inp);
678 kfree(bmp);
679 lpfc_sli_release_iocbq(phba, cmdiocb);
680 return;
681}
682
683
dea31012005-04-17 16:05:31 -0500684static void
James Smart2e0fef82007-06-17 19:56:36 -0500685lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
686 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500687{
James Smart92d7f7b2007-06-17 19:56:38 -0500688 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500689 struct lpfc_dmabuf *bmp;
690 struct lpfc_dmabuf *inp;
691 struct lpfc_dmabuf *outp;
692 IOCB_t *irsp;
693 struct lpfc_sli_ct_request *CTrsp;
James Smart92d7f7b2007-06-17 19:56:38 -0500694 int cmdcode, rc;
695 uint8_t retry;
dea31012005-04-17 16:05:31 -0500696
dea31012005-04-17 16:05:31 -0500697 /* we pass cmdiocb to state machine which needs rspiocb as well */
698 cmdiocb->context_un.rsp_iocb = rspiocb;
699
700 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
701 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
702 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
703 irsp = &rspiocb->iocb;
704
James Smart92d7f7b2007-06-17 19:56:38 -0500705 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
706 CommandResponse.bits.CmdRsp);
dea31012005-04-17 16:05:31 -0500707 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
708
James Smart92d7f7b2007-06-17 19:56:38 -0500709 /* NS request completes status <ulpStatus> CmdRsp <CmdRsp> */
dea31012005-04-17 16:05:31 -0500710 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500711 "%d (%d):0209 NS request %x completes "
712 "ulpStatus x%x / x%x "
James Smart2e0fef82007-06-17 19:56:36 -0500713 "CmdRsp x%x, Context x%x, Tag x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500714 phba->brd_no, vport->vpi,
715 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart2e0fef82007-06-17 19:56:36 -0500716 CTrsp->CommandResponse.bits.CmdRsp,
717 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500718
James Smart92d7f7b2007-06-17 19:56:38 -0500719 if (irsp->ulpStatus) {
720 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
721 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
722 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
723 goto out;
724
725 retry = cmdiocb->retry;
726 if (retry >= LPFC_MAX_NS_RETRY)
727 goto out;
728
729 retry++;
730 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
731 "%d (%d):0216 Retrying NS cmd %x\n",
732 phba->brd_no, vport->vpi, cmdcode);
733 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
734 if (rc == 0)
735 goto out;
736 }
737
738out:
dea31012005-04-17 16:05:31 -0500739 lpfc_free_ct_rsp(phba, outp);
740 lpfc_mbuf_free(phba, inp->virt, inp->phys);
741 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
742 kfree(inp);
743 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500744 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500745 return;
746}
747
748static void
James Smart2e0fef82007-06-17 19:56:36 -0500749lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
750 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500751{
752 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
753 return;
754}
755
756static void
James Smart92d7f7b2007-06-17 19:56:38 -0500757lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
758 struct lpfc_iocbq *rspiocb)
759{
760 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
761 return;
762}
763
764static void
James Smart2e0fef82007-06-17 19:56:36 -0500765lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
766 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500767{
768 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
769 return;
770}
771
James Smart2fb9bd82006-12-02 13:33:57 -0500772static void
James Smart92d7f7b2007-06-17 19:56:38 -0500773lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
774 struct lpfc_iocbq *rspiocb)
James Smart2fb9bd82006-12-02 13:33:57 -0500775{
James Smart92d7f7b2007-06-17 19:56:38 -0500776 IOCB_t *irsp = &rspiocb->iocb;
777 struct lpfc_vport *vport = cmdiocb->vport;
778
779 if (irsp->ulpStatus != IOSTAT_SUCCESS)
780 vport->fc_flag |= FC_RFF_NOT_SUPPORTED;
781
James Smart2fb9bd82006-12-02 13:33:57 -0500782 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
783 return;
784}
785
James Smart92d7f7b2007-06-17 19:56:38 -0500786int
787lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
788 size_t size)
789{
790 int n;
791 uint8_t *wwn = vport->phba->wwpn;
792
793 n = snprintf(symbol, size,
794 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
795 wwn[0], wwn[1], wwn[2], wwn[3],
796 wwn[4], wwn[5], wwn[6], wwn[7]);
797
798 if (vport->port_type == LPFC_PHYSICAL_PORT)
799 return n;
800
801 if (n < size)
802 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
803
804 if (n < size && vport->vname)
805 n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
806 return n;
807}
808
809int
810lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
811 size_t size)
dea31012005-04-17 16:05:31 -0500812{
813 char fwrev[16];
James Smart92d7f7b2007-06-17 19:56:38 -0500814 int n;
dea31012005-04-17 16:05:31 -0500815
James Smart92d7f7b2007-06-17 19:56:38 -0500816 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea31012005-04-17 16:05:31 -0500817
James Smart92d7f7b2007-06-17 19:56:38 -0500818 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
819 vport->phba->ModelName, fwrev, lpfc_release_version);
820 return n;
dea31012005-04-17 16:05:31 -0500821}
822
823/*
824 * lpfc_ns_cmd
825 * Description:
826 * Issue Cmd to NameServer
827 * SLI_CTNS_GID_FT
828 * LI_CTNS_RFT_ID
829 */
830int
James Smart92d7f7b2007-06-17 19:56:38 -0500831lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
832 uint8_t retry, uint32_t context)
dea31012005-04-17 16:05:31 -0500833{
James Smart92d7f7b2007-06-17 19:56:38 -0500834 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500835 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500836 struct lpfc_dmabuf *mp, *bmp;
837 struct lpfc_sli_ct_request *CtReq;
838 struct ulp_bde64 *bpl;
839 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
840 struct lpfc_iocbq *) = NULL;
841 uint32_t rsp_size = 1024;
James Smart92d7f7b2007-06-17 19:56:38 -0500842 size_t size;
843
844 ndlp = lpfc_findnode_did(vport, NameServer_DID);
845 if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
846 return 1;
dea31012005-04-17 16:05:31 -0500847
848 /* fill in BDEs for command */
849 /* Allocate buffer for command payload */
850 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
851 if (!mp)
852 goto ns_cmd_exit;
853
854 INIT_LIST_HEAD(&mp->list);
855 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
856 if (!mp->virt)
857 goto ns_cmd_free_mp;
858
859 /* Allocate buffer for Buffer ptr list */
860 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
861 if (!bmp)
862 goto ns_cmd_free_mpvirt;
863
864 INIT_LIST_HEAD(&bmp->list);
865 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
866 if (!bmp->virt)
867 goto ns_cmd_free_bmp;
868
869 /* NameServer Req */
James Smart92d7f7b2007-06-17 19:56:38 -0500870 lpfc_printf_log(phba, KERN_INFO ,LOG_DISCOVERY,
871 "%d (%d):0236 NameServer Req Data: x%x x%x x%x\n",
872 phba->brd_no, vport->vpi, cmdcode, vport->fc_flag,
James Smart2e0fef82007-06-17 19:56:36 -0500873 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -0500874
875 bpl = (struct ulp_bde64 *) bmp->virt;
876 memset(bpl, 0, sizeof(struct ulp_bde64));
James Smart92d7f7b2007-06-17 19:56:38 -0500877 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
878 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -0500879 bpl->tus.f.bdeFlags = 0;
880 if (cmdcode == SLI_CTNS_GID_FT)
881 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -0500882 else if (cmdcode == SLI_CTNS_GFF_ID)
883 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -0500884 else if (cmdcode == SLI_CTNS_RFT_ID)
885 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
886 else if (cmdcode == SLI_CTNS_RNN_ID)
887 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
James Smart92d7f7b2007-06-17 19:56:38 -0500888 else if (cmdcode == SLI_CTNS_RSPN_ID)
889 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea31012005-04-17 16:05:31 -0500890 else if (cmdcode == SLI_CTNS_RSNN_NN)
891 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -0500892 else if (cmdcode == SLI_CTNS_RFF_ID)
893 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -0500894 else
895 bpl->tus.f.bdeSize = 0;
896 bpl->tus.w = le32_to_cpu(bpl->tus.w);
897
898 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
899 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
900 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
901 CtReq->RevisionId.bits.InId = 0;
902 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
903 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
904 CtReq->CommandResponse.bits.Size = 0;
905 switch (cmdcode) {
906 case SLI_CTNS_GID_FT:
907 CtReq->CommandResponse.bits.CmdRsp =
908 be16_to_cpu(SLI_CTNS_GID_FT);
909 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart92d7f7b2007-06-17 19:56:38 -0500910 if (vport->port_state < LPFC_NS_QRY)
James Smart2e0fef82007-06-17 19:56:36 -0500911 vport->port_state = LPFC_NS_QRY;
912 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500913 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
914 rsp_size = FC_MAX_NS_RSP;
915 break;
916
James Smart92d7f7b2007-06-17 19:56:38 -0500917 case SLI_CTNS_GFF_ID:
918 CtReq->CommandResponse.bits.CmdRsp =
919 be16_to_cpu(SLI_CTNS_GFF_ID);
920 CtReq->un.gff.PortId = be32_to_cpu(context);
921 cmpl = lpfc_cmpl_ct_cmd_gff_id;
922 break;
923
dea31012005-04-17 16:05:31 -0500924 case SLI_CTNS_RFT_ID:
925 CtReq->CommandResponse.bits.CmdRsp =
926 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500927 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -0500928 CtReq->un.rft.fcpReg = 1;
929 cmpl = lpfc_cmpl_ct_cmd_rft_id;
930 break;
931
932 case SLI_CTNS_RNN_ID:
933 CtReq->CommandResponse.bits.CmdRsp =
934 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500935 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
936 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -0500937 sizeof (struct lpfc_name));
938 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
939 break;
940
James Smart92d7f7b2007-06-17 19:56:38 -0500941 case SLI_CTNS_RSPN_ID:
942 CtReq->CommandResponse.bits.CmdRsp =
943 be16_to_cpu(SLI_CTNS_RSPN_ID);
944 CtReq->un.rspn.PortId = be32_to_cpu(vport->fc_myDID);
945 size = sizeof(CtReq->un.rspn.symbname);
946 CtReq->un.rspn.len =
947 lpfc_vport_symbolic_port_name(vport,
948 CtReq->un.rspn.symbname, size);
949 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
950 break;
dea31012005-04-17 16:05:31 -0500951 case SLI_CTNS_RSNN_NN:
952 CtReq->CommandResponse.bits.CmdRsp =
953 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -0500954 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -0500955 sizeof (struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500956 size = sizeof(CtReq->un.rsnn.symbname);
957 CtReq->un.rsnn.len =
958 lpfc_vport_symbolic_node_name(vport,
959 CtReq->un.rsnn.symbname, size);
dea31012005-04-17 16:05:31 -0500960 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
961 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500962 case SLI_CTNS_RFF_ID:
963 vport->fc_flag &= ~FC_RFF_NOT_SUPPORTED;
964 CtReq->CommandResponse.bits.CmdRsp =
965 be16_to_cpu(SLI_CTNS_RFF_ID);
966 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);;
967 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
968 CtReq->un.rff.type_code = FC_FCP_DATA;
969 cmpl = lpfc_cmpl_ct_cmd_rff_id;
970 break;
dea31012005-04-17 16:05:31 -0500971 }
972
James Smart92d7f7b2007-06-17 19:56:38 -0500973 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry))
dea31012005-04-17 16:05:31 -0500974 /* On success, The cmpl function will free the buffers */
975 return 0;
976
977 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
978ns_cmd_free_bmp:
979 kfree(bmp);
980ns_cmd_free_mpvirt:
981 lpfc_mbuf_free(phba, mp->virt, mp->phys);
982ns_cmd_free_mp:
983 kfree(mp);
984ns_cmd_exit:
985 return 1;
986}
987
988static void
James Smart2e0fef82007-06-17 19:56:36 -0500989lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
990 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -0500991{
992 struct lpfc_dmabuf *bmp = cmdiocb->context3;
993 struct lpfc_dmabuf *inp = cmdiocb->context1;
994 struct lpfc_dmabuf *outp = cmdiocb->context2;
995 struct lpfc_sli_ct_request *CTrsp = outp->virt;
996 struct lpfc_sli_ct_request *CTcmd = inp->virt;
997 struct lpfc_nodelist *ndlp;
998 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
999 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -05001000 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001001
James Smart2e0fef82007-06-17 19:56:36 -05001002 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001003 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1004 /* FDMI rsp failed */
James Smarted957682007-06-17 19:56:37 -05001005 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05001006 "%d (%d):0220 FDMI rsp failed Data: x%x\n",
1007 phba->brd_no, vport->vpi,
1008 be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -05001009 }
1010
1011 switch (be16_to_cpu(fdmi_cmd)) {
1012 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001013 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -05001014 break;
1015
1016 case SLI_MGMT_RPA:
1017 break;
1018
1019 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -05001020 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -05001021 break;
1022
1023 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -05001024 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -05001025 break;
1026 }
1027
1028 lpfc_free_ct_rsp(phba, outp);
1029 lpfc_mbuf_free(phba, inp->virt, inp->phys);
1030 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1031 kfree(inp);
1032 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -05001033 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05001034 return;
1035}
James Smart2e0fef82007-06-17 19:56:36 -05001036
dea31012005-04-17 16:05:31 -05001037int
James Smart2e0fef82007-06-17 19:56:36 -05001038lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -05001039{
James Smart2e0fef82007-06-17 19:56:36 -05001040 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001041 struct lpfc_dmabuf *mp, *bmp;
1042 struct lpfc_sli_ct_request *CtReq;
1043 struct ulp_bde64 *bpl;
1044 uint32_t size;
1045 REG_HBA *rh;
1046 PORT_ENTRY *pe;
1047 REG_PORT_ATTRIBUTE *pab;
1048 ATTRIBUTE_BLOCK *ab;
1049 ATTRIBUTE_ENTRY *ae;
1050 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1051 struct lpfc_iocbq *);
1052
1053
1054 /* fill in BDEs for command */
1055 /* Allocate buffer for command payload */
1056 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1057 if (!mp)
1058 goto fdmi_cmd_exit;
1059
1060 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1061 if (!mp->virt)
1062 goto fdmi_cmd_free_mp;
1063
1064 /* Allocate buffer for Buffer ptr list */
1065 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1066 if (!bmp)
1067 goto fdmi_cmd_free_mpvirt;
1068
1069 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1070 if (!bmp->virt)
1071 goto fdmi_cmd_free_bmp;
1072
1073 INIT_LIST_HEAD(&mp->list);
1074 INIT_LIST_HEAD(&bmp->list);
1075
1076 /* FDMI request */
James Smarted957682007-06-17 19:56:37 -05001077 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05001078 "%d (%d):0218 FDMI Request Data: x%x x%x x%x\n",
1079 phba->brd_no, vport->vpi, vport->fc_flag,
1080 vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -05001081
1082 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1083
1084 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1085 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1086 CtReq->RevisionId.bits.InId = 0;
1087
1088 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1089 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1090 size = 0;
1091
1092 switch (cmdcode) {
1093 case SLI_MGMT_RHBA:
1094 {
1095 lpfc_vpd_t *vp = &phba->vpd;
1096 uint32_t i, j, incr;
1097 int len;
1098
1099 CtReq->CommandResponse.bits.CmdRsp =
1100 be16_to_cpu(SLI_MGMT_RHBA);
1101 CtReq->CommandResponse.bits.Size = 0;
1102 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -05001103 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001104 sizeof (struct lpfc_name));
1105 /* One entry (port) per adapter */
1106 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -05001107 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001108 sizeof (struct lpfc_name));
1109
1110 /* point to the HBA attribute block */
1111 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1112 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1113 ab->EntryCnt = 0;
1114
1115 /* Point to the beginning of the first HBA attribute
1116 entry */
1117 /* #1 HBA attribute entry */
1118 size += FOURBYTES;
1119 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1120 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1121 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1122 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001123 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -05001124 sizeof (struct lpfc_name));
1125 ab->EntryCnt++;
1126 size += FOURBYTES + sizeof (struct lpfc_name);
1127
1128 /* #2 HBA attribute entry */
1129 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1130 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1131 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1132 len = strlen(ae->un.Manufacturer);
1133 len += (len & 3) ? (4 - (len & 3)) : 4;
1134 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1135 ab->EntryCnt++;
1136 size += FOURBYTES + len;
1137
1138 /* #3 HBA attribute entry */
1139 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1140 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1141 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1142 len = strlen(ae->un.SerialNumber);
1143 len += (len & 3) ? (4 - (len & 3)) : 4;
1144 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1145 ab->EntryCnt++;
1146 size += FOURBYTES + len;
1147
1148 /* #4 HBA attribute entry */
1149 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1150 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1151 strcpy(ae->un.Model, phba->ModelName);
1152 len = strlen(ae->un.Model);
1153 len += (len & 3) ? (4 - (len & 3)) : 4;
1154 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1155 ab->EntryCnt++;
1156 size += FOURBYTES + len;
1157
1158 /* #5 HBA attribute entry */
1159 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1160 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1161 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1162 len = strlen(ae->un.ModelDescription);
1163 len += (len & 3) ? (4 - (len & 3)) : 4;
1164 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1165 ab->EntryCnt++;
1166 size += FOURBYTES + len;
1167
1168 /* #6 HBA attribute entry */
1169 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1170 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1171 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1172 /* Convert JEDEC ID to ascii for hardware version */
1173 incr = vp->rev.biuRev;
1174 for (i = 0; i < 8; i++) {
1175 j = (incr & 0xf);
1176 if (j <= 9)
1177 ae->un.HardwareVersion[7 - i] =
1178 (char)((uint8_t) 0x30 +
1179 (uint8_t) j);
1180 else
1181 ae->un.HardwareVersion[7 - i] =
1182 (char)((uint8_t) 0x61 +
1183 (uint8_t) (j - 10));
1184 incr = (incr >> 4);
1185 }
1186 ab->EntryCnt++;
1187 size += FOURBYTES + 8;
1188
1189 /* #7 HBA attribute entry */
1190 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1191 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1192 strcpy(ae->un.DriverVersion, lpfc_release_version);
1193 len = strlen(ae->un.DriverVersion);
1194 len += (len & 3) ? (4 - (len & 3)) : 4;
1195 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1196 ab->EntryCnt++;
1197 size += FOURBYTES + len;
1198
1199 /* #8 HBA attribute entry */
1200 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1201 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1202 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1203 len = strlen(ae->un.OptionROMVersion);
1204 len += (len & 3) ? (4 - (len & 3)) : 4;
1205 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1206 ab->EntryCnt++;
1207 size += FOURBYTES + len;
1208
1209 /* #9 HBA attribute entry */
1210 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1211 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1212 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1213 1);
1214 len = strlen(ae->un.FirmwareVersion);
1215 len += (len & 3) ? (4 - (len & 3)) : 4;
1216 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1217 ab->EntryCnt++;
1218 size += FOURBYTES + len;
1219
1220 /* #10 HBA attribute entry */
1221 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1222 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1223 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -05001224 init_utsname()->sysname,
1225 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001226 init_utsname()->version);
dea31012005-04-17 16:05:31 -05001227 len = strlen(ae->un.OsNameVersion);
1228 len += (len & 3) ? (4 - (len & 3)) : 4;
1229 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1230 ab->EntryCnt++;
1231 size += FOURBYTES + len;
1232
1233 /* #11 HBA attribute entry */
1234 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1235 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1236 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1237 ae->un.MaxCTPayloadLen = (65 * 4096);
1238 ab->EntryCnt++;
1239 size += FOURBYTES + 4;
1240
1241 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1242 /* Total size */
1243 size = GID_REQUEST_SZ - 4 + size;
1244 }
1245 break;
1246
1247 case SLI_MGMT_RPA:
1248 {
1249 lpfc_vpd_t *vp;
1250 struct serv_parm *hsp;
1251 int len;
1252
1253 vp = &phba->vpd;
1254
1255 CtReq->CommandResponse.bits.CmdRsp =
1256 be16_to_cpu(SLI_MGMT_RPA);
1257 CtReq->CommandResponse.bits.Size = 0;
1258 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1259 size = sizeof (struct lpfc_name) + FOURBYTES;
1260 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001261 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001262 sizeof (struct lpfc_name));
1263 pab->ab.EntryCnt = 0;
1264
1265 /* #1 Port attribute entry */
1266 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1267 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1268 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1269 ae->un.SupportFC4Types[2] = 1;
1270 ae->un.SupportFC4Types[7] = 1;
1271 pab->ab.EntryCnt++;
1272 size += FOURBYTES + 32;
1273
1274 /* #2 Port attribute entry */
1275 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1276 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1277 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001278
1279 ae->un.SupportSpeed = 0;
1280 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001281 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001282 if (phba->lmt & LMT_8Gb)
1283 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1284 if (phba->lmt & LMT_4Gb)
1285 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1286 if (phba->lmt & LMT_2Gb)
1287 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1288 if (phba->lmt & LMT_1Gb)
1289 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1290
dea31012005-04-17 16:05:31 -05001291 pab->ab.EntryCnt++;
1292 size += FOURBYTES + 4;
1293
1294 /* #3 Port attribute entry */
1295 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1296 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1297 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1298 switch(phba->fc_linkspeed) {
1299 case LA_1GHZ_LINK:
1300 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1301 break;
1302 case LA_2GHZ_LINK:
1303 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1304 break;
1305 case LA_4GHZ_LINK:
1306 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1307 break;
James Smartb87eab32007-04-25 09:53:28 -04001308 case LA_8GHZ_LINK:
1309 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1310 break;
dea31012005-04-17 16:05:31 -05001311 default:
1312 ae->un.PortSpeed =
1313 HBA_PORTSPEED_UNKNOWN;
1314 break;
1315 }
1316 pab->ab.EntryCnt++;
1317 size += FOURBYTES + 4;
1318
1319 /* #4 Port attribute entry */
1320 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1321 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1322 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001323 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001324 ae->un.MaxFrameSize =
1325 (((uint32_t) hsp->cmn.
1326 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1327 bbRcvSizeLsb;
1328 pab->ab.EntryCnt++;
1329 size += FOURBYTES + 4;
1330
1331 /* #5 Port attribute entry */
1332 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1333 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1334 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1335 len = strlen((char *)ae->un.OsDeviceName);
1336 len += (len & 3) ? (4 - (len & 3)) : 4;
1337 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1338 pab->ab.EntryCnt++;
1339 size += FOURBYTES + len;
1340
1341 if (phba->cfg_fdmi_on == 2) {
1342 /* #6 Port attribute entry */
1343 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1344 size);
1345 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1346 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001347 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001348 len = strlen(ae->un.HostName);
1349 len += (len & 3) ? (4 - (len & 3)) : 4;
1350 ae->ad.bits.AttrLen =
1351 be16_to_cpu(FOURBYTES + len);
1352 pab->ab.EntryCnt++;
1353 size += FOURBYTES + len;
1354 }
1355
1356 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1357 /* Total size */
1358 size = GID_REQUEST_SZ - 4 + size;
1359 }
1360 break;
1361
1362 case SLI_MGMT_DHBA:
1363 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1364 CtReq->CommandResponse.bits.Size = 0;
1365 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1366 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001367 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001368 sizeof (struct lpfc_name));
1369 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1370 break;
1371
1372 case SLI_MGMT_DPRT:
1373 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1374 CtReq->CommandResponse.bits.Size = 0;
1375 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1376 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001377 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001378 sizeof (struct lpfc_name));
1379 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1380 break;
1381 }
1382
1383 bpl = (struct ulp_bde64 *) bmp->virt;
James Smart92d7f7b2007-06-17 19:56:38 -05001384 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1385 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea31012005-04-17 16:05:31 -05001386 bpl->tus.f.bdeFlags = 0;
1387 bpl->tus.f.bdeSize = size;
1388 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1389
1390 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1391
James Smart92d7f7b2007-06-17 19:56:38 -05001392 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea31012005-04-17 16:05:31 -05001393 return 0;
1394
1395 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1396fdmi_cmd_free_bmp:
1397 kfree(bmp);
1398fdmi_cmd_free_mpvirt:
1399 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1400fdmi_cmd_free_mp:
1401 kfree(mp);
1402fdmi_cmd_exit:
1403 /* Issue FDMI request failed */
James Smarted957682007-06-17 19:56:37 -05001404 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05001405 "%d (%d):0244 Issue FDMI request failed Data: x%x\n",
1406 phba->brd_no, vport->vpi, cmdcode);
dea31012005-04-17 16:05:31 -05001407 return 1;
1408}
1409
1410void
1411lpfc_fdmi_tmo(unsigned long ptr)
1412{
James Smart2e0fef82007-06-17 19:56:36 -05001413 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1414 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001415 unsigned long iflag;
1416
James Smart2e0fef82007-06-17 19:56:36 -05001417 spin_lock_irqsave(&vport->work_port_lock, iflag);
1418 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1419 vport->work_port_events |= WORKER_FDMI_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05001420 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1421
1422 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001423 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001424 lpfc_worker_wake_up(phba);
1425 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05001426 }
James Smart92d7f7b2007-06-17 19:56:38 -05001427 else
1428 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05001429}
1430
1431void
James Smart2e0fef82007-06-17 19:56:36 -05001432lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001433{
1434 struct lpfc_nodelist *ndlp;
1435
James Smart2e0fef82007-06-17 19:56:36 -05001436 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001437 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001438 if (init_utsname()->nodename[0] != '\0')
1439 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1440 else
1441 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001442 }
dea31012005-04-17 16:05:31 -05001443 return;
1444}
1445
dea31012005-04-17 16:05:31 -05001446void
James Smart2e0fef82007-06-17 19:56:36 -05001447lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001448{
1449 struct lpfc_sli *psli = &phba->sli;
1450 lpfc_vpd_t *vp = &phba->vpd;
1451 uint32_t b1, b2, b3, b4, i, rev;
1452 char c;
1453 uint32_t *ptr, str[4];
1454 uint8_t *fwname;
1455
1456 if (vp->rev.rBit) {
1457 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1458 rev = vp->rev.sli2FwRev;
1459 else
1460 rev = vp->rev.sli1FwRev;
1461
1462 b1 = (rev & 0x0000f000) >> 12;
1463 b2 = (rev & 0x00000f00) >> 8;
1464 b3 = (rev & 0x000000c0) >> 6;
1465 b4 = (rev & 0x00000030) >> 4;
1466
1467 switch (b4) {
1468 case 0:
1469 c = 'N';
1470 break;
1471 case 1:
1472 c = 'A';
1473 break;
1474 case 2:
1475 c = 'B';
1476 break;
1477 default:
1478 c = 0;
1479 break;
1480 }
1481 b4 = (rev & 0x0000000f);
1482
1483 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1484 fwname = vp->rev.sli2FwName;
1485 else
1486 fwname = vp->rev.sli1FwName;
1487
1488 for (i = 0; i < 16; i++)
1489 if (fwname[i] == 0x20)
1490 fwname[i] = 0;
1491
1492 ptr = (uint32_t*)fwname;
1493
1494 for (i = 0; i < 3; i++)
1495 str[i] = be32_to_cpu(*ptr++);
1496
1497 if (c == 0) {
1498 if (flag)
1499 sprintf(fwrevision, "%d.%d%d (%s)",
1500 b1, b2, b3, (char *)str);
1501 else
1502 sprintf(fwrevision, "%d.%d%d", b1,
1503 b2, b3);
1504 } else {
1505 if (flag)
1506 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1507 b1, b2, b3, c,
1508 b4, (char *)str);
1509 else
1510 sprintf(fwrevision, "%d.%d%d%c%d",
1511 b1, b2, b3, c, b4);
1512 }
1513 } else {
1514 rev = vp->rev.smFwRev;
1515
1516 b1 = (rev & 0xff000000) >> 24;
1517 b2 = (rev & 0x00f00000) >> 20;
1518 b3 = (rev & 0x000f0000) >> 16;
1519 c = (rev & 0x0000ff00) >> 8;
1520 b4 = (rev & 0x000000ff);
1521
1522 if (flag)
1523 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1524 b2, b3, c, b4);
1525 else
1526 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1527 b2, b3, c, b4);
1528 }
1529 return;
1530}