blob: e8ed5d7ccf9fec779bd8581b92ea7e63fed95478 [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"
43
44#define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
45 * incapable of reporting */
46#define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
47#define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
48#define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
49#define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
50#define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
51#define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
52
53#define FOURBYTES 4
54
55
56static char *lpfc_release_version = LPFC_DRIVER_VERSION;
57
58/*
59 * lpfc_ct_unsol_event
60 */
James Smarted957682007-06-17 19:56:37 -050061static void
62lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
63 struct lpfc_dmabuf *mp, uint32_t size)
64{
65 if (!mp) {
66 printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
67 "piocbq = %p, status = x%x, mp = %p, size = %d\n",
68 __FUNCTION__, __LINE__,
69 piocbq, piocbq->iocb.ulpStatus, mp, size);
70 }
71
72 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
73 "buffer = %p, size = %d, status = x%x\n",
74 __FUNCTION__, __LINE__,
75 piocbq, mp, size,
76 piocbq->iocb.ulpStatus);
77}
78
79static void
80lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct hbq_dmabuf *sp, uint32_t size)
82{
83 struct lpfc_dmabuf *mp = NULL;
84
85 mp = sp ? &sp->dbuf : NULL;
86 if (!mp) {
87 printk(KERN_ERR "%s (%d): Unsolited CT, no "
88 "HBQ buffer, piocbq = %p, status = x%x\n",
89 __FUNCTION__, __LINE__,
90 piocbq, piocbq->iocb.ulpStatus);
91 } else {
92 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
93 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
94 "piocbq = %p, buffer = %p, size = %d, "
95 "status = x%x\n",
96 __FUNCTION__, __LINE__,
97 piocbq, mp, size, piocbq->iocb.ulpStatus);
98 }
99}
100
dea31012005-04-17 16:05:31 -0500101void
James Smart2e0fef82007-06-17 19:56:36 -0500102lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
103 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -0500104{
James Smarted957682007-06-17 19:56:37 -0500105 struct lpfc_dmabuf *mp = NULL;
106 struct hbq_dmabuf *sp = NULL;
dea31012005-04-17 16:05:31 -0500107 IOCB_t *icmd = &piocbq->iocb;
James Smarted957682007-06-17 19:56:37 -0500108 int i;
109 struct lpfc_iocbq *iocbq;
110 dma_addr_t paddr;
111 uint32_t size;
dea31012005-04-17 16:05:31 -0500112
113 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarted957682007-06-17 19:56:37 -0500114 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -0500115 /* Not enough posted buffers; Try posting more buffers */
116 phba->fc_stat.NoRcvBuf++;
James Smarted957682007-06-17 19:56:37 -0500117 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
118 lpfc_sli_hbqbuf_fill_hbq(phba);
119 else
120 lpfc_post_buffer(phba, pring, 0, 1);
dea31012005-04-17 16:05:31 -0500121 return;
122 }
123
124 /* If there are no BDEs associated with this IOCB,
125 * there is nothing to do.
126 */
127 if (icmd->ulpBdeCount == 0)
128 return;
129
James Smarted957682007-06-17 19:56:37 -0500130 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
131 list_for_each_entry(iocbq, &piocbq->list, list) {
132 icmd = &iocbq->iocb;
133 if (icmd->ulpBdeCount == 0) {
134 printk(KERN_ERR "%s (%d): Unsolited CT, no "
135 "BDE, iocbq = %p, status = x%x\n",
136 __FUNCTION__, __LINE__,
137 iocbq, iocbq->iocb.ulpStatus);
138 continue;
dea31012005-04-17 16:05:31 -0500139 }
140
James Smarted957682007-06-17 19:56:37 -0500141 size = icmd->un.cont64[0].tus.f.bdeSize;
142 sp = lpfc_sli_hbqbuf_find(phba, icmd->un.ulpWord[3]);
143 if (sp)
144 phba->hbq_buff_count--;
145 lpfc_ct_ignore_hbq_buffer(phba, iocbq, sp, size);
146 lpfc_sli_free_hbq(phba, sp);
147 if (icmd->ulpBdeCount == 2) {
148 sp = lpfc_sli_hbqbuf_find(phba,
149 icmd->un.ulpWord[15]);
150 if (sp)
151 phba->hbq_buff_count--;
152 lpfc_ct_ignore_hbq_buffer(phba, iocbq, sp,
153 size);
154 lpfc_sli_free_hbq(phba, sp);
155 }
dea31012005-04-17 16:05:31 -0500156
dea31012005-04-17 16:05:31 -0500157 }
James Smarted957682007-06-17 19:56:37 -0500158 lpfc_sli_hbqbuf_fill_hbq(phba);
159 } else {
160 struct lpfc_iocbq *next;
dea31012005-04-17 16:05:31 -0500161
James Smarted957682007-06-17 19:56:37 -0500162 list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
163 icmd = &iocbq->iocb;
164 if (icmd->ulpBdeCount == 0) {
165 printk(KERN_ERR "%s (%d): Unsolited CT, no "
166 "BDE, iocbq = %p, status = x%x\n",
167 __FUNCTION__, __LINE__,
168 iocbq, iocbq->iocb.ulpStatus);
169 continue;
170 }
dea31012005-04-17 16:05:31 -0500171
James Smarted957682007-06-17 19:56:37 -0500172 for (i = 0; i < icmd->ulpBdeCount; i++) {
173 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
174 icmd->un.cont64[i].addrLow);
175 mp = lpfc_sli_ringpostbuf_get(phba, pring,
176 paddr);
177 size = icmd->un.cont64[i].tus.f.bdeSize;
178 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
179 lpfc_mbuf_free(phba, mp->virt, mp->phys);
180 kfree(mp);
181 }
182 list_del(&iocbq->list);
183 lpfc_sli_release_iocbq(phba, iocbq);
dea31012005-04-17 16:05:31 -0500184 }
dea31012005-04-17 16:05:31 -0500185 }
dea31012005-04-17 16:05:31 -0500186}
187
188static void
James Smart2e0fef82007-06-17 19:56:36 -0500189lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500190{
191 struct lpfc_dmabuf *mlast, *next_mlast;
192
193 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
194 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
195 list_del(&mlast->list);
196 kfree(mlast);
197 }
198 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
199 kfree(mlist);
200 return;
201}
202
203static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500204lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500205 uint32_t size, int *entries)
206{
207 struct lpfc_dmabuf *mlist = NULL;
208 struct lpfc_dmabuf *mp;
209 int cnt, i = 0;
210
211 /* We get chucks of FCELSSIZE */
212 cnt = size > FCELSSIZE ? FCELSSIZE: size;
213
214 while (size) {
215 /* Allocate buffer for rsp payload */
216 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
217 if (!mp) {
218 if (mlist)
219 lpfc_free_ct_rsp(phba, mlist);
220 return NULL;
221 }
222
223 INIT_LIST_HEAD(&mp->list);
224
225 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
226 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
227 else
228 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
229
230 if (!mp->virt) {
231 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700232 if (mlist)
233 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500234 return NULL;
235 }
236
237 /* Queue it to a linked list */
238 if (!mlist)
239 mlist = mp;
240 else
241 list_add_tail(&mp->list, &mlist->list);
242
243 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
244 /* build buffer ptr list for IOCB */
245 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
246 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
247 bpl->tus.f.bdeSize = (uint16_t) cnt;
248 bpl->tus.w = le32_to_cpu(bpl->tus.w);
249 bpl++;
250
251 i++;
252 size -= cnt;
253 }
254
255 *entries = i;
256 return mlist;
257}
258
259static int
James Smart2e0fef82007-06-17 19:56:36 -0500260lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500261 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
262 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
263 struct lpfc_iocbq *),
264 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
265 uint32_t tmo)
266{
James Smart2e0fef82007-06-17 19:56:36 -0500267 struct lpfc_hba *phba = vport->phba;
268 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500269 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500270 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400271 struct lpfc_iocbq *geniocb;
dea31012005-04-17 16:05:31 -0500272
273 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400274 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500275
276 if (geniocb == NULL)
277 return 1;
dea31012005-04-17 16:05:31 -0500278
279 icmd = &geniocb->iocb;
280 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
281 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
282 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
283 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
284 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
285
286 if (usr_flg)
287 geniocb->context3 = NULL;
288 else
289 geniocb->context3 = (uint8_t *) bmp;
290
291 /* Save for completion so we can release these resources */
292 geniocb->context1 = (uint8_t *) inp;
293 geniocb->context2 = (uint8_t *) outp;
294
295 /* Fill in payload, bp points to frame payload */
296 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
297
298 /* Fill in rest of iocb */
299 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
300 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
301 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
302 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
303
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500304 if (!tmo) {
305 /* FC spec states we need 3 * ratov for CT requests */
306 tmo = (3 * phba->fc_ratov);
307 }
dea31012005-04-17 16:05:31 -0500308 icmd->ulpTimeout = tmo;
309 icmd->ulpBdeCount = 1;
310 icmd->ulpLe = 1;
311 icmd->ulpClass = CLASS3;
312 icmd->ulpContext = ndlp->nlp_rpi;
313
314 /* Issue GEN REQ IOCB for NPORT <did> */
315 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
316 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
317 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
James Smart2e0fef82007-06-17 19:56:36 -0500318 icmd->ulpIoTag, vport->port_state);
dea31012005-04-17 16:05:31 -0500319 geniocb->iocb_cmpl = cmpl;
320 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500321 geniocb->vport = vport;
dea31012005-04-17 16:05:31 -0500322 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500323 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500324 return 1;
325 }
dea31012005-04-17 16:05:31 -0500326
327 return 0;
328}
329
330static int
James Smart2e0fef82007-06-17 19:56:36 -0500331lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500332 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
333 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
334 struct lpfc_iocbq *),
335 uint32_t rsp_size)
336{
James Smart2e0fef82007-06-17 19:56:36 -0500337 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500338 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
339 struct lpfc_dmabuf *outmp;
340 int cnt = 0, status;
341 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
342 CommandResponse.bits.CmdRsp;
343
344 bpl++; /* Skip past ct request */
345
346 /* Put buffer(s) for ct rsp in bpl */
347 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
348 if (!outmp)
349 return -ENOMEM;
350
James Smart2e0fef82007-06-17 19:56:36 -0500351 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
dea31012005-04-17 16:05:31 -0500352 cnt+1, 0);
353 if (status) {
354 lpfc_free_ct_rsp(phba, outmp);
355 return -ENOMEM;
356 }
357 return 0;
358}
359
360static int
James Smart2e0fef82007-06-17 19:56:36 -0500361lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500362{
James Smart2e0fef82007-06-17 19:56:36 -0500363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
364 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500365 struct lpfc_sli_ct_request *Response =
366 (struct lpfc_sli_ct_request *) mp->virt;
367 struct lpfc_nodelist *ndlp = NULL;
368 struct lpfc_dmabuf *mlast, *next_mp;
369 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500370 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500371 int Cnt;
372 struct list_head head;
373
James Smart2e0fef82007-06-17 19:56:36 -0500374 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500375
dea31012005-04-17 16:05:31 -0500376
377 list_add_tail(&head, &mp->list);
378 list_for_each_entry_safe(mp, next_mp, &head, list) {
379 mlast = mp;
380
James Smart7054a602007-04-25 09:52:34 -0400381 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
382
dea31012005-04-17 16:05:31 -0500383 Size -= Cnt;
384
James Smart1dcb58e2007-04-25 09:51:30 -0400385 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500386 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400387 } else
dea31012005-04-17 16:05:31 -0500388 Cnt -= 16; /* subtract length of CT header */
389
390 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400391 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500392 /* Get next DID from NameServer List */
393 CTentry = *ctptr++;
394 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
dea31012005-04-17 16:05:31 -0500395 ndlp = NULL;
James Smart2e0fef82007-06-17 19:56:36 -0500396 /* Check for rscn processing or not */
397 if (Did != vport->fc_myDID)
398 ndlp = lpfc_setup_disc_node(vport, Did);
dea31012005-04-17 16:05:31 -0500399 if (ndlp) {
dea31012005-04-17 16:05:31 -0500400 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
401 "%d:0238 Process x%x NameServer"
402 " Rsp Data: x%x x%x x%x\n",
403 phba->brd_no,
404 Did, ndlp->nlp_flag,
James Smart2e0fef82007-06-17 19:56:36 -0500405 vport->fc_flag,
406 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -0500407 } else {
James Smarted957682007-06-17 19:56:37 -0500408 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -0500409 "%d:0239 Skip x%x NameServer "
410 "Rsp Data: x%x x%x x%x\n",
411 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -0500412 Did, Size, vport->fc_flag,
413 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -0500414 }
dea31012005-04-17 16:05:31 -0500415 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
416 goto nsout1;
417 Cnt -= sizeof (uint32_t);
418 }
419 ctptr = NULL;
420
421 }
422
423nsout1:
424 list_del(&head);
425
Jamie Wellnitz50eba242006-02-28 19:25:38 -0500426 /*
James Smart2e0fef82007-06-17 19:56:36 -0500427 * The driver has cycled through all Nports in the RSCN payload.
428 * Complete the handling by cleaning up and marking the
429 * current driver state.
430 */
431 if (vport->port_state == LPFC_VPORT_READY) {
432 lpfc_els_flush_rscn(vport);
433 spin_lock_irq(shost->host_lock);
434 vport->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
435 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500436 }
437 return 0;
438}
439
440
441
442
443static void
James Smart2e0fef82007-06-17 19:56:36 -0500444lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
445 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500446{
James Smart2e0fef82007-06-17 19:56:36 -0500447 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500448 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500449 struct lpfc_dmabuf *bmp;
450 struct lpfc_dmabuf *inp;
451 struct lpfc_dmabuf *outp;
452 struct lpfc_nodelist *ndlp;
453 struct lpfc_sli_ct_request *CTrsp;
James Smart2e0fef82007-06-17 19:56:36 -0500454 int rc;
dea31012005-04-17 16:05:31 -0500455
dea31012005-04-17 16:05:31 -0500456 /* we pass cmdiocb to state machine which needs rspiocb as well */
457 cmdiocb->context_un.rsp_iocb = rspiocb;
458
459 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
460 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
461 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
462
463 irsp = &rspiocb->iocb;
464 if (irsp->ulpStatus) {
465 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
466 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
James Smart2e0fef82007-06-17 19:56:36 -0500467 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
dea31012005-04-17 16:05:31 -0500468 goto out;
dea31012005-04-17 16:05:31 -0500469
470 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500471 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
472 vport->fc_ns_retry++;
dea31012005-04-17 16:05:31 -0500473 /* CT command is being retried */
James Smart2e0fef82007-06-17 19:56:36 -0500474 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -0400475 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -0500476 rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
477 if (rc == 0)
dea31012005-04-17 16:05:31 -0500478 goto out;
479 }
480 }
dea31012005-04-17 16:05:31 -0500481 } else {
482 /* Good status, continue checking */
483 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
484 if (CTrsp->CommandResponse.bits.CmdRsp ==
485 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500486 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -0400487 "%d:0208 NameServer Rsp "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500488 "Data: x%x\n",
489 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -0500490 vport->fc_flag);
491 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500492 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
493 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
494 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
495 /* NameServer Rsp Error */
496 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
497 "%d:0240 NameServer Rsp Error "
498 "Data: x%x x%x x%x x%x\n",
499 phba->brd_no,
500 CTrsp->CommandResponse.bits.CmdRsp,
501 (uint32_t) CTrsp->ReasonCode,
502 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500503 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500504 } else {
505 /* NameServer Rsp Error */
506 lpfc_printf_log(phba,
507 KERN_INFO,
508 LOG_DISCOVERY,
509 "%d:0241 NameServer Rsp Error "
510 "Data: x%x x%x x%x x%x\n",
511 phba->brd_no,
512 CTrsp->CommandResponse.bits.CmdRsp,
513 (uint32_t) CTrsp->ReasonCode,
514 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500515 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500516 }
517 }
518 /* Link up / RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500519 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500520out:
521 lpfc_free_ct_rsp(phba, outp);
522 lpfc_mbuf_free(phba, inp->virt, inp->phys);
523 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
524 kfree(inp);
525 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500526 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500527 return;
528}
529
530static void
James Smart2e0fef82007-06-17 19:56:36 -0500531lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
532 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500533{
dea31012005-04-17 16:05:31 -0500534 struct lpfc_dmabuf *bmp;
535 struct lpfc_dmabuf *inp;
536 struct lpfc_dmabuf *outp;
537 IOCB_t *irsp;
538 struct lpfc_sli_ct_request *CTrsp;
539
dea31012005-04-17 16:05:31 -0500540 /* we pass cmdiocb to state machine which needs rspiocb as well */
541 cmdiocb->context_un.rsp_iocb = rspiocb;
542
543 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
544 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
545 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
546 irsp = &rspiocb->iocb;
547
548 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
549
550 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
551 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
552 "%d:0209 RFT request completes ulpStatus x%x "
James Smart2e0fef82007-06-17 19:56:36 -0500553 "CmdRsp x%x, Context x%x, Tag x%x\n",
554 phba->brd_no, irsp->ulpStatus,
555 CTrsp->CommandResponse.bits.CmdRsp,
556 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500557
558 lpfc_free_ct_rsp(phba, outp);
559 lpfc_mbuf_free(phba, inp->virt, inp->phys);
560 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
561 kfree(inp);
562 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500563 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500564 return;
565}
566
567static void
James Smart2e0fef82007-06-17 19:56:36 -0500568lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
569 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500570{
571 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
572 return;
573}
574
575static void
James Smart2e0fef82007-06-17 19:56:36 -0500576lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
577 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500578{
579 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
580 return;
581}
582
James Smart2fb9bd82006-12-02 13:33:57 -0500583static void
584lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
585 struct lpfc_iocbq * rspiocb)
586{
587 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
588 return;
589}
590
dea31012005-04-17 16:05:31 -0500591void
James Smart2e0fef82007-06-17 19:56:36 -0500592lpfc_get_hba_sym_node_name(struct lpfc_hba *phba, uint8_t *symbp)
dea31012005-04-17 16:05:31 -0500593{
594 char fwrev[16];
595
596 lpfc_decode_firmware_rev(phba, fwrev, 0);
597
James Smartdca94792006-08-01 07:34:08 -0400598 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
599 fwrev, lpfc_release_version);
600 return;
dea31012005-04-17 16:05:31 -0500601}
602
603/*
604 * lpfc_ns_cmd
605 * Description:
606 * Issue Cmd to NameServer
607 * SLI_CTNS_GID_FT
608 * LI_CTNS_RFT_ID
609 */
610int
James Smart2e0fef82007-06-17 19:56:36 -0500611lpfc_ns_cmd(struct lpfc_vport *vport, struct lpfc_nodelist * ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -0500612{
James Smart2e0fef82007-06-17 19:56:36 -0500613 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500614 struct lpfc_dmabuf *mp, *bmp;
615 struct lpfc_sli_ct_request *CtReq;
616 struct ulp_bde64 *bpl;
617 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
618 struct lpfc_iocbq *) = NULL;
619 uint32_t rsp_size = 1024;
620
621 /* fill in BDEs for command */
622 /* Allocate buffer for command payload */
623 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
624 if (!mp)
625 goto ns_cmd_exit;
626
627 INIT_LIST_HEAD(&mp->list);
628 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
629 if (!mp->virt)
630 goto ns_cmd_free_mp;
631
632 /* Allocate buffer for Buffer ptr list */
633 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
634 if (!bmp)
635 goto ns_cmd_free_mpvirt;
636
637 INIT_LIST_HEAD(&bmp->list);
638 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
639 if (!bmp->virt)
640 goto ns_cmd_free_bmp;
641
642 /* NameServer Req */
643 lpfc_printf_log(phba,
644 KERN_INFO,
645 LOG_DISCOVERY,
646 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500647 phba->brd_no, cmdcode, vport->fc_flag,
648 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -0500649
650 bpl = (struct ulp_bde64 *) bmp->virt;
651 memset(bpl, 0, sizeof(struct ulp_bde64));
652 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
653 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
654 bpl->tus.f.bdeFlags = 0;
655 if (cmdcode == SLI_CTNS_GID_FT)
656 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
657 else if (cmdcode == SLI_CTNS_RFT_ID)
658 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
659 else if (cmdcode == SLI_CTNS_RNN_ID)
660 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
661 else if (cmdcode == SLI_CTNS_RSNN_NN)
662 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -0500663 else if (cmdcode == SLI_CTNS_RFF_ID)
664 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -0500665 else
666 bpl->tus.f.bdeSize = 0;
667 bpl->tus.w = le32_to_cpu(bpl->tus.w);
668
669 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
670 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
671 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
672 CtReq->RevisionId.bits.InId = 0;
673 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
674 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
675 CtReq->CommandResponse.bits.Size = 0;
676 switch (cmdcode) {
677 case SLI_CTNS_GID_FT:
678 CtReq->CommandResponse.bits.CmdRsp =
679 be16_to_cpu(SLI_CTNS_GID_FT);
680 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart2e0fef82007-06-17 19:56:36 -0500681 if (vport->port_state < LPFC_VPORT_READY)
682 vport->port_state = LPFC_NS_QRY;
683 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500684 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
685 rsp_size = FC_MAX_NS_RSP;
686 break;
687
688 case SLI_CTNS_RFT_ID:
689 CtReq->CommandResponse.bits.CmdRsp =
690 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500691 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -0500692 CtReq->un.rft.fcpReg = 1;
693 cmpl = lpfc_cmpl_ct_cmd_rft_id;
694 break;
695
James Smart2fb9bd82006-12-02 13:33:57 -0500696 case SLI_CTNS_RFF_ID:
697 CtReq->CommandResponse.bits.CmdRsp =
698 be16_to_cpu(SLI_CTNS_RFF_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500699 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);
James Smart2fb9bd82006-12-02 13:33:57 -0500700 CtReq->un.rff.feature_res = 0;
701 CtReq->un.rff.feature_tgt = 0;
702 CtReq->un.rff.type_code = FC_FCP_DATA;
703 CtReq->un.rff.feature_init = 1;
704 cmpl = lpfc_cmpl_ct_cmd_rff_id;
705 break;
706
dea31012005-04-17 16:05:31 -0500707 case SLI_CTNS_RNN_ID:
708 CtReq->CommandResponse.bits.CmdRsp =
709 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500710 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
711 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -0500712 sizeof (struct lpfc_name));
713 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
714 break;
715
716 case SLI_CTNS_RSNN_NN:
717 CtReq->CommandResponse.bits.CmdRsp =
718 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -0500719 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -0500720 sizeof (struct lpfc_name));
721 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
722 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
723 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
724 break;
725 }
726
James Smart2e0fef82007-06-17 19:56:36 -0500727 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size))
dea31012005-04-17 16:05:31 -0500728 /* On success, The cmpl function will free the buffers */
729 return 0;
730
731 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
732ns_cmd_free_bmp:
733 kfree(bmp);
734ns_cmd_free_mpvirt:
735 lpfc_mbuf_free(phba, mp->virt, mp->phys);
736ns_cmd_free_mp:
737 kfree(mp);
738ns_cmd_exit:
739 return 1;
740}
741
742static void
James Smart2e0fef82007-06-17 19:56:36 -0500743lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
744 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -0500745{
746 struct lpfc_dmabuf *bmp = cmdiocb->context3;
747 struct lpfc_dmabuf *inp = cmdiocb->context1;
748 struct lpfc_dmabuf *outp = cmdiocb->context2;
749 struct lpfc_sli_ct_request *CTrsp = outp->virt;
750 struct lpfc_sli_ct_request *CTcmd = inp->virt;
751 struct lpfc_nodelist *ndlp;
752 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
753 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -0500754 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500755
James Smart2e0fef82007-06-17 19:56:36 -0500756 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -0500757 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
758 /* FDMI rsp failed */
James Smarted957682007-06-17 19:56:37 -0500759 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
760 "%d:0220 FDMI rsp failed Data: x%x\n",
761 phba->brd_no, be16_to_cpu(fdmi_cmd));
dea31012005-04-17 16:05:31 -0500762 }
763
764 switch (be16_to_cpu(fdmi_cmd)) {
765 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -0500766 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -0500767 break;
768
769 case SLI_MGMT_RPA:
770 break;
771
772 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -0500773 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -0500774 break;
775
776 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -0500777 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -0500778 break;
779 }
780
781 lpfc_free_ct_rsp(phba, outp);
782 lpfc_mbuf_free(phba, inp->virt, inp->phys);
783 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
784 kfree(inp);
785 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500786 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500787 return;
788}
James Smart2e0fef82007-06-17 19:56:36 -0500789
dea31012005-04-17 16:05:31 -0500790int
James Smart2e0fef82007-06-17 19:56:36 -0500791lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -0500792{
James Smart2e0fef82007-06-17 19:56:36 -0500793 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500794 struct lpfc_dmabuf *mp, *bmp;
795 struct lpfc_sli_ct_request *CtReq;
796 struct ulp_bde64 *bpl;
797 uint32_t size;
798 REG_HBA *rh;
799 PORT_ENTRY *pe;
800 REG_PORT_ATTRIBUTE *pab;
801 ATTRIBUTE_BLOCK *ab;
802 ATTRIBUTE_ENTRY *ae;
803 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
804 struct lpfc_iocbq *);
805
806
807 /* fill in BDEs for command */
808 /* Allocate buffer for command payload */
809 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
810 if (!mp)
811 goto fdmi_cmd_exit;
812
813 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
814 if (!mp->virt)
815 goto fdmi_cmd_free_mp;
816
817 /* Allocate buffer for Buffer ptr list */
818 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
819 if (!bmp)
820 goto fdmi_cmd_free_mpvirt;
821
822 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
823 if (!bmp->virt)
824 goto fdmi_cmd_free_bmp;
825
826 INIT_LIST_HEAD(&mp->list);
827 INIT_LIST_HEAD(&bmp->list);
828
829 /* FDMI request */
James Smarted957682007-06-17 19:56:37 -0500830 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -0500831 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
832 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -0500833 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -0500834
835 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
836
837 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
838 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
839 CtReq->RevisionId.bits.InId = 0;
840
841 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
842 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
843 size = 0;
844
845 switch (cmdcode) {
846 case SLI_MGMT_RHBA:
847 {
848 lpfc_vpd_t *vp = &phba->vpd;
849 uint32_t i, j, incr;
850 int len;
851
852 CtReq->CommandResponse.bits.CmdRsp =
853 be16_to_cpu(SLI_MGMT_RHBA);
854 CtReq->CommandResponse.bits.Size = 0;
855 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -0500856 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500857 sizeof (struct lpfc_name));
858 /* One entry (port) per adapter */
859 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -0500860 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500861 sizeof (struct lpfc_name));
862
863 /* point to the HBA attribute block */
864 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
865 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
866 ab->EntryCnt = 0;
867
868 /* Point to the beginning of the first HBA attribute
869 entry */
870 /* #1 HBA attribute entry */
871 size += FOURBYTES;
872 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
873 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
874 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
875 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500876 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500877 sizeof (struct lpfc_name));
878 ab->EntryCnt++;
879 size += FOURBYTES + sizeof (struct lpfc_name);
880
881 /* #2 HBA attribute entry */
882 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
883 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
884 strcpy(ae->un.Manufacturer, "Emulex Corporation");
885 len = strlen(ae->un.Manufacturer);
886 len += (len & 3) ? (4 - (len & 3)) : 4;
887 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
888 ab->EntryCnt++;
889 size += FOURBYTES + len;
890
891 /* #3 HBA attribute entry */
892 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
893 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
894 strcpy(ae->un.SerialNumber, phba->SerialNumber);
895 len = strlen(ae->un.SerialNumber);
896 len += (len & 3) ? (4 - (len & 3)) : 4;
897 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
898 ab->EntryCnt++;
899 size += FOURBYTES + len;
900
901 /* #4 HBA attribute entry */
902 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
903 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
904 strcpy(ae->un.Model, phba->ModelName);
905 len = strlen(ae->un.Model);
906 len += (len & 3) ? (4 - (len & 3)) : 4;
907 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
908 ab->EntryCnt++;
909 size += FOURBYTES + len;
910
911 /* #5 HBA attribute entry */
912 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
913 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
914 strcpy(ae->un.ModelDescription, phba->ModelDesc);
915 len = strlen(ae->un.ModelDescription);
916 len += (len & 3) ? (4 - (len & 3)) : 4;
917 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
918 ab->EntryCnt++;
919 size += FOURBYTES + len;
920
921 /* #6 HBA attribute entry */
922 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
923 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
924 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
925 /* Convert JEDEC ID to ascii for hardware version */
926 incr = vp->rev.biuRev;
927 for (i = 0; i < 8; i++) {
928 j = (incr & 0xf);
929 if (j <= 9)
930 ae->un.HardwareVersion[7 - i] =
931 (char)((uint8_t) 0x30 +
932 (uint8_t) j);
933 else
934 ae->un.HardwareVersion[7 - i] =
935 (char)((uint8_t) 0x61 +
936 (uint8_t) (j - 10));
937 incr = (incr >> 4);
938 }
939 ab->EntryCnt++;
940 size += FOURBYTES + 8;
941
942 /* #7 HBA attribute entry */
943 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
944 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
945 strcpy(ae->un.DriverVersion, lpfc_release_version);
946 len = strlen(ae->un.DriverVersion);
947 len += (len & 3) ? (4 - (len & 3)) : 4;
948 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
949 ab->EntryCnt++;
950 size += FOURBYTES + len;
951
952 /* #8 HBA attribute entry */
953 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
954 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
955 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
956 len = strlen(ae->un.OptionROMVersion);
957 len += (len & 3) ? (4 - (len & 3)) : 4;
958 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
959 ab->EntryCnt++;
960 size += FOURBYTES + len;
961
962 /* #9 HBA attribute entry */
963 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
964 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
965 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
966 1);
967 len = strlen(ae->un.FirmwareVersion);
968 len += (len & 3) ? (4 - (len & 3)) : 4;
969 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
970 ab->EntryCnt++;
971 size += FOURBYTES + len;
972
973 /* #10 HBA attribute entry */
974 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
975 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
976 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -0500977 init_utsname()->sysname,
978 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700979 init_utsname()->version);
dea31012005-04-17 16:05:31 -0500980 len = strlen(ae->un.OsNameVersion);
981 len += (len & 3) ? (4 - (len & 3)) : 4;
982 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
983 ab->EntryCnt++;
984 size += FOURBYTES + len;
985
986 /* #11 HBA attribute entry */
987 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
988 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
989 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
990 ae->un.MaxCTPayloadLen = (65 * 4096);
991 ab->EntryCnt++;
992 size += FOURBYTES + 4;
993
994 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
995 /* Total size */
996 size = GID_REQUEST_SZ - 4 + size;
997 }
998 break;
999
1000 case SLI_MGMT_RPA:
1001 {
1002 lpfc_vpd_t *vp;
1003 struct serv_parm *hsp;
1004 int len;
1005
1006 vp = &phba->vpd;
1007
1008 CtReq->CommandResponse.bits.CmdRsp =
1009 be16_to_cpu(SLI_MGMT_RPA);
1010 CtReq->CommandResponse.bits.Size = 0;
1011 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1012 size = sizeof (struct lpfc_name) + FOURBYTES;
1013 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001014 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001015 sizeof (struct lpfc_name));
1016 pab->ab.EntryCnt = 0;
1017
1018 /* #1 Port attribute entry */
1019 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1020 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1021 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1022 ae->un.SupportFC4Types[2] = 1;
1023 ae->un.SupportFC4Types[7] = 1;
1024 pab->ab.EntryCnt++;
1025 size += FOURBYTES + 32;
1026
1027 /* #2 Port attribute entry */
1028 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1029 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1030 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001031
1032 ae->un.SupportSpeed = 0;
1033 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001034 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001035 if (phba->lmt & LMT_8Gb)
1036 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1037 if (phba->lmt & LMT_4Gb)
1038 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1039 if (phba->lmt & LMT_2Gb)
1040 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1041 if (phba->lmt & LMT_1Gb)
1042 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1043
dea31012005-04-17 16:05:31 -05001044 pab->ab.EntryCnt++;
1045 size += FOURBYTES + 4;
1046
1047 /* #3 Port attribute entry */
1048 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1049 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1050 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1051 switch(phba->fc_linkspeed) {
1052 case LA_1GHZ_LINK:
1053 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1054 break;
1055 case LA_2GHZ_LINK:
1056 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1057 break;
1058 case LA_4GHZ_LINK:
1059 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1060 break;
James Smartb87eab32007-04-25 09:53:28 -04001061 case LA_8GHZ_LINK:
1062 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1063 break;
dea31012005-04-17 16:05:31 -05001064 default:
1065 ae->un.PortSpeed =
1066 HBA_PORTSPEED_UNKNOWN;
1067 break;
1068 }
1069 pab->ab.EntryCnt++;
1070 size += FOURBYTES + 4;
1071
1072 /* #4 Port attribute entry */
1073 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1074 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1075 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001076 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001077 ae->un.MaxFrameSize =
1078 (((uint32_t) hsp->cmn.
1079 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1080 bbRcvSizeLsb;
1081 pab->ab.EntryCnt++;
1082 size += FOURBYTES + 4;
1083
1084 /* #5 Port attribute entry */
1085 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1086 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1087 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1088 len = strlen((char *)ae->un.OsDeviceName);
1089 len += (len & 3) ? (4 - (len & 3)) : 4;
1090 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1091 pab->ab.EntryCnt++;
1092 size += FOURBYTES + len;
1093
1094 if (phba->cfg_fdmi_on == 2) {
1095 /* #6 Port attribute entry */
1096 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1097 size);
1098 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1099 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001100 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001101 len = strlen(ae->un.HostName);
1102 len += (len & 3) ? (4 - (len & 3)) : 4;
1103 ae->ad.bits.AttrLen =
1104 be16_to_cpu(FOURBYTES + len);
1105 pab->ab.EntryCnt++;
1106 size += FOURBYTES + len;
1107 }
1108
1109 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1110 /* Total size */
1111 size = GID_REQUEST_SZ - 4 + size;
1112 }
1113 break;
1114
1115 case SLI_MGMT_DHBA:
1116 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1117 CtReq->CommandResponse.bits.Size = 0;
1118 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1119 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001120 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001121 sizeof (struct lpfc_name));
1122 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1123 break;
1124
1125 case SLI_MGMT_DPRT:
1126 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1127 CtReq->CommandResponse.bits.Size = 0;
1128 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1129 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001130 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001131 sizeof (struct lpfc_name));
1132 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1133 break;
1134 }
1135
1136 bpl = (struct ulp_bde64 *) bmp->virt;
1137 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1138 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1139 bpl->tus.f.bdeFlags = 0;
1140 bpl->tus.f.bdeSize = size;
1141 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1142
1143 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1144
James Smart2e0fef82007-06-17 19:56:36 -05001145 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
dea31012005-04-17 16:05:31 -05001146 return 0;
1147
1148 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1149fdmi_cmd_free_bmp:
1150 kfree(bmp);
1151fdmi_cmd_free_mpvirt:
1152 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1153fdmi_cmd_free_mp:
1154 kfree(mp);
1155fdmi_cmd_exit:
1156 /* Issue FDMI request failed */
James Smarted957682007-06-17 19:56:37 -05001157 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -05001158 "%d:0244 Issue FDMI request failed Data: x%x\n",
James Smarted957682007-06-17 19:56:37 -05001159 phba->brd_no, cmdcode);
dea31012005-04-17 16:05:31 -05001160 return 1;
1161}
1162
1163void
1164lpfc_fdmi_tmo(unsigned long ptr)
1165{
James Smart2e0fef82007-06-17 19:56:36 -05001166 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1167 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001168 unsigned long iflag;
1169
James Smart2e0fef82007-06-17 19:56:36 -05001170 spin_lock_irqsave(&vport->work_port_lock, iflag);
1171 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1172 vport->work_port_events |= WORKER_FDMI_TMO;
dea31012005-04-17 16:05:31 -05001173 if (phba->work_wait)
1174 wake_up(phba->work_wait);
1175 }
James Smart2e0fef82007-06-17 19:56:36 -05001176 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05001177}
1178
1179void
James Smart2e0fef82007-06-17 19:56:36 -05001180lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001181{
1182 struct lpfc_nodelist *ndlp;
1183
James Smart2e0fef82007-06-17 19:56:36 -05001184 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001185 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001186 if (init_utsname()->nodename[0] != '\0')
1187 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1188 else
1189 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001190 }
dea31012005-04-17 16:05:31 -05001191 return;
1192}
1193
dea31012005-04-17 16:05:31 -05001194void
James Smart2e0fef82007-06-17 19:56:36 -05001195lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001196{
1197 struct lpfc_sli *psli = &phba->sli;
1198 lpfc_vpd_t *vp = &phba->vpd;
1199 uint32_t b1, b2, b3, b4, i, rev;
1200 char c;
1201 uint32_t *ptr, str[4];
1202 uint8_t *fwname;
1203
1204 if (vp->rev.rBit) {
1205 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1206 rev = vp->rev.sli2FwRev;
1207 else
1208 rev = vp->rev.sli1FwRev;
1209
1210 b1 = (rev & 0x0000f000) >> 12;
1211 b2 = (rev & 0x00000f00) >> 8;
1212 b3 = (rev & 0x000000c0) >> 6;
1213 b4 = (rev & 0x00000030) >> 4;
1214
1215 switch (b4) {
1216 case 0:
1217 c = 'N';
1218 break;
1219 case 1:
1220 c = 'A';
1221 break;
1222 case 2:
1223 c = 'B';
1224 break;
1225 default:
1226 c = 0;
1227 break;
1228 }
1229 b4 = (rev & 0x0000000f);
1230
1231 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1232 fwname = vp->rev.sli2FwName;
1233 else
1234 fwname = vp->rev.sli1FwName;
1235
1236 for (i = 0; i < 16; i++)
1237 if (fwname[i] == 0x20)
1238 fwname[i] = 0;
1239
1240 ptr = (uint32_t*)fwname;
1241
1242 for (i = 0; i < 3; i++)
1243 str[i] = be32_to_cpu(*ptr++);
1244
1245 if (c == 0) {
1246 if (flag)
1247 sprintf(fwrevision, "%d.%d%d (%s)",
1248 b1, b2, b3, (char *)str);
1249 else
1250 sprintf(fwrevision, "%d.%d%d", b1,
1251 b2, b3);
1252 } else {
1253 if (flag)
1254 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1255 b1, b2, b3, c,
1256 b4, (char *)str);
1257 else
1258 sprintf(fwrevision, "%d.%d%d%c%d",
1259 b1, b2, b3, c, b4);
1260 }
1261 } else {
1262 rev = vp->rev.smFwRev;
1263
1264 b1 = (rev & 0xff000000) >> 24;
1265 b2 = (rev & 0x00f00000) >> 20;
1266 b3 = (rev & 0x000f0000) >> 16;
1267 c = (rev & 0x0000ff00) >> 8;
1268 b4 = (rev & 0x000000ff);
1269
1270 if (flag)
1271 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1272 b2, b3, c, b4);
1273 else
1274 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1275 b2, b3, c, b4);
1276 }
1277 return;
1278}