blob: 0c982bbc4c77a6d9325d7dc300ea60b4c0f2bec8 [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. *
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004 * Copyright (C) 2004-2006 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:
134 if (pmbuf) {
135 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
136 lpfc_mbuf_free(phba, matp->virt, matp->phys);
137 list_del(&matp->list);
138 kfree(matp);
139 }
140 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
141 kfree(pmbuf);
142 }
143 return;
144}
145
146static void
147lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
148{
149 struct lpfc_dmabuf *mlast, *next_mlast;
150
151 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
152 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
153 list_del(&mlast->list);
154 kfree(mlast);
155 }
156 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
157 kfree(mlist);
158 return;
159}
160
161static struct lpfc_dmabuf *
162lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
163 uint32_t size, int *entries)
164{
165 struct lpfc_dmabuf *mlist = NULL;
166 struct lpfc_dmabuf *mp;
167 int cnt, i = 0;
168
169 /* We get chucks of FCELSSIZE */
170 cnt = size > FCELSSIZE ? FCELSSIZE: size;
171
172 while (size) {
173 /* Allocate buffer for rsp payload */
174 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
175 if (!mp) {
176 if (mlist)
177 lpfc_free_ct_rsp(phba, mlist);
178 return NULL;
179 }
180
181 INIT_LIST_HEAD(&mp->list);
182
183 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
184 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
185 else
186 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
187
188 if (!mp->virt) {
189 kfree(mp);
190 lpfc_free_ct_rsp(phba, mlist);
191 return NULL;
192 }
193
194 /* Queue it to a linked list */
195 if (!mlist)
196 mlist = mp;
197 else
198 list_add_tail(&mp->list, &mlist->list);
199
200 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
201 /* build buffer ptr list for IOCB */
202 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
203 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
204 bpl->tus.f.bdeSize = (uint16_t) cnt;
205 bpl->tus.w = le32_to_cpu(bpl->tus.w);
206 bpl++;
207
208 i++;
209 size -= cnt;
210 }
211
212 *entries = i;
213 return mlist;
214}
215
216static int
217lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
218 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
219 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
220 struct lpfc_iocbq *),
221 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
222 uint32_t tmo)
223{
224
225 struct lpfc_sli *psli = &phba->sli;
226 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -0500227 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400228 struct lpfc_iocbq *geniocb;
dea31012005-04-17 16:05:31 -0500229
230 /* Allocate buffer for command iocb */
231 spin_lock_irq(phba->host->host_lock);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400232 geniocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500233 spin_unlock_irq(phba->host->host_lock);
234
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],
277 icmd->ulpIoTag, phba->hba_state);
278 geniocb->iocb_cmpl = cmpl;
279 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
280 spin_lock_irq(phba->host->host_lock);
281 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 spin_unlock_irq(phba->host->host_lock);
284 return 1;
285 }
286 spin_unlock_irq(phba->host->host_lock);
287
288 return 0;
289}
290
291static int
292lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
293 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
294 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
295 struct lpfc_iocbq *),
296 uint32_t rsp_size)
297{
298 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
299 struct lpfc_dmabuf *outmp;
300 int cnt = 0, status;
301 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
302 CommandResponse.bits.CmdRsp;
303
304 bpl++; /* Skip past ct request */
305
306 /* Put buffer(s) for ct rsp in bpl */
307 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
308 if (!outmp)
309 return -ENOMEM;
310
311 status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
312 cnt+1, 0);
313 if (status) {
314 lpfc_free_ct_rsp(phba, outmp);
315 return -ENOMEM;
316 }
317 return 0;
318}
319
320static int
321lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
322{
323 struct lpfc_sli_ct_request *Response =
324 (struct lpfc_sli_ct_request *) mp->virt;
325 struct lpfc_nodelist *ndlp = NULL;
Jamie Wellnitz50eba242006-02-28 19:25:38 -0500326 struct lpfc_nodelist *next_ndlp;
dea31012005-04-17 16:05:31 -0500327 struct lpfc_dmabuf *mlast, *next_mp;
328 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
329 uint32_t Did;
330 uint32_t CTentry;
331 int Cnt;
332 struct list_head head;
333
334 lpfc_set_disctmo(phba);
335
336 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
337
338 list_add_tail(&head, &mp->list);
339 list_for_each_entry_safe(mp, next_mp, &head, list) {
340 mlast = mp;
341
342 Size -= Cnt;
343
344 if (!ctptr)
345 ctptr = (uint32_t *) mlast->virt;
346 else
347 Cnt -= 16; /* subtract length of CT header */
348
349 /* Loop through entire NameServer list of DIDs */
350 while (Cnt) {
351
352 /* Get next DID from NameServer List */
353 CTentry = *ctptr++;
354 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
355
356 ndlp = NULL;
357 if (Did != phba->fc_myDID) {
358 /* Check for rscn processing or not */
359 ndlp = lpfc_setup_disc_node(phba, Did);
360 }
361 /* Mark all node table entries that are in the
362 Nameserver */
363 if (ndlp) {
364 /* NameServer Rsp */
365 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
366 "%d:0238 Process x%x NameServer"
367 " Rsp Data: x%x x%x x%x\n",
368 phba->brd_no,
369 Did, ndlp->nlp_flag,
370 phba->fc_flag,
371 phba->fc_rscn_id_cnt);
372 } else {
373 /* NameServer Rsp */
374 lpfc_printf_log(phba,
375 KERN_INFO,
376 LOG_DISCOVERY,
377 "%d:0239 Skip x%x NameServer "
378 "Rsp Data: x%x x%x x%x\n",
379 phba->brd_no,
380 Did, Size, phba->fc_flag,
381 phba->fc_rscn_id_cnt);
382 }
383
384 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
385 goto nsout1;
386 Cnt -= sizeof (uint32_t);
387 }
388 ctptr = NULL;
389
390 }
391
392nsout1:
393 list_del(&head);
394
Jamie Wellnitz50eba242006-02-28 19:25:38 -0500395 /*
396 * The driver has cycled through all Nports in the RSCN payload.
397 * Complete the handling by cleaning up and marking the
398 * current driver state.
399 */
dea31012005-04-17 16:05:31 -0500400 if (phba->hba_state == LPFC_HBA_READY) {
Jamie Wellnitz50eba242006-02-28 19:25:38 -0500401
402 /*
403 * Switch ports that connect a loop of multiple targets need
404 * special consideration. The driver wants to unregister the
405 * rpi only on the target that was pulled from the loop. On
406 * RSCN, the driver wants to rediscover an NPort only if the
407 * driver flagged it as NLP_NPR_2B_DISC. Provided adisc is
408 * not enabled and the NPort is not capable of retransmissions
409 * (FC Tape) prevent timing races with the scsi error handler by
410 * unregistering the Nport's RPI. This action causes all
411 * outstanding IO to flush back to the midlayer.
412 */
413 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
414 nlp_listp) {
415 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
416 (lpfc_rscn_payload_check(phba, ndlp->nlp_DID))) {
417 if ((phba->cfg_use_adisc == 0) &&
418 !(ndlp->nlp_fcp_info &
419 NLP_FCP_2_DEVICE)) {
420 lpfc_unreg_rpi(phba, ndlp);
421 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
422 }
423 }
424 }
dea31012005-04-17 16:05:31 -0500425 lpfc_els_flush_rscn(phba);
426 spin_lock_irq(phba->host->host_lock);
427 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
428 spin_unlock_irq(phba->host->host_lock);
429 }
430 return 0;
431}
432
433
434
435
436static void
437lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
438 struct lpfc_iocbq * rspiocb)
439{
440 IOCB_t *irsp;
441 struct lpfc_sli *psli;
442 struct lpfc_dmabuf *bmp;
443 struct lpfc_dmabuf *inp;
444 struct lpfc_dmabuf *outp;
445 struct lpfc_nodelist *ndlp;
446 struct lpfc_sli_ct_request *CTrsp;
447
448 psli = &phba->sli;
449 /* we pass cmdiocb to state machine which needs rspiocb as well */
450 cmdiocb->context_un.rsp_iocb = rspiocb;
451
452 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
453 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
454 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
455
456 irsp = &rspiocb->iocb;
457 if (irsp->ulpStatus) {
458 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
459 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
460 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
461 goto out;
462 }
463
464 /* Check for retry */
465 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
466 phba->fc_ns_retry++;
467 /* CT command is being retried */
468 ndlp =
469 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
470 NameServer_DID);
471 if (ndlp) {
472 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
473 0) {
474 goto out;
475 }
476 }
477 }
478 } else {
479 /* Good status, continue checking */
480 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
481 if (CTrsp->CommandResponse.bits.CmdRsp ==
482 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500483 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
484 "%d:0239 NameServer Rsp "
485 "Data: x%x\n",
486 phba->brd_no,
487 phba->fc_flag);
dea31012005-04-17 16:05:31 -0500488 lpfc_ns_rsp(phba, outp,
489 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
490 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
491 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
492 /* NameServer Rsp Error */
493 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
494 "%d:0240 NameServer Rsp Error "
495 "Data: x%x x%x x%x x%x\n",
496 phba->brd_no,
497 CTrsp->CommandResponse.bits.CmdRsp,
498 (uint32_t) CTrsp->ReasonCode,
499 (uint32_t) CTrsp->Explanation,
500 phba->fc_flag);
501 } else {
502 /* NameServer Rsp Error */
503 lpfc_printf_log(phba,
504 KERN_INFO,
505 LOG_DISCOVERY,
506 "%d:0241 NameServer Rsp Error "
507 "Data: x%x x%x x%x x%x\n",
508 phba->brd_no,
509 CTrsp->CommandResponse.bits.CmdRsp,
510 (uint32_t) CTrsp->ReasonCode,
511 (uint32_t) CTrsp->Explanation,
512 phba->fc_flag);
513 }
514 }
515 /* Link up / RSCN discovery */
516 lpfc_disc_start(phba);
517out:
518 lpfc_free_ct_rsp(phba, outp);
519 lpfc_mbuf_free(phba, inp->virt, inp->phys);
520 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
521 kfree(inp);
522 kfree(bmp);
523 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500524 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500525 spin_unlock_irq(phba->host->host_lock);
526 return;
527}
528
529static void
530lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
531 struct lpfc_iocbq * rspiocb)
532{
533 struct lpfc_sli *psli;
534 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
540 psli = &phba->sli;
541 /* we pass cmdiocb to state machine which needs rspiocb as well */
542 cmdiocb->context_un.rsp_iocb = rspiocb;
543
544 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
545 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
546 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
547 irsp = &rspiocb->iocb;
548
549 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
550
551 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
552 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
553 "%d:0209 RFT request completes ulpStatus x%x "
554 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
555 CTrsp->CommandResponse.bits.CmdRsp);
556
557 lpfc_free_ct_rsp(phba, outp);
558 lpfc_mbuf_free(phba, inp->virt, inp->phys);
559 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
560 kfree(inp);
561 kfree(bmp);
562 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500563 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500564 spin_unlock_irq(phba->host->host_lock);
565 return;
566}
567
568static void
569lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
570 struct lpfc_iocbq * rspiocb)
571{
572 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
573 return;
574}
575
576static void
577lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
578 struct lpfc_iocbq * rspiocb)
579{
580 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
581 return;
582}
583
584void
585lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
586{
587 char fwrev[16];
588
589 lpfc_decode_firmware_rev(phba, fwrev, 0);
590
591 if (phba->Port[0]) {
592 sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
593 phba->Port, fwrev, lpfc_release_version);
594 } else {
595 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
596 fwrev, lpfc_release_version);
597 }
598}
599
600/*
601 * lpfc_ns_cmd
602 * Description:
603 * Issue Cmd to NameServer
604 * SLI_CTNS_GID_FT
605 * LI_CTNS_RFT_ID
606 */
607int
608lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
609{
610 struct lpfc_dmabuf *mp, *bmp;
611 struct lpfc_sli_ct_request *CtReq;
612 struct ulp_bde64 *bpl;
613 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
614 struct lpfc_iocbq *) = NULL;
615 uint32_t rsp_size = 1024;
616
617 /* fill in BDEs for command */
618 /* Allocate buffer for command payload */
619 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
620 if (!mp)
621 goto ns_cmd_exit;
622
623 INIT_LIST_HEAD(&mp->list);
624 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
625 if (!mp->virt)
626 goto ns_cmd_free_mp;
627
628 /* Allocate buffer for Buffer ptr list */
629 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
630 if (!bmp)
631 goto ns_cmd_free_mpvirt;
632
633 INIT_LIST_HEAD(&bmp->list);
634 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
635 if (!bmp->virt)
636 goto ns_cmd_free_bmp;
637
638 /* NameServer Req */
639 lpfc_printf_log(phba,
640 KERN_INFO,
641 LOG_DISCOVERY,
642 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
643 phba->brd_no, cmdcode, phba->fc_flag,
644 phba->fc_rscn_id_cnt);
645
646 bpl = (struct ulp_bde64 *) bmp->virt;
647 memset(bpl, 0, sizeof(struct ulp_bde64));
648 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
649 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
650 bpl->tus.f.bdeFlags = 0;
651 if (cmdcode == SLI_CTNS_GID_FT)
652 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
653 else if (cmdcode == SLI_CTNS_RFT_ID)
654 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
655 else if (cmdcode == SLI_CTNS_RNN_ID)
656 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
657 else if (cmdcode == SLI_CTNS_RSNN_NN)
658 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
659 else
660 bpl->tus.f.bdeSize = 0;
661 bpl->tus.w = le32_to_cpu(bpl->tus.w);
662
663 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
664 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
665 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
666 CtReq->RevisionId.bits.InId = 0;
667 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
668 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
669 CtReq->CommandResponse.bits.Size = 0;
670 switch (cmdcode) {
671 case SLI_CTNS_GID_FT:
672 CtReq->CommandResponse.bits.CmdRsp =
673 be16_to_cpu(SLI_CTNS_GID_FT);
674 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
675 if (phba->hba_state < LPFC_HBA_READY)
676 phba->hba_state = LPFC_NS_QRY;
677 lpfc_set_disctmo(phba);
678 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
679 rsp_size = FC_MAX_NS_RSP;
680 break;
681
682 case SLI_CTNS_RFT_ID:
683 CtReq->CommandResponse.bits.CmdRsp =
684 be16_to_cpu(SLI_CTNS_RFT_ID);
685 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
686 CtReq->un.rft.fcpReg = 1;
687 cmpl = lpfc_cmpl_ct_cmd_rft_id;
688 break;
689
690 case SLI_CTNS_RNN_ID:
691 CtReq->CommandResponse.bits.CmdRsp =
692 be16_to_cpu(SLI_CTNS_RNN_ID);
693 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
694 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
695 sizeof (struct lpfc_name));
696 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
697 break;
698
699 case SLI_CTNS_RSNN_NN:
700 CtReq->CommandResponse.bits.CmdRsp =
701 be16_to_cpu(SLI_CTNS_RSNN_NN);
702 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
703 sizeof (struct lpfc_name));
704 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
705 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
706 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
707 break;
708 }
709
710 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
711 /* On success, The cmpl function will free the buffers */
712 return 0;
713
714 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
715ns_cmd_free_bmp:
716 kfree(bmp);
717ns_cmd_free_mpvirt:
718 lpfc_mbuf_free(phba, mp->virt, mp->phys);
719ns_cmd_free_mp:
720 kfree(mp);
721ns_cmd_exit:
722 return 1;
723}
724
725static void
726lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
727 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
728{
729 struct lpfc_dmabuf *bmp = cmdiocb->context3;
730 struct lpfc_dmabuf *inp = cmdiocb->context1;
731 struct lpfc_dmabuf *outp = cmdiocb->context2;
732 struct lpfc_sli_ct_request *CTrsp = outp->virt;
733 struct lpfc_sli_ct_request *CTcmd = inp->virt;
734 struct lpfc_nodelist *ndlp;
735 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
736 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
737
738 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
739 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
740 /* FDMI rsp failed */
741 lpfc_printf_log(phba,
742 KERN_INFO,
743 LOG_DISCOVERY,
744 "%d:0220 FDMI rsp failed Data: x%x\n",
745 phba->brd_no,
746 be16_to_cpu(fdmi_cmd));
747 }
748
749 switch (be16_to_cpu(fdmi_cmd)) {
750 case SLI_MGMT_RHBA:
751 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
752 break;
753
754 case SLI_MGMT_RPA:
755 break;
756
757 case SLI_MGMT_DHBA:
758 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
759 break;
760
761 case SLI_MGMT_DPRT:
762 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
763 break;
764 }
765
766 lpfc_free_ct_rsp(phba, outp);
767 lpfc_mbuf_free(phba, inp->virt, inp->phys);
768 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
769 kfree(inp);
770 kfree(bmp);
771 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500772 lpfc_sli_release_iocbq(phba, cmdiocb);
dea31012005-04-17 16:05:31 -0500773 spin_unlock_irq(phba->host->host_lock);
774 return;
775}
776int
777lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
778{
779 struct lpfc_dmabuf *mp, *bmp;
780 struct lpfc_sli_ct_request *CtReq;
781 struct ulp_bde64 *bpl;
782 uint32_t size;
783 REG_HBA *rh;
784 PORT_ENTRY *pe;
785 REG_PORT_ATTRIBUTE *pab;
786 ATTRIBUTE_BLOCK *ab;
787 ATTRIBUTE_ENTRY *ae;
788 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
789 struct lpfc_iocbq *);
790
791
792 /* fill in BDEs for command */
793 /* Allocate buffer for command payload */
794 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
795 if (!mp)
796 goto fdmi_cmd_exit;
797
798 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
799 if (!mp->virt)
800 goto fdmi_cmd_free_mp;
801
802 /* Allocate buffer for Buffer ptr list */
803 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
804 if (!bmp)
805 goto fdmi_cmd_free_mpvirt;
806
807 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
808 if (!bmp->virt)
809 goto fdmi_cmd_free_bmp;
810
811 INIT_LIST_HEAD(&mp->list);
812 INIT_LIST_HEAD(&bmp->list);
813
814 /* FDMI request */
815 lpfc_printf_log(phba,
816 KERN_INFO,
817 LOG_DISCOVERY,
818 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
819 phba->brd_no,
820 phba->fc_flag, phba->hba_state, cmdcode);
821
822 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
823
824 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
825 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
826 CtReq->RevisionId.bits.InId = 0;
827
828 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
829 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
830 size = 0;
831
832 switch (cmdcode) {
833 case SLI_MGMT_RHBA:
834 {
835 lpfc_vpd_t *vp = &phba->vpd;
836 uint32_t i, j, incr;
837 int len;
838
839 CtReq->CommandResponse.bits.CmdRsp =
840 be16_to_cpu(SLI_MGMT_RHBA);
841 CtReq->CommandResponse.bits.Size = 0;
842 rh = (REG_HBA *) & CtReq->un.PortID;
843 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
844 sizeof (struct lpfc_name));
845 /* One entry (port) per adapter */
846 rh->rpl.EntryCnt = be32_to_cpu(1);
847 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
848 sizeof (struct lpfc_name));
849
850 /* point to the HBA attribute block */
851 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
852 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
853 ab->EntryCnt = 0;
854
855 /* Point to the beginning of the first HBA attribute
856 entry */
857 /* #1 HBA attribute entry */
858 size += FOURBYTES;
859 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
860 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
861 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
862 + sizeof (struct lpfc_name));
863 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
864 sizeof (struct lpfc_name));
865 ab->EntryCnt++;
866 size += FOURBYTES + sizeof (struct lpfc_name);
867
868 /* #2 HBA attribute entry */
869 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
870 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
871 strcpy(ae->un.Manufacturer, "Emulex Corporation");
872 len = strlen(ae->un.Manufacturer);
873 len += (len & 3) ? (4 - (len & 3)) : 4;
874 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
875 ab->EntryCnt++;
876 size += FOURBYTES + len;
877
878 /* #3 HBA attribute entry */
879 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
880 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
881 strcpy(ae->un.SerialNumber, phba->SerialNumber);
882 len = strlen(ae->un.SerialNumber);
883 len += (len & 3) ? (4 - (len & 3)) : 4;
884 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
885 ab->EntryCnt++;
886 size += FOURBYTES + len;
887
888 /* #4 HBA attribute entry */
889 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
890 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
891 strcpy(ae->un.Model, phba->ModelName);
892 len = strlen(ae->un.Model);
893 len += (len & 3) ? (4 - (len & 3)) : 4;
894 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
895 ab->EntryCnt++;
896 size += FOURBYTES + len;
897
898 /* #5 HBA attribute entry */
899 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
900 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
901 strcpy(ae->un.ModelDescription, phba->ModelDesc);
902 len = strlen(ae->un.ModelDescription);
903 len += (len & 3) ? (4 - (len & 3)) : 4;
904 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
905 ab->EntryCnt++;
906 size += FOURBYTES + len;
907
908 /* #6 HBA attribute entry */
909 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
910 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
911 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
912 /* Convert JEDEC ID to ascii for hardware version */
913 incr = vp->rev.biuRev;
914 for (i = 0; i < 8; i++) {
915 j = (incr & 0xf);
916 if (j <= 9)
917 ae->un.HardwareVersion[7 - i] =
918 (char)((uint8_t) 0x30 +
919 (uint8_t) j);
920 else
921 ae->un.HardwareVersion[7 - i] =
922 (char)((uint8_t) 0x61 +
923 (uint8_t) (j - 10));
924 incr = (incr >> 4);
925 }
926 ab->EntryCnt++;
927 size += FOURBYTES + 8;
928
929 /* #7 HBA attribute entry */
930 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
931 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
932 strcpy(ae->un.DriverVersion, lpfc_release_version);
933 len = strlen(ae->un.DriverVersion);
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 /* #8 HBA attribute entry */
940 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
941 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
942 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
943 len = strlen(ae->un.OptionROMVersion);
944 len += (len & 3) ? (4 - (len & 3)) : 4;
945 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
946 ab->EntryCnt++;
947 size += FOURBYTES + len;
948
949 /* #9 HBA attribute entry */
950 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
951 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
952 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
953 1);
954 len = strlen(ae->un.FirmwareVersion);
955 len += (len & 3) ? (4 - (len & 3)) : 4;
956 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
957 ab->EntryCnt++;
958 size += FOURBYTES + len;
959
960 /* #10 HBA attribute entry */
961 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
962 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
963 sprintf(ae->un.OsNameVersion, "%s %s %s",
964 system_utsname.sysname, system_utsname.release,
965 system_utsname.version);
966 len = strlen(ae->un.OsNameVersion);
967 len += (len & 3) ? (4 - (len & 3)) : 4;
968 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
969 ab->EntryCnt++;
970 size += FOURBYTES + len;
971
972 /* #11 HBA attribute entry */
973 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
974 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
975 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
976 ae->un.MaxCTPayloadLen = (65 * 4096);
977 ab->EntryCnt++;
978 size += FOURBYTES + 4;
979
980 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
981 /* Total size */
982 size = GID_REQUEST_SZ - 4 + size;
983 }
984 break;
985
986 case SLI_MGMT_RPA:
987 {
988 lpfc_vpd_t *vp;
989 struct serv_parm *hsp;
990 int len;
991
992 vp = &phba->vpd;
993
994 CtReq->CommandResponse.bits.CmdRsp =
995 be16_to_cpu(SLI_MGMT_RPA);
996 CtReq->CommandResponse.bits.Size = 0;
997 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
998 size = sizeof (struct lpfc_name) + FOURBYTES;
999 memcpy((uint8_t *) & pab->PortName,
1000 (uint8_t *) & phba->fc_sparam.portName,
1001 sizeof (struct lpfc_name));
1002 pab->ab.EntryCnt = 0;
1003
1004 /* #1 Port attribute entry */
1005 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1006 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1007 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1008 ae->un.SupportFC4Types[2] = 1;
1009 ae->un.SupportFC4Types[7] = 1;
1010 pab->ab.EntryCnt++;
1011 size += FOURBYTES + 32;
1012
1013 /* #2 Port attribute entry */
1014 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1015 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1016 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1017 if (FC_JEDEC_ID(vp->rev.biuRev) == VIPER_JEDEC_ID)
1018 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1019 else if (FC_JEDEC_ID(vp->rev.biuRev) == HELIOS_JEDEC_ID)
1020 ae->un.SupportSpeed = HBA_PORTSPEED_4GBIT;
1021 else if ((FC_JEDEC_ID(vp->rev.biuRev) ==
1022 CENTAUR_2G_JEDEC_ID)
1023 || (FC_JEDEC_ID(vp->rev.biuRev) ==
1024 PEGASUS_JEDEC_ID)
1025 || (FC_JEDEC_ID(vp->rev.biuRev) ==
1026 THOR_JEDEC_ID))
1027 ae->un.SupportSpeed = HBA_PORTSPEED_2GBIT;
1028 else
1029 ae->un.SupportSpeed = HBA_PORTSPEED_1GBIT;
1030 pab->ab.EntryCnt++;
1031 size += FOURBYTES + 4;
1032
1033 /* #3 Port attribute entry */
1034 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1035 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1036 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1037 switch(phba->fc_linkspeed) {
1038 case LA_1GHZ_LINK:
1039 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1040 break;
1041 case LA_2GHZ_LINK:
1042 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1043 break;
1044 case LA_4GHZ_LINK:
1045 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1046 break;
1047 default:
1048 ae->un.PortSpeed =
1049 HBA_PORTSPEED_UNKNOWN;
1050 break;
1051 }
1052 pab->ab.EntryCnt++;
1053 size += FOURBYTES + 4;
1054
1055 /* #4 Port attribute entry */
1056 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1057 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1058 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1059 hsp = (struct serv_parm *) & phba->fc_sparam;
1060 ae->un.MaxFrameSize =
1061 (((uint32_t) hsp->cmn.
1062 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1063 bbRcvSizeLsb;
1064 pab->ab.EntryCnt++;
1065 size += FOURBYTES + 4;
1066
1067 /* #5 Port attribute entry */
1068 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1069 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1070 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1071 len = strlen((char *)ae->un.OsDeviceName);
1072 len += (len & 3) ? (4 - (len & 3)) : 4;
1073 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1074 pab->ab.EntryCnt++;
1075 size += FOURBYTES + len;
1076
1077 if (phba->cfg_fdmi_on == 2) {
1078 /* #6 Port attribute entry */
1079 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1080 size);
1081 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1082 sprintf(ae->un.HostName, "%s",
1083 system_utsname.nodename);
1084 len = strlen(ae->un.HostName);
1085 len += (len & 3) ? (4 - (len & 3)) : 4;
1086 ae->ad.bits.AttrLen =
1087 be16_to_cpu(FOURBYTES + len);
1088 pab->ab.EntryCnt++;
1089 size += FOURBYTES + len;
1090 }
1091
1092 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1093 /* Total size */
1094 size = GID_REQUEST_SZ - 4 + size;
1095 }
1096 break;
1097
1098 case SLI_MGMT_DHBA:
1099 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1100 CtReq->CommandResponse.bits.Size = 0;
1101 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1102 memcpy((uint8_t *) & pe->PortName,
1103 (uint8_t *) & phba->fc_sparam.portName,
1104 sizeof (struct lpfc_name));
1105 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1106 break;
1107
1108 case SLI_MGMT_DPRT:
1109 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1110 CtReq->CommandResponse.bits.Size = 0;
1111 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1112 memcpy((uint8_t *) & pe->PortName,
1113 (uint8_t *) & phba->fc_sparam.portName,
1114 sizeof (struct lpfc_name));
1115 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1116 break;
1117 }
1118
1119 bpl = (struct ulp_bde64 *) bmp->virt;
1120 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1121 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1122 bpl->tus.f.bdeFlags = 0;
1123 bpl->tus.f.bdeSize = size;
1124 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1125
1126 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1127
1128 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1129 return 0;
1130
1131 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1132fdmi_cmd_free_bmp:
1133 kfree(bmp);
1134fdmi_cmd_free_mpvirt:
1135 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1136fdmi_cmd_free_mp:
1137 kfree(mp);
1138fdmi_cmd_exit:
1139 /* Issue FDMI request failed */
1140 lpfc_printf_log(phba,
1141 KERN_INFO,
1142 LOG_DISCOVERY,
1143 "%d:0244 Issue FDMI request failed Data: x%x\n",
1144 phba->brd_no,
1145 cmdcode);
1146 return 1;
1147}
1148
1149void
1150lpfc_fdmi_tmo(unsigned long ptr)
1151{
1152 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1153 unsigned long iflag;
1154
1155 spin_lock_irqsave(phba->host->host_lock, iflag);
1156 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1157 phba->work_hba_events |= WORKER_FDMI_TMO;
1158 if (phba->work_wait)
1159 wake_up(phba->work_wait);
1160 }
1161 spin_unlock_irqrestore(phba->host->host_lock,iflag);
1162}
1163
1164void
1165lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1166{
1167 struct lpfc_nodelist *ndlp;
1168
1169 spin_lock_irq(phba->host->host_lock);
1170 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1171 spin_unlock_irq(phba->host->host_lock);
1172 return;
1173 }
1174 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1175 if (ndlp) {
1176 if (system_utsname.nodename[0] != '\0') {
1177 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1178 } else {
1179 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1180 }
1181 }
1182 spin_unlock_irq(phba->host->host_lock);
1183 return;
1184}
1185
1186
1187void
1188lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1189{
1190 struct lpfc_sli *psli = &phba->sli;
1191 lpfc_vpd_t *vp = &phba->vpd;
1192 uint32_t b1, b2, b3, b4, i, rev;
1193 char c;
1194 uint32_t *ptr, str[4];
1195 uint8_t *fwname;
1196
1197 if (vp->rev.rBit) {
1198 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1199 rev = vp->rev.sli2FwRev;
1200 else
1201 rev = vp->rev.sli1FwRev;
1202
1203 b1 = (rev & 0x0000f000) >> 12;
1204 b2 = (rev & 0x00000f00) >> 8;
1205 b3 = (rev & 0x000000c0) >> 6;
1206 b4 = (rev & 0x00000030) >> 4;
1207
1208 switch (b4) {
1209 case 0:
1210 c = 'N';
1211 break;
1212 case 1:
1213 c = 'A';
1214 break;
1215 case 2:
1216 c = 'B';
1217 break;
1218 default:
1219 c = 0;
1220 break;
1221 }
1222 b4 = (rev & 0x0000000f);
1223
1224 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1225 fwname = vp->rev.sli2FwName;
1226 else
1227 fwname = vp->rev.sli1FwName;
1228
1229 for (i = 0; i < 16; i++)
1230 if (fwname[i] == 0x20)
1231 fwname[i] = 0;
1232
1233 ptr = (uint32_t*)fwname;
1234
1235 for (i = 0; i < 3; i++)
1236 str[i] = be32_to_cpu(*ptr++);
1237
1238 if (c == 0) {
1239 if (flag)
1240 sprintf(fwrevision, "%d.%d%d (%s)",
1241 b1, b2, b3, (char *)str);
1242 else
1243 sprintf(fwrevision, "%d.%d%d", b1,
1244 b2, b3);
1245 } else {
1246 if (flag)
1247 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1248 b1, b2, b3, c,
1249 b4, (char *)str);
1250 else
1251 sprintf(fwrevision, "%d.%d%d%c%d",
1252 b1, b2, b3, c, b4);
1253 }
1254 } else {
1255 rev = vp->rev.smFwRev;
1256
1257 b1 = (rev & 0xff000000) >> 24;
1258 b2 = (rev & 0x00f00000) >> 20;
1259 b3 = (rev & 0x000f0000) >> 16;
1260 c = (rev & 0x0000ff00) >> 8;
1261 b4 = (rev & 0x000000ff);
1262
1263 if (flag)
1264 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1265 b2, b3, c, b4);
1266 else
1267 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1268 b2, b3, c, b4);
1269 }
1270 return;
1271}