blob: 34a9e3bb2614058c9ca827be246b65539564e0cb [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
62lpfc_ct_unsol_event(struct lpfc_hba * phba,
63 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
64{
65
66 struct lpfc_iocbq *next_piocbq;
67 struct lpfc_dmabuf *pmbuf = NULL;
68 struct lpfc_dmabuf *matp, *next_matp;
69 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
148lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
149{
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 *
163lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
164 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
219lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
220 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{
226
227 struct lpfc_sli *psli = &phba->sli;
228 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 */
233 spin_lock_irq(phba->host->host_lock);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400234 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500235 spin_unlock_irq(phba->host->host_lock);
236
237 if (geniocb == NULL)
238 return 1;
dea31012005-04-17 16:05:31 -0500239
240 icmd = &geniocb->iocb;
241 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
242 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
243 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
244 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
245 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
246
247 if (usr_flg)
248 geniocb->context3 = NULL;
249 else
250 geniocb->context3 = (uint8_t *) bmp;
251
252 /* Save for completion so we can release these resources */
253 geniocb->context1 = (uint8_t *) inp;
254 geniocb->context2 = (uint8_t *) outp;
255
256 /* Fill in payload, bp points to frame payload */
257 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
258
259 /* Fill in rest of iocb */
260 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
261 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
262 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
263 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
264
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500265 if (!tmo) {
266 /* FC spec states we need 3 * ratov for CT requests */
267 tmo = (3 * phba->fc_ratov);
268 }
dea31012005-04-17 16:05:31 -0500269 icmd->ulpTimeout = tmo;
270 icmd->ulpBdeCount = 1;
271 icmd->ulpLe = 1;
272 icmd->ulpClass = CLASS3;
273 icmd->ulpContext = ndlp->nlp_rpi;
274
275 /* Issue GEN REQ IOCB for NPORT <did> */
276 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
277 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
278 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
279 icmd->ulpIoTag, phba->hba_state);
280 geniocb->iocb_cmpl = cmpl;
281 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
282 spin_lock_irq(phba->host->host_lock);
283 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
James Bottomley604a3e32005-10-29 10:28:33 -0500284 lpfc_sli_release_iocbq(phba, geniocb);
dea31012005-04-17 16:05:31 -0500285 spin_unlock_irq(phba->host->host_lock);
286 return 1;
287 }
288 spin_unlock_irq(phba->host->host_lock);
289
290 return 0;
291}
292
293static int
294lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
295 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
296 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
297 struct lpfc_iocbq *),
298 uint32_t rsp_size)
299{
300 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
301 struct lpfc_dmabuf *outmp;
302 int cnt = 0, status;
303 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
304 CommandResponse.bits.CmdRsp;
305
306 bpl++; /* Skip past ct request */
307
308 /* Put buffer(s) for ct rsp in bpl */
309 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
310 if (!outmp)
311 return -ENOMEM;
312
313 status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
314 cnt+1, 0);
315 if (status) {
316 lpfc_free_ct_rsp(phba, outmp);
317 return -ENOMEM;
318 }
319 return 0;
320}
321
322static int
323lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
324{
325 struct lpfc_sli_ct_request *Response =
326 (struct lpfc_sli_ct_request *) mp->virt;
327 struct lpfc_nodelist *ndlp = NULL;
328 struct lpfc_dmabuf *mlast, *next_mp;
329 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
330 uint32_t Did;
331 uint32_t CTentry;
332 int Cnt;
333 struct list_head head;
334
335 lpfc_set_disctmo(phba);
336
dea31012005-04-17 16:05:31 -0500337
338 list_add_tail(&head, &mp->list);
339 list_for_each_entry_safe(mp, next_mp, &head, list) {
340 mlast = mp;
341
James Smart7054a602007-04-25 09:52:34 -0400342 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
343
dea31012005-04-17 16:05:31 -0500344 Size -= Cnt;
345
James Smart1dcb58e2007-04-25 09:51:30 -0400346 if (!ctptr) {
dea31012005-04-17 16:05:31 -0500347 ctptr = (uint32_t *) mlast->virt;
James Smart1dcb58e2007-04-25 09:51:30 -0400348 } else
dea31012005-04-17 16:05:31 -0500349 Cnt -= 16; /* subtract length of CT header */
350
351 /* Loop through entire NameServer list of DIDs */
James Smart7054a602007-04-25 09:52:34 -0400352 while (Cnt >= sizeof (uint32_t)) {
dea31012005-04-17 16:05:31 -0500353
354 /* Get next DID from NameServer List */
355 CTentry = *ctptr++;
356 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
357
358 ndlp = NULL;
359 if (Did != phba->fc_myDID) {
360 /* Check for rscn processing or not */
361 ndlp = lpfc_setup_disc_node(phba, Did);
362 }
363 /* Mark all node table entries that are in the
364 Nameserver */
365 if (ndlp) {
366 /* NameServer Rsp */
367 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
368 "%d:0238 Process x%x NameServer"
369 " Rsp Data: x%x x%x x%x\n",
370 phba->brd_no,
371 Did, ndlp->nlp_flag,
372 phba->fc_flag,
373 phba->fc_rscn_id_cnt);
374 } else {
375 /* NameServer Rsp */
376 lpfc_printf_log(phba,
377 KERN_INFO,
378 LOG_DISCOVERY,
379 "%d:0239 Skip x%x NameServer "
380 "Rsp Data: x%x x%x x%x\n",
381 phba->brd_no,
382 Did, Size, phba->fc_flag,
383 phba->fc_rscn_id_cnt);
384 }
385
386 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
387 goto nsout1;
388 Cnt -= sizeof (uint32_t);
389 }
390 ctptr = NULL;
391
392 }
393
394nsout1:
395 list_del(&head);
396
Jamie Wellnitz50eba242006-02-28 19:25:38 -0500397 /*
398 * The driver has cycled through all Nports in the RSCN payload.
399 * Complete the handling by cleaning up and marking the
400 * current driver state.
401 */
dea31012005-04-17 16:05:31 -0500402 if (phba->hba_state == LPFC_HBA_READY) {
403 lpfc_els_flush_rscn(phba);
404 spin_lock_irq(phba->host->host_lock);
405 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
406 spin_unlock_irq(phba->host->host_lock);
407 }
408 return 0;
409}
410
411
412
413
414static void
415lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
416 struct lpfc_iocbq * rspiocb)
417{
418 IOCB_t *irsp;
419 struct lpfc_sli *psli;
420 struct lpfc_dmabuf *bmp;
421 struct lpfc_dmabuf *inp;
422 struct lpfc_dmabuf *outp;
423 struct lpfc_nodelist *ndlp;
424 struct lpfc_sli_ct_request *CTrsp;
425
426 psli = &phba->sli;
427 /* we pass cmdiocb to state machine which needs rspiocb as well */
428 cmdiocb->context_un.rsp_iocb = rspiocb;
429
430 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
431 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
432 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
433
434 irsp = &rspiocb->iocb;
435 if (irsp->ulpStatus) {
436 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
437 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
438 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
439 goto out;
440 }
441
442 /* Check for retry */
443 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
444 phba->fc_ns_retry++;
445 /* CT command is being retried */
James Smart685f0bf2007-04-25 09:53:08 -0400446 ndlp = lpfc_findnode_did(phba, NameServer_DID);
447 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -0500448 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
449 0) {
450 goto out;
451 }
452 }
453 }
454 } else {
455 /* Good status, continue checking */
456 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
457 if (CTrsp->CommandResponse.bits.CmdRsp ==
458 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500459 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -0400460 "%d:0208 NameServer Rsp "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500461 "Data: x%x\n",
462 phba->brd_no,
463 phba->fc_flag);
dea31012005-04-17 16:05:31 -0500464 lpfc_ns_rsp(phba, outp,
465 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
466 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
467 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
468 /* NameServer Rsp Error */
469 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
470 "%d:0240 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,
476 phba->fc_flag);
477 } else {
478 /* NameServer Rsp Error */
479 lpfc_printf_log(phba,
480 KERN_INFO,
481 LOG_DISCOVERY,
482 "%d:0241 NameServer Rsp Error "
483 "Data: x%x x%x x%x x%x\n",
484 phba->brd_no,
485 CTrsp->CommandResponse.bits.CmdRsp,
486 (uint32_t) CTrsp->ReasonCode,
487 (uint32_t) CTrsp->Explanation,
488 phba->fc_flag);
489 }
490 }
491 /* Link up / RSCN discovery */
492 lpfc_disc_start(phba);
493out:
494 lpfc_free_ct_rsp(phba, outp);
495 lpfc_mbuf_free(phba, inp->virt, inp->phys);
496 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
497 kfree(inp);
498 kfree(bmp);
499 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500500 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500501 spin_unlock_irq(phba->host->host_lock);
502 return;
503}
504
505static void
506lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
507 struct lpfc_iocbq * rspiocb)
508{
509 struct lpfc_sli *psli;
510 struct lpfc_dmabuf *bmp;
511 struct lpfc_dmabuf *inp;
512 struct lpfc_dmabuf *outp;
513 IOCB_t *irsp;
514 struct lpfc_sli_ct_request *CTrsp;
515
516 psli = &phba->sli;
517 /* we pass cmdiocb to state machine which needs rspiocb as well */
518 cmdiocb->context_un.rsp_iocb = rspiocb;
519
520 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
521 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
522 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
523 irsp = &rspiocb->iocb;
524
525 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
526
527 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
528 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
529 "%d:0209 RFT request completes ulpStatus x%x "
530 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
531 CTrsp->CommandResponse.bits.CmdRsp);
532
533 lpfc_free_ct_rsp(phba, outp);
534 lpfc_mbuf_free(phba, inp->virt, inp->phys);
535 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
536 kfree(inp);
537 kfree(bmp);
538 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500539 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500540 spin_unlock_irq(phba->host->host_lock);
541 return;
542}
543
544static void
545lpfc_cmpl_ct_cmd_rnn_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
552static void
553lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
554 struct lpfc_iocbq * rspiocb)
555{
556 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
557 return;
558}
559
James Smart2fb9bd82006-12-02 13:33:57 -0500560static void
561lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
562 struct lpfc_iocbq * rspiocb)
563{
564 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
565 return;
566}
567
dea31012005-04-17 16:05:31 -0500568void
569lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
570{
571 char fwrev[16];
572
573 lpfc_decode_firmware_rev(phba, fwrev, 0);
574
James Smartdca94792006-08-01 07:34:08 -0400575 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
576 fwrev, lpfc_release_version);
577 return;
dea31012005-04-17 16:05:31 -0500578}
579
580/*
581 * lpfc_ns_cmd
582 * Description:
583 * Issue Cmd to NameServer
584 * SLI_CTNS_GID_FT
585 * LI_CTNS_RFT_ID
586 */
587int
588lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
589{
590 struct lpfc_dmabuf *mp, *bmp;
591 struct lpfc_sli_ct_request *CtReq;
592 struct ulp_bde64 *bpl;
593 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
594 struct lpfc_iocbq *) = NULL;
595 uint32_t rsp_size = 1024;
596
597 /* fill in BDEs for command */
598 /* Allocate buffer for command payload */
599 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
600 if (!mp)
601 goto ns_cmd_exit;
602
603 INIT_LIST_HEAD(&mp->list);
604 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
605 if (!mp->virt)
606 goto ns_cmd_free_mp;
607
608 /* Allocate buffer for Buffer ptr list */
609 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
610 if (!bmp)
611 goto ns_cmd_free_mpvirt;
612
613 INIT_LIST_HEAD(&bmp->list);
614 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
615 if (!bmp->virt)
616 goto ns_cmd_free_bmp;
617
618 /* NameServer Req */
619 lpfc_printf_log(phba,
620 KERN_INFO,
621 LOG_DISCOVERY,
622 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
623 phba->brd_no, cmdcode, phba->fc_flag,
624 phba->fc_rscn_id_cnt);
625
626 bpl = (struct ulp_bde64 *) bmp->virt;
627 memset(bpl, 0, sizeof(struct ulp_bde64));
628 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
629 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
630 bpl->tus.f.bdeFlags = 0;
631 if (cmdcode == SLI_CTNS_GID_FT)
632 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
633 else if (cmdcode == SLI_CTNS_RFT_ID)
634 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
635 else if (cmdcode == SLI_CTNS_RNN_ID)
636 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
637 else if (cmdcode == SLI_CTNS_RSNN_NN)
638 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
James Smart2fb9bd82006-12-02 13:33:57 -0500639 else if (cmdcode == SLI_CTNS_RFF_ID)
640 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea31012005-04-17 16:05:31 -0500641 else
642 bpl->tus.f.bdeSize = 0;
643 bpl->tus.w = le32_to_cpu(bpl->tus.w);
644
645 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
646 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
647 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
648 CtReq->RevisionId.bits.InId = 0;
649 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
650 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
651 CtReq->CommandResponse.bits.Size = 0;
652 switch (cmdcode) {
653 case SLI_CTNS_GID_FT:
654 CtReq->CommandResponse.bits.CmdRsp =
655 be16_to_cpu(SLI_CTNS_GID_FT);
656 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
657 if (phba->hba_state < LPFC_HBA_READY)
658 phba->hba_state = LPFC_NS_QRY;
659 lpfc_set_disctmo(phba);
660 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
661 rsp_size = FC_MAX_NS_RSP;
662 break;
663
664 case SLI_CTNS_RFT_ID:
665 CtReq->CommandResponse.bits.CmdRsp =
666 be16_to_cpu(SLI_CTNS_RFT_ID);
667 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
668 CtReq->un.rft.fcpReg = 1;
669 cmpl = lpfc_cmpl_ct_cmd_rft_id;
670 break;
671
James Smart2fb9bd82006-12-02 13:33:57 -0500672 case SLI_CTNS_RFF_ID:
673 CtReq->CommandResponse.bits.CmdRsp =
674 be16_to_cpu(SLI_CTNS_RFF_ID);
675 CtReq->un.rff.PortId = be32_to_cpu(phba->fc_myDID);
676 CtReq->un.rff.feature_res = 0;
677 CtReq->un.rff.feature_tgt = 0;
678 CtReq->un.rff.type_code = FC_FCP_DATA;
679 CtReq->un.rff.feature_init = 1;
680 cmpl = lpfc_cmpl_ct_cmd_rff_id;
681 break;
682
dea31012005-04-17 16:05:31 -0500683 case SLI_CTNS_RNN_ID:
684 CtReq->CommandResponse.bits.CmdRsp =
685 be16_to_cpu(SLI_CTNS_RNN_ID);
686 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
687 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
688 sizeof (struct lpfc_name));
689 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
690 break;
691
692 case SLI_CTNS_RSNN_NN:
693 CtReq->CommandResponse.bits.CmdRsp =
694 be16_to_cpu(SLI_CTNS_RSNN_NN);
695 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
696 sizeof (struct lpfc_name));
697 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
698 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
699 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
700 break;
701 }
702
703 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
704 /* On success, The cmpl function will free the buffers */
705 return 0;
706
707 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
708ns_cmd_free_bmp:
709 kfree(bmp);
710ns_cmd_free_mpvirt:
711 lpfc_mbuf_free(phba, mp->virt, mp->phys);
712ns_cmd_free_mp:
713 kfree(mp);
714ns_cmd_exit:
715 return 1;
716}
717
718static void
719lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
720 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
721{
722 struct lpfc_dmabuf *bmp = cmdiocb->context3;
723 struct lpfc_dmabuf *inp = cmdiocb->context1;
724 struct lpfc_dmabuf *outp = cmdiocb->context2;
725 struct lpfc_sli_ct_request *CTrsp = outp->virt;
726 struct lpfc_sli_ct_request *CTcmd = inp->virt;
727 struct lpfc_nodelist *ndlp;
728 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
729 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
730
James Smart685f0bf2007-04-25 09:53:08 -0400731 ndlp = lpfc_findnode_did(phba, FDMI_DID);
dea31012005-04-17 16:05:31 -0500732 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
733 /* FDMI rsp failed */
734 lpfc_printf_log(phba,
735 KERN_INFO,
736 LOG_DISCOVERY,
737 "%d:0220 FDMI rsp failed Data: x%x\n",
738 phba->brd_no,
739 be16_to_cpu(fdmi_cmd));
740 }
741
742 switch (be16_to_cpu(fdmi_cmd)) {
743 case SLI_MGMT_RHBA:
744 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
745 break;
746
747 case SLI_MGMT_RPA:
748 break;
749
750 case SLI_MGMT_DHBA:
751 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
752 break;
753
754 case SLI_MGMT_DPRT:
755 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
756 break;
757 }
758
759 lpfc_free_ct_rsp(phba, outp);
760 lpfc_mbuf_free(phba, inp->virt, inp->phys);
761 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
762 kfree(inp);
763 kfree(bmp);
764 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500765 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500766 spin_unlock_irq(phba->host->host_lock);
767 return;
768}
769int
770lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
771{
772 struct lpfc_dmabuf *mp, *bmp;
773 struct lpfc_sli_ct_request *CtReq;
774 struct ulp_bde64 *bpl;
775 uint32_t size;
776 REG_HBA *rh;
777 PORT_ENTRY *pe;
778 REG_PORT_ATTRIBUTE *pab;
779 ATTRIBUTE_BLOCK *ab;
780 ATTRIBUTE_ENTRY *ae;
781 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
782 struct lpfc_iocbq *);
783
784
785 /* fill in BDEs for command */
786 /* Allocate buffer for command payload */
787 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
788 if (!mp)
789 goto fdmi_cmd_exit;
790
791 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
792 if (!mp->virt)
793 goto fdmi_cmd_free_mp;
794
795 /* Allocate buffer for Buffer ptr list */
796 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
797 if (!bmp)
798 goto fdmi_cmd_free_mpvirt;
799
800 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
801 if (!bmp->virt)
802 goto fdmi_cmd_free_bmp;
803
804 INIT_LIST_HEAD(&mp->list);
805 INIT_LIST_HEAD(&bmp->list);
806
807 /* FDMI request */
808 lpfc_printf_log(phba,
809 KERN_INFO,
810 LOG_DISCOVERY,
811 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
812 phba->brd_no,
813 phba->fc_flag, phba->hba_state, cmdcode);
814
815 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
816
817 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
818 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
819 CtReq->RevisionId.bits.InId = 0;
820
821 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
822 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
823 size = 0;
824
825 switch (cmdcode) {
826 case SLI_MGMT_RHBA:
827 {
828 lpfc_vpd_t *vp = &phba->vpd;
829 uint32_t i, j, incr;
830 int len;
831
832 CtReq->CommandResponse.bits.CmdRsp =
833 be16_to_cpu(SLI_MGMT_RHBA);
834 CtReq->CommandResponse.bits.Size = 0;
835 rh = (REG_HBA *) & CtReq->un.PortID;
836 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
837 sizeof (struct lpfc_name));
838 /* One entry (port) per adapter */
839 rh->rpl.EntryCnt = be32_to_cpu(1);
840 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
841 sizeof (struct lpfc_name));
842
843 /* point to the HBA attribute block */
844 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
845 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
846 ab->EntryCnt = 0;
847
848 /* Point to the beginning of the first HBA attribute
849 entry */
850 /* #1 HBA attribute entry */
851 size += FOURBYTES;
852 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
853 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
854 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
855 + sizeof (struct lpfc_name));
856 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
857 sizeof (struct lpfc_name));
858 ab->EntryCnt++;
859 size += FOURBYTES + sizeof (struct lpfc_name);
860
861 /* #2 HBA attribute entry */
862 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
863 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
864 strcpy(ae->un.Manufacturer, "Emulex Corporation");
865 len = strlen(ae->un.Manufacturer);
866 len += (len & 3) ? (4 - (len & 3)) : 4;
867 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
868 ab->EntryCnt++;
869 size += FOURBYTES + len;
870
871 /* #3 HBA attribute entry */
872 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
873 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
874 strcpy(ae->un.SerialNumber, phba->SerialNumber);
875 len = strlen(ae->un.SerialNumber);
876 len += (len & 3) ? (4 - (len & 3)) : 4;
877 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
878 ab->EntryCnt++;
879 size += FOURBYTES + len;
880
881 /* #4 HBA attribute entry */
882 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
883 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
884 strcpy(ae->un.Model, phba->ModelName);
885 len = strlen(ae->un.Model);
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 /* #5 HBA attribute entry */
892 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
893 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
894 strcpy(ae->un.ModelDescription, phba->ModelDesc);
895 len = strlen(ae->un.ModelDescription);
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 /* #6 HBA attribute entry */
902 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
903 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
904 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
905 /* Convert JEDEC ID to ascii for hardware version */
906 incr = vp->rev.biuRev;
907 for (i = 0; i < 8; i++) {
908 j = (incr & 0xf);
909 if (j <= 9)
910 ae->un.HardwareVersion[7 - i] =
911 (char)((uint8_t) 0x30 +
912 (uint8_t) j);
913 else
914 ae->un.HardwareVersion[7 - i] =
915 (char)((uint8_t) 0x61 +
916 (uint8_t) (j - 10));
917 incr = (incr >> 4);
918 }
919 ab->EntryCnt++;
920 size += FOURBYTES + 8;
921
922 /* #7 HBA attribute entry */
923 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
924 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
925 strcpy(ae->un.DriverVersion, lpfc_release_version);
926 len = strlen(ae->un.DriverVersion);
927 len += (len & 3) ? (4 - (len & 3)) : 4;
928 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
929 ab->EntryCnt++;
930 size += FOURBYTES + len;
931
932 /* #8 HBA attribute entry */
933 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
934 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
935 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
936 len = strlen(ae->un.OptionROMVersion);
937 len += (len & 3) ? (4 - (len & 3)) : 4;
938 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
939 ab->EntryCnt++;
940 size += FOURBYTES + len;
941
942 /* #9 HBA attribute entry */
943 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
944 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
945 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
946 1);
947 len = strlen(ae->un.FirmwareVersion);
948 len += (len & 3) ? (4 - (len & 3)) : 4;
949 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
950 ab->EntryCnt++;
951 size += FOURBYTES + len;
952
953 /* #10 HBA attribute entry */
954 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
955 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
956 sprintf(ae->un.OsNameVersion, "%s %s %s",
James Smart2fb9bd82006-12-02 13:33:57 -0500957 init_utsname()->sysname,
958 init_utsname()->release,
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700959 init_utsname()->version);
dea31012005-04-17 16:05:31 -0500960 len = strlen(ae->un.OsNameVersion);
961 len += (len & 3) ? (4 - (len & 3)) : 4;
962 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
963 ab->EntryCnt++;
964 size += FOURBYTES + len;
965
966 /* #11 HBA attribute entry */
967 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
968 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
969 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
970 ae->un.MaxCTPayloadLen = (65 * 4096);
971 ab->EntryCnt++;
972 size += FOURBYTES + 4;
973
974 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
975 /* Total size */
976 size = GID_REQUEST_SZ - 4 + size;
977 }
978 break;
979
980 case SLI_MGMT_RPA:
981 {
982 lpfc_vpd_t *vp;
983 struct serv_parm *hsp;
984 int len;
985
986 vp = &phba->vpd;
987
988 CtReq->CommandResponse.bits.CmdRsp =
989 be16_to_cpu(SLI_MGMT_RPA);
990 CtReq->CommandResponse.bits.Size = 0;
991 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
992 size = sizeof (struct lpfc_name) + FOURBYTES;
993 memcpy((uint8_t *) & pab->PortName,
994 (uint8_t *) & phba->fc_sparam.portName,
995 sizeof (struct lpfc_name));
996 pab->ab.EntryCnt = 0;
997
998 /* #1 Port attribute entry */
999 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1000 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1001 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1002 ae->un.SupportFC4Types[2] = 1;
1003 ae->un.SupportFC4Types[7] = 1;
1004 pab->ab.EntryCnt++;
1005 size += FOURBYTES + 32;
1006
1007 /* #2 Port attribute entry */
1008 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1009 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1010 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001011
1012 ae->un.SupportSpeed = 0;
1013 if (phba->lmt & LMT_10Gb)
dea31012005-04-17 16:05:31 -05001014 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001015 if (phba->lmt & LMT_8Gb)
1016 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1017 if (phba->lmt & LMT_4Gb)
1018 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1019 if (phba->lmt & LMT_2Gb)
1020 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1021 if (phba->lmt & LMT_1Gb)
1022 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1023
dea31012005-04-17 16:05:31 -05001024 pab->ab.EntryCnt++;
1025 size += FOURBYTES + 4;
1026
1027 /* #3 Port attribute entry */
1028 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1029 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1030 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1031 switch(phba->fc_linkspeed) {
1032 case LA_1GHZ_LINK:
1033 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1034 break;
1035 case LA_2GHZ_LINK:
1036 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1037 break;
1038 case LA_4GHZ_LINK:
1039 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1040 break;
James Smartb87eab32007-04-25 09:53:28 -04001041 case LA_8GHZ_LINK:
1042 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1043 break;
dea31012005-04-17 16:05:31 -05001044 default:
1045 ae->un.PortSpeed =
1046 HBA_PORTSPEED_UNKNOWN;
1047 break;
1048 }
1049 pab->ab.EntryCnt++;
1050 size += FOURBYTES + 4;
1051
1052 /* #4 Port attribute entry */
1053 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1054 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1055 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1056 hsp = (struct serv_parm *) & phba->fc_sparam;
1057 ae->un.MaxFrameSize =
1058 (((uint32_t) hsp->cmn.
1059 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1060 bbRcvSizeLsb;
1061 pab->ab.EntryCnt++;
1062 size += FOURBYTES + 4;
1063
1064 /* #5 Port attribute entry */
1065 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1066 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1067 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1068 len = strlen((char *)ae->un.OsDeviceName);
1069 len += (len & 3) ? (4 - (len & 3)) : 4;
1070 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1071 pab->ab.EntryCnt++;
1072 size += FOURBYTES + len;
1073
1074 if (phba->cfg_fdmi_on == 2) {
1075 /* #6 Port attribute entry */
1076 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1077 size);
1078 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1079 sprintf(ae->un.HostName, "%s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001080 init_utsname()->nodename);
dea31012005-04-17 16:05:31 -05001081 len = strlen(ae->un.HostName);
1082 len += (len & 3) ? (4 - (len & 3)) : 4;
1083 ae->ad.bits.AttrLen =
1084 be16_to_cpu(FOURBYTES + len);
1085 pab->ab.EntryCnt++;
1086 size += FOURBYTES + len;
1087 }
1088
1089 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1090 /* Total size */
1091 size = GID_REQUEST_SZ - 4 + size;
1092 }
1093 break;
1094
1095 case SLI_MGMT_DHBA:
1096 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1097 CtReq->CommandResponse.bits.Size = 0;
1098 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1099 memcpy((uint8_t *) & pe->PortName,
1100 (uint8_t *) & phba->fc_sparam.portName,
1101 sizeof (struct lpfc_name));
1102 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1103 break;
1104
1105 case SLI_MGMT_DPRT:
1106 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1107 CtReq->CommandResponse.bits.Size = 0;
1108 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1109 memcpy((uint8_t *) & pe->PortName,
1110 (uint8_t *) & phba->fc_sparam.portName,
1111 sizeof (struct lpfc_name));
1112 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1113 break;
1114 }
1115
1116 bpl = (struct ulp_bde64 *) bmp->virt;
1117 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1118 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1119 bpl->tus.f.bdeFlags = 0;
1120 bpl->tus.f.bdeSize = size;
1121 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1122
1123 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1124
1125 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1126 return 0;
1127
1128 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1129fdmi_cmd_free_bmp:
1130 kfree(bmp);
1131fdmi_cmd_free_mpvirt:
1132 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1133fdmi_cmd_free_mp:
1134 kfree(mp);
1135fdmi_cmd_exit:
1136 /* Issue FDMI request failed */
1137 lpfc_printf_log(phba,
1138 KERN_INFO,
1139 LOG_DISCOVERY,
1140 "%d:0244 Issue FDMI request failed Data: x%x\n",
1141 phba->brd_no,
1142 cmdcode);
1143 return 1;
1144}
1145
1146void
1147lpfc_fdmi_tmo(unsigned long ptr)
1148{
1149 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1150 unsigned long iflag;
1151
1152 spin_lock_irqsave(phba->host->host_lock, iflag);
1153 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1154 phba->work_hba_events |= WORKER_FDMI_TMO;
1155 if (phba->work_wait)
1156 wake_up(phba->work_wait);
1157 }
1158 spin_unlock_irqrestore(phba->host->host_lock,iflag);
1159}
1160
1161void
1162lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1163{
1164 struct lpfc_nodelist *ndlp;
1165
James Smart685f0bf2007-04-25 09:53:08 -04001166 ndlp = lpfc_findnode_did(phba, FDMI_DID);
dea31012005-04-17 16:05:31 -05001167 if (ndlp) {
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07001168 if (init_utsname()->nodename[0] != '\0') {
dea31012005-04-17 16:05:31 -05001169 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1170 } else {
1171 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1172 }
1173 }
dea31012005-04-17 16:05:31 -05001174 return;
1175}
1176
1177
1178void
1179lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1180{
1181 struct lpfc_sli *psli = &phba->sli;
1182 lpfc_vpd_t *vp = &phba->vpd;
1183 uint32_t b1, b2, b3, b4, i, rev;
1184 char c;
1185 uint32_t *ptr, str[4];
1186 uint8_t *fwname;
1187
1188 if (vp->rev.rBit) {
1189 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1190 rev = vp->rev.sli2FwRev;
1191 else
1192 rev = vp->rev.sli1FwRev;
1193
1194 b1 = (rev & 0x0000f000) >> 12;
1195 b2 = (rev & 0x00000f00) >> 8;
1196 b3 = (rev & 0x000000c0) >> 6;
1197 b4 = (rev & 0x00000030) >> 4;
1198
1199 switch (b4) {
1200 case 0:
1201 c = 'N';
1202 break;
1203 case 1:
1204 c = 'A';
1205 break;
1206 case 2:
1207 c = 'B';
1208 break;
1209 default:
1210 c = 0;
1211 break;
1212 }
1213 b4 = (rev & 0x0000000f);
1214
1215 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1216 fwname = vp->rev.sli2FwName;
1217 else
1218 fwname = vp->rev.sli1FwName;
1219
1220 for (i = 0; i < 16; i++)
1221 if (fwname[i] == 0x20)
1222 fwname[i] = 0;
1223
1224 ptr = (uint32_t*)fwname;
1225
1226 for (i = 0; i < 3; i++)
1227 str[i] = be32_to_cpu(*ptr++);
1228
1229 if (c == 0) {
1230 if (flag)
1231 sprintf(fwrevision, "%d.%d%d (%s)",
1232 b1, b2, b3, (char *)str);
1233 else
1234 sprintf(fwrevision, "%d.%d%d", b1,
1235 b2, b3);
1236 } else {
1237 if (flag)
1238 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1239 b1, b2, b3, c,
1240 b4, (char *)str);
1241 else
1242 sprintf(fwrevision, "%d.%d%d%c%d",
1243 b1, b2, b3, c, b4);
1244 }
1245 } else {
1246 rev = vp->rev.smFwRev;
1247
1248 b1 = (rev & 0xff000000) >> 24;
1249 b2 = (rev & 0x00f00000) >> 20;
1250 b3 = (rev & 0x000f0000) >> 16;
1251 c = (rev & 0x0000ff00) >> 8;
1252 b4 = (rev & 0x000000ff);
1253
1254 if (flag)
1255 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1256 b2, b3, c, b4);
1257 else
1258 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1259 b2, b3, c, b4);
1260 }
1261 return;
1262}