blob: dc25a53524c47e4dc6ee23e06e7329c768b20574 [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 */
61void
James Smart2e0fef82007-06-17 19:56:36 -050062lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
63 struct lpfc_iocbq *piocbq)
dea31012005-04-17 16:05:31 -050064{
65
66 struct lpfc_iocbq *next_piocbq;
67 struct lpfc_dmabuf *pmbuf = NULL;
James Smart2e0fef82007-06-17 19:56:36 -050068 struct lpfc_dmabuf *matp = NULL, *next_matp;
dea31012005-04-17 16:05:31 -050069 uint32_t ctx = 0, size = 0, cnt = 0;
70 IOCB_t *icmd = &piocbq->iocb;
71 IOCB_t *save_icmd = icmd;
72 int i, go_exit = 0;
73 struct list_head head;
74
75 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
76 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
77 /* Not enough posted buffers; Try posting more buffers */
78 phba->fc_stat.NoRcvBuf++;
79 lpfc_post_buffer(phba, pring, 0, 1);
80 return;
81 }
82
83 /* If there are no BDEs associated with this IOCB,
84 * there is nothing to do.
85 */
86 if (icmd->ulpBdeCount == 0)
87 return;
88
89 INIT_LIST_HEAD(&head);
90 list_add_tail(&head, &piocbq->list);
91
92 list_for_each_entry_safe(piocbq, next_piocbq, &head, list) {
93 icmd = &piocbq->iocb;
94 if (ctx == 0)
95 ctx = (uint32_t) (icmd->ulpContext);
96 if (icmd->ulpBdeCount == 0)
97 continue;
98
99 for (i = 0; i < icmd->ulpBdeCount; i++) {
100 matp = lpfc_sli_ringpostbuf_get(phba, pring,
101 getPaddr(icmd->un.
102 cont64[i].
103 addrHigh,
104 icmd->un.
105 cont64[i].
106 addrLow));
107 if (!matp) {
108 /* Insert lpfc log message here */
109 lpfc_post_buffer(phba, pring, cnt, 1);
110 go_exit = 1;
111 goto ct_unsol_event_exit_piocbq;
112 }
113
114 /* Typically for Unsolicited CT requests */
115 if (!pmbuf) {
116 pmbuf = matp;
117 INIT_LIST_HEAD(&pmbuf->list);
118 } else
119 list_add_tail(&matp->list, &pmbuf->list);
120
121 size += icmd->un.cont64[i].tus.f.bdeSize;
122 cnt++;
123 }
124
125 icmd->ulpBdeCount = 0;
126 }
127
128 lpfc_post_buffer(phba, pring, cnt, 1);
129 if (save_icmd->ulpStatus) {
130 go_exit = 1;
131 }
132
133ct_unsol_event_exit_piocbq:
James Smart8f6d98d2006-08-01 07:34:00 -0400134 list_del(&head);
dea31012005-04-17 16:05:31 -0500135 if (pmbuf) {
136 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
137 lpfc_mbuf_free(phba, matp->virt, matp->phys);
138 list_del(&matp->list);
139 kfree(matp);
140 }
141 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
142 kfree(pmbuf);
143 }
144 return;
145}
146
147static void
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea31012005-04-17 16:05:31 -0500149{
150 struct lpfc_dmabuf *mlast, *next_mlast;
151
152 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
153 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
154 list_del(&mlast->list);
155 kfree(mlast);
156 }
157 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
158 kfree(mlist);
159 return;
160}
161
162static struct lpfc_dmabuf *
James Smart2e0fef82007-06-17 19:56:36 -0500163lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea31012005-04-17 16:05:31 -0500164 uint32_t size, int *entries)
165{
166 struct lpfc_dmabuf *mlist = NULL;
167 struct lpfc_dmabuf *mp;
168 int cnt, i = 0;
169
170 /* We get chucks of FCELSSIZE */
171 cnt = size > FCELSSIZE ? FCELSSIZE: size;
172
173 while (size) {
174 /* Allocate buffer for rsp payload */
175 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
176 if (!mp) {
177 if (mlist)
178 lpfc_free_ct_rsp(phba, mlist);
179 return NULL;
180 }
181
182 INIT_LIST_HEAD(&mp->list);
183
184 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
185 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
186 else
187 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
188
189 if (!mp->virt) {
190 kfree(mp);
Eric Sesterhenn0b3a82d2006-10-10 14:41:43 -0700191 if (mlist)
192 lpfc_free_ct_rsp(phba, mlist);
dea31012005-04-17 16:05:31 -0500193 return NULL;
194 }
195
196 /* Queue it to a linked list */
197 if (!mlist)
198 mlist = mp;
199 else
200 list_add_tail(&mp->list, &mlist->list);
201
202 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
203 /* build buffer ptr list for IOCB */
204 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
205 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
206 bpl->tus.f.bdeSize = (uint16_t) cnt;
207 bpl->tus.w = le32_to_cpu(bpl->tus.w);
208 bpl++;
209
210 i++;
211 size -= cnt;
212 }
213
214 *entries = i;
215 return mlist;
216}
217
218static int
James Smart2e0fef82007-06-17 19:56:36 -0500219lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea31012005-04-17 16:05:31 -0500220 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
221 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
222 struct lpfc_iocbq *),
223 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
224 uint32_t tmo)
225{
James Smart2e0fef82007-06-17 19:56:36 -0500226 struct lpfc_hba *phba = vport->phba;
227 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500228 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500229 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400230 struct lpfc_iocbq *geniocb;
dea31012005-04-17 16:05:31 -0500231
232 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400233 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500234
235 if (geniocb == NULL)
236 return 1;
dea31012005-04-17 16:05:31 -0500237
238 icmd = &geniocb->iocb;
239 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
240 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
241 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
242 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
243 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
244
245 if (usr_flg)
246 geniocb->context3 = NULL;
247 else
248 geniocb->context3 = (uint8_t *) bmp;
249
250 /* Save for completion so we can release these resources */
251 geniocb->context1 = (uint8_t *) inp;
252 geniocb->context2 = (uint8_t *) outp;
253
254 /* Fill in payload, bp points to frame payload */
255 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
256
257 /* Fill in rest of iocb */
258 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
259 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
260 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
261 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
262
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500263 if (!tmo) {
264 /* FC spec states we need 3 * ratov for CT requests */
265 tmo = (3 * phba->fc_ratov);
266 }
dea31012005-04-17 16:05:31 -0500267 icmd->ulpTimeout = tmo;
268 icmd->ulpBdeCount = 1;
269 icmd->ulpLe = 1;
270 icmd->ulpClass = CLASS3;
271 icmd->ulpContext = ndlp->nlp_rpi;
272
273 /* Issue GEN REQ IOCB for NPORT <did> */
274 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
275 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
276 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
James Smart2e0fef82007-06-17 19:56:36 -0500277 icmd->ulpIoTag, vport->port_state);
dea31012005-04-17 16:05:31 -0500278 geniocb->iocb_cmpl = cmpl;
279 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
James Smart2e0fef82007-06-17 19:56:36 -0500280 geniocb->vport = vport;
dea31012005-04-17 16:05:31 -0500281 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500282 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500283 return 1;
284 }
dea31012005-04-17 16:05:31 -0500285
286 return 0;
287}
288
289static int
James Smart2e0fef82007-06-17 19:56:36 -0500290lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea31012005-04-17 16:05:31 -0500291 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
292 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
293 struct lpfc_iocbq *),
294 uint32_t rsp_size)
295{
James Smart2e0fef82007-06-17 19:56:36 -0500296 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500297 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
298 struct lpfc_dmabuf *outmp;
299 int cnt = 0, status;
300 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
301 CommandResponse.bits.CmdRsp;
302
303 bpl++; /* Skip past ct request */
304
305 /* Put buffer(s) for ct rsp in bpl */
306 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
307 if (!outmp)
308 return -ENOMEM;
309
James Smart2e0fef82007-06-17 19:56:36 -0500310 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
dea31012005-04-17 16:05:31 -0500311 cnt+1, 0);
312 if (status) {
313 lpfc_free_ct_rsp(phba, outmp);
314 return -ENOMEM;
315 }
316 return 0;
317}
318
319static int
James Smart2e0fef82007-06-17 19:56:36 -0500320lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea31012005-04-17 16:05:31 -0500321{
James Smart2e0fef82007-06-17 19:56:36 -0500322 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
323 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500324 struct lpfc_sli_ct_request *Response =
325 (struct lpfc_sli_ct_request *) mp->virt;
326 struct lpfc_nodelist *ndlp = NULL;
327 struct lpfc_dmabuf *mlast, *next_mp;
328 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
James Smart2e0fef82007-06-17 19:56:36 -0500329 uint32_t Did, CTentry;
dea31012005-04-17 16:05:31 -0500330 int Cnt;
331 struct list_head head;
332
James Smart2e0fef82007-06-17 19:56:36 -0500333 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500334
dea31012005-04-17 16:05:31 -0500335
336 list_add_tail(&head, &mp->list);
337 list_for_each_entry_safe(mp, next_mp, &head, list) {
338 mlast = mp;
339
James Smart7054a602007-04-25 09:52:34 -0400340 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
341
dea31012005-04-17 16:05:31 -0500342 Size -= Cnt;
343
James Smart1dcb58e2007-04-25 09:51:30 -0400344 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500345 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400346 } else
dea31012005-04-17 16:05:31 -0500347 Cnt -= 16; /* subtract length of CT header */
348
349 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400350 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500351 /* Get next DID from NameServer List */
352 CTentry = *ctptr++;
353 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
dea31012005-04-17 16:05:31 -0500354 ndlp = NULL;
James Smart2e0fef82007-06-17 19:56:36 -0500355 /* Check for rscn processing or not */
356 if (Did != vport->fc_myDID)
357 ndlp = lpfc_setup_disc_node(vport, Did);
dea31012005-04-17 16:05:31 -0500358 if (ndlp) {
dea31012005-04-17 16:05:31 -0500359 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
360 "%d:0238 Process x%x NameServer"
361 " Rsp Data: x%x x%x x%x\n",
362 phba->brd_no,
363 Did, ndlp->nlp_flag,
James Smart2e0fef82007-06-17 19:56:36 -0500364 vport->fc_flag,
365 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -0500366 } else {
dea31012005-04-17 16:05:31 -0500367 lpfc_printf_log(phba,
368 KERN_INFO,
369 LOG_DISCOVERY,
370 "%d:0239 Skip x%x NameServer "
371 "Rsp Data: x%x x%x x%x\n",
372 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -0500373 Did, Size, vport->fc_flag,
374 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -0500375 }
dea31012005-04-17 16:05:31 -0500376 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
377 goto nsout1;
378 Cnt -= sizeof (uint32_t);
379 }
380 ctptr = NULL;
381
382 }
383
384nsout1:
385 list_del(&head);
386
Jamie Wellnitz50eba242006-02-28 19:25:38 -0500387 /*
James Smart2e0fef82007-06-17 19:56:36 -0500388 * The driver has cycled through all Nports in the RSCN payload.
389 * Complete the handling by cleaning up and marking the
390 * current driver state.
391 */
392 if (vport->port_state == LPFC_VPORT_READY) {
393 lpfc_els_flush_rscn(vport);
394 spin_lock_irq(shost->host_lock);
395 vport->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
396 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500397 }
398 return 0;
399}
400
401
402
403
404static void
James Smart2e0fef82007-06-17 19:56:36 -0500405lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
406 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500407{
James Smart2e0fef82007-06-17 19:56:36 -0500408 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500409 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500410 struct lpfc_dmabuf *bmp;
411 struct lpfc_dmabuf *inp;
412 struct lpfc_dmabuf *outp;
413 struct lpfc_nodelist *ndlp;
414 struct lpfc_sli_ct_request *CTrsp;
James Smart2e0fef82007-06-17 19:56:36 -0500415 int rc;
dea31012005-04-17 16:05:31 -0500416
dea31012005-04-17 16:05:31 -0500417 /* we pass cmdiocb to state machine which needs rspiocb as well */
418 cmdiocb->context_un.rsp_iocb = rspiocb;
419
420 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
421 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
422 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
423
424 irsp = &rspiocb->iocb;
425 if (irsp->ulpStatus) {
426 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
427 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
James Smart2e0fef82007-06-17 19:56:36 -0500428 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
dea31012005-04-17 16:05:31 -0500429 goto out;
dea31012005-04-17 16:05:31 -0500430
431 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500432 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
433 vport->fc_ns_retry++;
dea31012005-04-17 16:05:31 -0500434 /* CT command is being retried */
James Smart2e0fef82007-06-17 19:56:36 -0500435 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -0400436 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -0500437 rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
438 if (rc == 0)
dea31012005-04-17 16:05:31 -0500439 goto out;
440 }
441 }
dea31012005-04-17 16:05:31 -0500442 } else {
443 /* Good status, continue checking */
444 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
445 if (CTrsp->CommandResponse.bits.CmdRsp ==
446 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500447 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -0400448 "%d:0208 NameServer Rsp "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500449 "Data: x%x\n",
450 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -0500451 vport->fc_flag);
452 lpfc_ns_rsp(vport, outp,
dea31012005-04-17 16:05:31 -0500453 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
454 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
455 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
456 /* NameServer Rsp Error */
457 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
458 "%d:0240 NameServer Rsp Error "
459 "Data: x%x x%x x%x x%x\n",
460 phba->brd_no,
461 CTrsp->CommandResponse.bits.CmdRsp,
462 (uint32_t) CTrsp->ReasonCode,
463 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500464 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500465 } else {
466 /* NameServer Rsp Error */
467 lpfc_printf_log(phba,
468 KERN_INFO,
469 LOG_DISCOVERY,
470 "%d:0241 NameServer Rsp Error "
471 "Data: x%x x%x x%x x%x\n",
472 phba->brd_no,
473 CTrsp->CommandResponse.bits.CmdRsp,
474 (uint32_t) CTrsp->ReasonCode,
475 (uint32_t) CTrsp->Explanation,
James Smart2e0fef82007-06-17 19:56:36 -0500476 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500477 }
478 }
479 /* Link up / RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500480 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500481out:
482 lpfc_free_ct_rsp(phba, outp);
483 lpfc_mbuf_free(phba, inp->virt, inp->phys);
484 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
485 kfree(inp);
486 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500487 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500488 return;
489}
490
491static void
James Smart2e0fef82007-06-17 19:56:36 -0500492lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
493 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500494{
dea31012005-04-17 16:05:31 -0500495 struct lpfc_dmabuf *bmp;
496 struct lpfc_dmabuf *inp;
497 struct lpfc_dmabuf *outp;
498 IOCB_t *irsp;
499 struct lpfc_sli_ct_request *CTrsp;
500
dea31012005-04-17 16:05:31 -0500501 /* we pass cmdiocb to state machine which needs rspiocb as well */
502 cmdiocb->context_un.rsp_iocb = rspiocb;
503
504 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
505 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
506 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
507 irsp = &rspiocb->iocb;
508
509 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
510
511 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
512 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
513 "%d:0209 RFT request completes ulpStatus x%x "
James Smart2e0fef82007-06-17 19:56:36 -0500514 "CmdRsp x%x, Context x%x, Tag x%x\n",
515 phba->brd_no, irsp->ulpStatus,
516 CTrsp->CommandResponse.bits.CmdRsp,
517 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea31012005-04-17 16:05:31 -0500518
519 lpfc_free_ct_rsp(phba, outp);
520 lpfc_mbuf_free(phba, inp->virt, inp->phys);
521 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
522 kfree(inp);
523 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500524 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500525 return;
526}
527
528static void
James Smart2e0fef82007-06-17 19:56:36 -0500529lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
530 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500531{
532 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
533 return;
534}
535
536static void
James Smart2e0fef82007-06-17 19:56:36 -0500537lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
538 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500539{
540 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
541 return;
542}
543
James Smart2fb9bd82006-12-02 13:33:57 -0500544static void
545lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
546 struct lpfc_iocbq * rspiocb)
547{
548 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
549 return;
550}
551
dea31012005-04-17 16:05:31 -0500552void
James Smart2e0fef82007-06-17 19:56:36 -0500553lpfc_get_hba_sym_node_name(struct lpfc_hba *phba, uint8_t *symbp)
dea31012005-04-17 16:05:31 -0500554{
555 char fwrev[16];
556
557 lpfc_decode_firmware_rev(phba, fwrev, 0);
558
James Smartdca94792006-08-01 07:34:08 -0400559 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
560 fwrev, lpfc_release_version);
561 return;
dea31012005-04-17 16:05:31 -0500562}
563
564/*
565 * lpfc_ns_cmd
566 * Description:
567 * Issue Cmd to NameServer
568 * SLI_CTNS_GID_FT
569 * LI_CTNS_RFT_ID
570 */
571int
James Smart2e0fef82007-06-17 19:56:36 -0500572lpfc_ns_cmd(struct lpfc_vport *vport, struct lpfc_nodelist * ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -0500573{
James Smart2e0fef82007-06-17 19:56:36 -0500574 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500575 struct lpfc_dmabuf *mp, *bmp;
576 struct lpfc_sli_ct_request *CtReq;
577 struct ulp_bde64 *bpl;
578 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
579 struct lpfc_iocbq *) = NULL;
580 uint32_t rsp_size = 1024;
581
582 /* fill in BDEs for command */
583 /* Allocate buffer for command payload */
584 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
585 if (!mp)
586 goto ns_cmd_exit;
587
588 INIT_LIST_HEAD(&mp->list);
589 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
590 if (!mp->virt)
591 goto ns_cmd_free_mp;
592
593 /* Allocate buffer for Buffer ptr list */
594 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
595 if (!bmp)
596 goto ns_cmd_free_mpvirt;
597
598 INIT_LIST_HEAD(&bmp->list);
599 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
600 if (!bmp->virt)
601 goto ns_cmd_free_bmp;
602
603 /* NameServer Req */
604 lpfc_printf_log(phba,
605 KERN_INFO,
606 LOG_DISCOVERY,
607 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500608 phba->brd_no, cmdcode, vport->fc_flag,
609 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -0500610
611 bpl = (struct ulp_bde64 *) bmp->virt;
612 memset(bpl, 0, sizeof(struct ulp_bde64));
613 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
614 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
615 bpl->tus.f.bdeFlags = 0;
616 if (cmdcode == SLI_CTNS_GID_FT)
617 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
618 else if (cmdcode == SLI_CTNS_RFT_ID)
619 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
620 else if (cmdcode == SLI_CTNS_RNN_ID)
621 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
622 else if (cmdcode == SLI_CTNS_RSNN_NN)
623 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -0500624 else if (cmdcode == SLI_CTNS_RFF_ID)
625 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -0500626 else
627 bpl->tus.f.bdeSize = 0;
628 bpl->tus.w = le32_to_cpu(bpl->tus.w);
629
630 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
631 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
632 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
633 CtReq->RevisionId.bits.InId = 0;
634 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
635 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
636 CtReq->CommandResponse.bits.Size = 0;
637 switch (cmdcode) {
638 case SLI_CTNS_GID_FT:
639 CtReq->CommandResponse.bits.CmdRsp =
640 be16_to_cpu(SLI_CTNS_GID_FT);
641 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
James Smart2e0fef82007-06-17 19:56:36 -0500642 if (vport->port_state < LPFC_VPORT_READY)
643 vport->port_state = LPFC_NS_QRY;
644 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500645 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
646 rsp_size = FC_MAX_NS_RSP;
647 break;
648
649 case SLI_CTNS_RFT_ID:
650 CtReq->CommandResponse.bits.CmdRsp =
651 be16_to_cpu(SLI_CTNS_RFT_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500652 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -0500653 CtReq->un.rft.fcpReg = 1;
654 cmpl = lpfc_cmpl_ct_cmd_rft_id;
655 break;
656
James Smart2fb9bd82006-12-02 13:33:57 -0500657 case SLI_CTNS_RFF_ID:
658 CtReq->CommandResponse.bits.CmdRsp =
659 be16_to_cpu(SLI_CTNS_RFF_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500660 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);
James Smart2fb9bd82006-12-02 13:33:57 -0500661 CtReq->un.rff.feature_res = 0;
662 CtReq->un.rff.feature_tgt = 0;
663 CtReq->un.rff.type_code = FC_FCP_DATA;
664 CtReq->un.rff.feature_init = 1;
665 cmpl = lpfc_cmpl_ct_cmd_rff_id;
666 break;
667
dea31012005-04-17 16:05:31 -0500668 case SLI_CTNS_RNN_ID:
669 CtReq->CommandResponse.bits.CmdRsp =
670 be16_to_cpu(SLI_CTNS_RNN_ID);
James Smart2e0fef82007-06-17 19:56:36 -0500671 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
672 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -0500673 sizeof (struct lpfc_name));
674 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
675 break;
676
677 case SLI_CTNS_RSNN_NN:
678 CtReq->CommandResponse.bits.CmdRsp =
679 be16_to_cpu(SLI_CTNS_RSNN_NN);
James Smart2e0fef82007-06-17 19:56:36 -0500680 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -0500681 sizeof (struct lpfc_name));
682 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
683 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
684 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
685 break;
686 }
687
James Smart2e0fef82007-06-17 19:56:36 -0500688 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size))
dea31012005-04-17 16:05:31 -0500689 /* On success, The cmpl function will free the buffers */
690 return 0;
691
692 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
693ns_cmd_free_bmp:
694 kfree(bmp);
695ns_cmd_free_mpvirt:
696 lpfc_mbuf_free(phba, mp->virt, mp->phys);
697ns_cmd_free_mp:
698 kfree(mp);
699ns_cmd_exit:
700 return 1;
701}
702
703static void
James Smart2e0fef82007-06-17 19:56:36 -0500704lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
705 struct lpfc_iocbq * rspiocb)
dea31012005-04-17 16:05:31 -0500706{
707 struct lpfc_dmabuf *bmp = cmdiocb->context3;
708 struct lpfc_dmabuf *inp = cmdiocb->context1;
709 struct lpfc_dmabuf *outp = cmdiocb->context2;
710 struct lpfc_sli_ct_request *CTrsp = outp->virt;
711 struct lpfc_sli_ct_request *CTcmd = inp->virt;
712 struct lpfc_nodelist *ndlp;
713 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
714 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
James Smart2e0fef82007-06-17 19:56:36 -0500715 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -0500716
James Smart2e0fef82007-06-17 19:56:36 -0500717 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -0500718 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
719 /* FDMI rsp failed */
720 lpfc_printf_log(phba,
721 KERN_INFO,
722 LOG_DISCOVERY,
723 "%d:0220 FDMI rsp failed Data: x%x\n",
724 phba->brd_no,
725 be16_to_cpu(fdmi_cmd));
726 }
727
728 switch (be16_to_cpu(fdmi_cmd)) {
729 case SLI_MGMT_RHBA:
James Smart2e0fef82007-06-17 19:56:36 -0500730 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea31012005-04-17 16:05:31 -0500731 break;
732
733 case SLI_MGMT_RPA:
734 break;
735
736 case SLI_MGMT_DHBA:
James Smart2e0fef82007-06-17 19:56:36 -0500737 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea31012005-04-17 16:05:31 -0500738 break;
739
740 case SLI_MGMT_DPRT:
James Smart2e0fef82007-06-17 19:56:36 -0500741 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea31012005-04-17 16:05:31 -0500742 break;
743 }
744
745 lpfc_free_ct_rsp(phba, outp);
746 lpfc_mbuf_free(phba, inp->virt, inp->phys);
747 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
748 kfree(inp);
749 kfree(bmp);
James Bottomley604a3e32005-10-29 10:28:33 -0500750 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500751 return;
752}
James Smart2e0fef82007-06-17 19:56:36 -0500753
dea31012005-04-17 16:05:31 -0500754int
James Smart2e0fef82007-06-17 19:56:36 -0500755lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea31012005-04-17 16:05:31 -0500756{
James Smart2e0fef82007-06-17 19:56:36 -0500757 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500758 struct lpfc_dmabuf *mp, *bmp;
759 struct lpfc_sli_ct_request *CtReq;
760 struct ulp_bde64 *bpl;
761 uint32_t size;
762 REG_HBA *rh;
763 PORT_ENTRY *pe;
764 REG_PORT_ATTRIBUTE *pab;
765 ATTRIBUTE_BLOCK *ab;
766 ATTRIBUTE_ENTRY *ae;
767 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
768 struct lpfc_iocbq *);
769
770
771 /* fill in BDEs for command */
772 /* Allocate buffer for command payload */
773 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
774 if (!mp)
775 goto fdmi_cmd_exit;
776
777 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
778 if (!mp->virt)
779 goto fdmi_cmd_free_mp;
780
781 /* Allocate buffer for Buffer ptr list */
782 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
783 if (!bmp)
784 goto fdmi_cmd_free_mpvirt;
785
786 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
787 if (!bmp->virt)
788 goto fdmi_cmd_free_bmp;
789
790 INIT_LIST_HEAD(&mp->list);
791 INIT_LIST_HEAD(&bmp->list);
792
793 /* FDMI request */
794 lpfc_printf_log(phba,
795 KERN_INFO,
796 LOG_DISCOVERY,
797 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
798 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -0500799 vport->fc_flag, vport->port_state, cmdcode);
dea31012005-04-17 16:05:31 -0500800
801 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
802
803 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
804 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
805 CtReq->RevisionId.bits.InId = 0;
806
807 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
808 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
809 size = 0;
810
811 switch (cmdcode) {
812 case SLI_MGMT_RHBA:
813 {
814 lpfc_vpd_t *vp = &phba->vpd;
815 uint32_t i, j, incr;
816 int len;
817
818 CtReq->CommandResponse.bits.CmdRsp =
819 be16_to_cpu(SLI_MGMT_RHBA);
820 CtReq->CommandResponse.bits.Size = 0;
821 rh = (REG_HBA *) & CtReq->un.PortID;
James Smart2e0fef82007-06-17 19:56:36 -0500822 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500823 sizeof (struct lpfc_name));
824 /* One entry (port) per adapter */
825 rh->rpl.EntryCnt = be32_to_cpu(1);
James Smart2e0fef82007-06-17 19:56:36 -0500826 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500827 sizeof (struct lpfc_name));
828
829 /* point to the HBA attribute block */
830 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
831 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
832 ab->EntryCnt = 0;
833
834 /* Point to the beginning of the first HBA attribute
835 entry */
836 /* #1 HBA attribute entry */
837 size += FOURBYTES;
838 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
839 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
840 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
841 + sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500842 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500843 sizeof (struct lpfc_name));
844 ab->EntryCnt++;
845 size += FOURBYTES + sizeof (struct lpfc_name);
846
847 /* #2 HBA attribute entry */
848 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
849 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
850 strcpy(ae->un.Manufacturer, "Emulex Corporation");
851 len = strlen(ae->un.Manufacturer);
852 len += (len & 3) ? (4 - (len & 3)) : 4;
853 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
854 ab->EntryCnt++;
855 size += FOURBYTES + len;
856
857 /* #3 HBA attribute entry */
858 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
859 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
860 strcpy(ae->un.SerialNumber, phba->SerialNumber);
861 len = strlen(ae->un.SerialNumber);
862 len += (len & 3) ? (4 - (len & 3)) : 4;
863 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
864 ab->EntryCnt++;
865 size += FOURBYTES + len;
866
867 /* #4 HBA attribute entry */
868 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
869 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
870 strcpy(ae->un.Model, phba->ModelName);
871 len = strlen(ae->un.Model);
872 len += (len & 3) ? (4 - (len & 3)) : 4;
873 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
874 ab->EntryCnt++;
875 size += FOURBYTES + len;
876
877 /* #5 HBA attribute entry */
878 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
879 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
880 strcpy(ae->un.ModelDescription, phba->ModelDesc);
881 len = strlen(ae->un.ModelDescription);
882 len += (len & 3) ? (4 - (len & 3)) : 4;
883 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
884 ab->EntryCnt++;
885 size += FOURBYTES + len;
886
887 /* #6 HBA attribute entry */
888 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
889 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
890 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
891 /* Convert JEDEC ID to ascii for hardware version */
892 incr = vp->rev.biuRev;
893 for (i = 0; i < 8; i++) {
894 j = (incr & 0xf);
895 if (j <= 9)
896 ae->un.HardwareVersion[7 - i] =
897 (char)((uint8_t) 0x30 +
898 (uint8_t) j);
899 else
900 ae->un.HardwareVersion[7 - i] =
901 (char)((uint8_t) 0x61 +
902 (uint8_t) (j - 10));
903 incr = (incr >> 4);
904 }
905 ab->EntryCnt++;
906 size += FOURBYTES + 8;
907
908 /* #7 HBA attribute entry */
909 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
910 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
911 strcpy(ae->un.DriverVersion, lpfc_release_version);
912 len = strlen(ae->un.DriverVersion);
913 len += (len & 3) ? (4 - (len & 3)) : 4;
914 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
915 ab->EntryCnt++;
916 size += FOURBYTES + len;
917
918 /* #8 HBA attribute entry */
919 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
920 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
921 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
922 len = strlen(ae->un.OptionROMVersion);
923 len += (len & 3) ? (4 - (len & 3)) : 4;
924 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
925 ab->EntryCnt++;
926 size += FOURBYTES + len;
927
928 /* #9 HBA attribute entry */
929 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
930 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
931 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
932 1);
933 len = strlen(ae->un.FirmwareVersion);
934 len += (len & 3) ? (4 - (len & 3)) : 4;
935 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
936 ab->EntryCnt++;
937 size += FOURBYTES + len;
938
939 /* #10 HBA attribute entry */
940 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
941 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
942 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -0500943 init_utsname()->sysname,
944 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700945 init_utsname()->version);
dea31012005-04-17 16:05:31 -0500946 len = strlen(ae->un.OsNameVersion);
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 /* #11 HBA attribute entry */
953 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
954 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
955 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
956 ae->un.MaxCTPayloadLen = (65 * 4096);
957 ab->EntryCnt++;
958 size += FOURBYTES + 4;
959
960 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
961 /* Total size */
962 size = GID_REQUEST_SZ - 4 + size;
963 }
964 break;
965
966 case SLI_MGMT_RPA:
967 {
968 lpfc_vpd_t *vp;
969 struct serv_parm *hsp;
970 int len;
971
972 vp = &phba->vpd;
973
974 CtReq->CommandResponse.bits.CmdRsp =
975 be16_to_cpu(SLI_MGMT_RPA);
976 CtReq->CommandResponse.bits.Size = 0;
977 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
978 size = sizeof (struct lpfc_name) + FOURBYTES;
979 memcpy((uint8_t *) & pab->PortName,
James Smart2e0fef82007-06-17 19:56:36 -0500980 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500981 sizeof (struct lpfc_name));
982 pab->ab.EntryCnt = 0;
983
984 /* #1 Port attribute entry */
985 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
986 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
987 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
988 ae->un.SupportFC4Types[2] = 1;
989 ae->un.SupportFC4Types[7] = 1;
990 pab->ab.EntryCnt++;
991 size += FOURBYTES + 32;
992
993 /* #2 Port attribute entry */
994 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
995 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
996 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500997
998 ae->un.SupportSpeed = 0;
999 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001000 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001001 if (phba->lmt & LMT_8Gb)
1002 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1003 if (phba->lmt & LMT_4Gb)
1004 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1005 if (phba->lmt & LMT_2Gb)
1006 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1007 if (phba->lmt & LMT_1Gb)
1008 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1009
dea31012005-04-17 16:05:31 -05001010 pab->ab.EntryCnt++;
1011 size += FOURBYTES + 4;
1012
1013 /* #3 Port attribute entry */
1014 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1015 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1016 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1017 switch(phba->fc_linkspeed) {
1018 case LA_1GHZ_LINK:
1019 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1020 break;
1021 case LA_2GHZ_LINK:
1022 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1023 break;
1024 case LA_4GHZ_LINK:
1025 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1026 break;
James Smartb87eab32007-04-25 09:53:28 -04001027 case LA_8GHZ_LINK:
1028 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1029 break;
dea31012005-04-17 16:05:31 -05001030 default:
1031 ae->un.PortSpeed =
1032 HBA_PORTSPEED_UNKNOWN;
1033 break;
1034 }
1035 pab->ab.EntryCnt++;
1036 size += FOURBYTES + 4;
1037
1038 /* #4 Port attribute entry */
1039 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1040 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1041 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
James Smart2e0fef82007-06-17 19:56:36 -05001042 hsp = (struct serv_parm *) & vport->fc_sparam;
dea31012005-04-17 16:05:31 -05001043 ae->un.MaxFrameSize =
1044 (((uint32_t) hsp->cmn.
1045 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1046 bbRcvSizeLsb;
1047 pab->ab.EntryCnt++;
1048 size += FOURBYTES + 4;
1049
1050 /* #5 Port attribute entry */
1051 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1052 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1053 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1054 len = strlen((char *)ae->un.OsDeviceName);
1055 len += (len & 3) ? (4 - (len & 3)) : 4;
1056 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1057 pab->ab.EntryCnt++;
1058 size += FOURBYTES + len;
1059
1060 if (phba->cfg_fdmi_on == 2) {
1061 /* #6 Port attribute entry */
1062 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1063 size);
1064 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1065 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001066 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001067 len = strlen(ae->un.HostName);
1068 len += (len & 3) ? (4 - (len & 3)) : 4;
1069 ae->ad.bits.AttrLen =
1070 be16_to_cpu(FOURBYTES + len);
1071 pab->ab.EntryCnt++;
1072 size += FOURBYTES + len;
1073 }
1074
1075 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1076 /* Total size */
1077 size = GID_REQUEST_SZ - 4 + size;
1078 }
1079 break;
1080
1081 case SLI_MGMT_DHBA:
1082 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1083 CtReq->CommandResponse.bits.Size = 0;
1084 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1085 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001086 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001087 sizeof (struct lpfc_name));
1088 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1089 break;
1090
1091 case SLI_MGMT_DPRT:
1092 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1093 CtReq->CommandResponse.bits.Size = 0;
1094 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1095 memcpy((uint8_t *) & pe->PortName,
James Smart2e0fef82007-06-17 19:56:36 -05001096 (uint8_t *) & vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -05001097 sizeof (struct lpfc_name));
1098 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1099 break;
1100 }
1101
1102 bpl = (struct ulp_bde64 *) bmp->virt;
1103 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1104 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1105 bpl->tus.f.bdeFlags = 0;
1106 bpl->tus.f.bdeSize = size;
1107 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1108
1109 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1110
James Smart2e0fef82007-06-17 19:56:36 -05001111 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
dea31012005-04-17 16:05:31 -05001112 return 0;
1113
1114 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1115fdmi_cmd_free_bmp:
1116 kfree(bmp);
1117fdmi_cmd_free_mpvirt:
1118 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1119fdmi_cmd_free_mp:
1120 kfree(mp);
1121fdmi_cmd_exit:
1122 /* Issue FDMI request failed */
1123 lpfc_printf_log(phba,
1124 KERN_INFO,
1125 LOG_DISCOVERY,
1126 "%d:0244 Issue FDMI request failed Data: x%x\n",
1127 phba->brd_no,
1128 cmdcode);
1129 return 1;
1130}
1131
1132void
1133lpfc_fdmi_tmo(unsigned long ptr)
1134{
James Smart2e0fef82007-06-17 19:56:36 -05001135 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1136 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001137 unsigned long iflag;
1138
James Smart2e0fef82007-06-17 19:56:36 -05001139 spin_lock_irqsave(&vport->work_port_lock, iflag);
1140 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1141 vport->work_port_events |= WORKER_FDMI_TMO;
dea31012005-04-17 16:05:31 -05001142 if (phba->work_wait)
1143 wake_up(phba->work_wait);
1144 }
James Smart2e0fef82007-06-17 19:56:36 -05001145 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05001146}
1147
1148void
James Smart2e0fef82007-06-17 19:56:36 -05001149lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001150{
1151 struct lpfc_nodelist *ndlp;
1152
James Smart2e0fef82007-06-17 19:56:36 -05001153 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea31012005-04-17 16:05:31 -05001154 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001155 if (init_utsname()->nodename[0] != '\0')
1156 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1157 else
1158 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05001159 }
dea31012005-04-17 16:05:31 -05001160 return;
1161}
1162
dea31012005-04-17 16:05:31 -05001163void
James Smart2e0fef82007-06-17 19:56:36 -05001164lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea31012005-04-17 16:05:31 -05001165{
1166 struct lpfc_sli *psli = &phba->sli;
1167 lpfc_vpd_t *vp = &phba->vpd;
1168 uint32_t b1, b2, b3, b4, i, rev;
1169 char c;
1170 uint32_t *ptr, str[4];
1171 uint8_t *fwname;
1172
1173 if (vp->rev.rBit) {
1174 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1175 rev = vp->rev.sli2FwRev;
1176 else
1177 rev = vp->rev.sli1FwRev;
1178
1179 b1 = (rev & 0x0000f000) >> 12;
1180 b2 = (rev & 0x00000f00) >> 8;
1181 b3 = (rev & 0x000000c0) >> 6;
1182 b4 = (rev & 0x00000030) >> 4;
1183
1184 switch (b4) {
1185 case 0:
1186 c = 'N';
1187 break;
1188 case 1:
1189 c = 'A';
1190 break;
1191 case 2:
1192 c = 'B';
1193 break;
1194 default:
1195 c = 0;
1196 break;
1197 }
1198 b4 = (rev & 0x0000000f);
1199
1200 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1201 fwname = vp->rev.sli2FwName;
1202 else
1203 fwname = vp->rev.sli1FwName;
1204
1205 for (i = 0; i < 16; i++)
1206 if (fwname[i] == 0x20)
1207 fwname[i] = 0;
1208
1209 ptr = (uint32_t*)fwname;
1210
1211 for (i = 0; i < 3; i++)
1212 str[i] = be32_to_cpu(*ptr++);
1213
1214 if (c == 0) {
1215 if (flag)
1216 sprintf(fwrevision, "%d.%d%d (%s)",
1217 b1, b2, b3, (char *)str);
1218 else
1219 sprintf(fwrevision, "%d.%d%d", b1,
1220 b2, b3);
1221 } else {
1222 if (flag)
1223 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1224 b1, b2, b3, c,
1225 b4, (char *)str);
1226 else
1227 sprintf(fwrevision, "%d.%d%d%c%d",
1228 b1, b2, b3, c, b4);
1229 }
1230 } else {
1231 rev = vp->rev.smFwRev;
1232
1233 b1 = (rev & 0xff000000) >> 24;
1234 b2 = (rev & 0x00f00000) >> 20;
1235 b3 = (rev & 0x000f0000) >> 16;
1236 c = (rev & 0x0000ff00) >> 8;
1237 b4 = (rev & 0x000000ff);
1238
1239 if (flag)
1240 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1241 b2, b3, c, b4);
1242 else
1243 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1244 b2, b3, c, b4);
1245 }
1246 return;
1247}