[SCSI] lpfc 8.2.2 : Fix locking around HBA's port_list
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / lpfc / lpfc_ct.c
blob43e2e33f9a07da7c28dd5c119987e3bc00c4cf12
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * 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. *
19 *******************************************************************/
22 * Fibre Channel SCSI LAN Device Driver CT support
25 #include <linux/blkdev.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/utsname.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
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 #include "lpfc_vport.h"
44 #include "lpfc_debugfs.h"
46 #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
47 * incapable of reporting */
48 #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
49 #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
50 #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
51 #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
52 #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
53 #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
55 #define FOURBYTES 4
58 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
61 * lpfc_ct_unsol_event
63 static void
64 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
65 struct lpfc_dmabuf *mp, uint32_t size)
67 if (!mp) {
68 printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
69 "piocbq = %p, status = x%x, mp = %p, size = %d\n",
70 __FUNCTION__, __LINE__,
71 piocbq, piocbq->iocb.ulpStatus, mp, size);
74 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
75 "buffer = %p, size = %d, status = x%x\n",
76 __FUNCTION__, __LINE__,
77 piocbq, mp, size,
78 piocbq->iocb.ulpStatus);
82 static void
83 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
84 struct lpfc_dmabuf *mp, uint32_t size)
86 if (!mp) {
87 printk(KERN_ERR "%s (%d): Unsolited CT, no "
88 "HBQ buffer, piocbq = %p, status = x%x\n",
89 __FUNCTION__, __LINE__,
90 piocbq, piocbq->iocb.ulpStatus);
91 } else {
92 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
93 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
94 "piocbq = %p, buffer = %p, size = %d, "
95 "status = x%x\n",
96 __FUNCTION__, __LINE__,
97 piocbq, mp, size, piocbq->iocb.ulpStatus);
101 void
102 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
103 struct lpfc_iocbq *piocbq)
106 struct lpfc_dmabuf *mp = NULL;
107 IOCB_t *icmd = &piocbq->iocb;
108 int i;
109 struct lpfc_iocbq *iocbq;
110 dma_addr_t paddr;
111 uint32_t size;
112 struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
113 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
115 piocbq->context2 = NULL;
116 piocbq->context3 = NULL;
118 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
119 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
120 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
121 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
122 /* Not enough posted buffers; Try posting more buffers */
123 phba->fc_stat.NoRcvBuf++;
124 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
125 lpfc_post_buffer(phba, pring, 0, 1);
126 return;
129 /* If there are no BDEs associated with this IOCB,
130 * there is nothing to do.
132 if (icmd->ulpBdeCount == 0)
133 return;
135 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
136 list_for_each_entry(iocbq, &piocbq->list, list) {
137 icmd = &iocbq->iocb;
138 if (icmd->ulpBdeCount == 0) {
139 printk(KERN_ERR "%s (%d): Unsolited CT, no "
140 "BDE, iocbq = %p, status = x%x\n",
141 __FUNCTION__, __LINE__,
142 iocbq, iocbq->iocb.ulpStatus);
143 continue;
146 size = icmd->un.cont64[0].tus.f.bdeSize;
147 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf1, size);
148 lpfc_in_buf_free(phba, bdeBuf1);
149 if (icmd->ulpBdeCount == 2) {
150 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf2,
151 size);
152 lpfc_in_buf_free(phba, bdeBuf2);
155 } else {
156 struct lpfc_iocbq *next;
158 list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
159 icmd = &iocbq->iocb;
160 if (icmd->ulpBdeCount == 0) {
161 printk(KERN_ERR "%s (%d): Unsolited CT, no "
162 "BDE, iocbq = %p, status = x%x\n",
163 __FUNCTION__, __LINE__,
164 iocbq, iocbq->iocb.ulpStatus);
165 continue;
168 for (i = 0; i < icmd->ulpBdeCount; i++) {
169 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
170 icmd->un.cont64[i].addrLow);
171 mp = lpfc_sli_ringpostbuf_get(phba, pring,
172 paddr);
173 size = icmd->un.cont64[i].tus.f.bdeSize;
174 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
175 lpfc_in_buf_free(phba, mp);
177 list_del(&iocbq->list);
178 lpfc_sli_release_iocbq(phba, iocbq);
183 static void
184 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
186 struct lpfc_dmabuf *mlast, *next_mlast;
188 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
189 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
190 list_del(&mlast->list);
191 kfree(mlast);
193 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
194 kfree(mlist);
195 return;
198 static struct lpfc_dmabuf *
199 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
200 uint32_t size, int *entries)
202 struct lpfc_dmabuf *mlist = NULL;
203 struct lpfc_dmabuf *mp;
204 int cnt, i = 0;
206 /* We get chucks of FCELSSIZE */
207 cnt = size > FCELSSIZE ? FCELSSIZE: size;
209 while (size) {
210 /* Allocate buffer for rsp payload */
211 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
212 if (!mp) {
213 if (mlist)
214 lpfc_free_ct_rsp(phba, mlist);
215 return NULL;
218 INIT_LIST_HEAD(&mp->list);
220 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
221 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
222 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
223 else
224 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
226 if (!mp->virt) {
227 kfree(mp);
228 if (mlist)
229 lpfc_free_ct_rsp(phba, mlist);
230 return NULL;
233 /* Queue it to a linked list */
234 if (!mlist)
235 mlist = mp;
236 else
237 list_add_tail(&mp->list, &mlist->list);
239 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
240 /* build buffer ptr list for IOCB */
241 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
242 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
243 bpl->tus.f.bdeSize = (uint16_t) cnt;
244 bpl->tus.w = le32_to_cpu(bpl->tus.w);
245 bpl++;
247 i++;
248 size -= cnt;
251 *entries = i;
252 return mlist;
256 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
258 struct lpfc_dmabuf *buf_ptr;
260 if (ctiocb->context1) {
261 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
262 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
263 kfree(buf_ptr);
264 ctiocb->context1 = NULL;
266 if (ctiocb->context2) {
267 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
268 ctiocb->context2 = NULL;
271 if (ctiocb->context3) {
272 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
273 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
274 kfree(buf_ptr);
275 ctiocb->context1 = NULL;
277 lpfc_sli_release_iocbq(phba, ctiocb);
278 return 0;
281 static int
282 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
283 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
284 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
285 struct lpfc_iocbq *),
286 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
287 uint32_t tmo, uint8_t retry)
289 struct lpfc_hba *phba = vport->phba;
290 struct lpfc_sli *psli = &phba->sli;
291 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
292 IOCB_t *icmd;
293 struct lpfc_iocbq *geniocb;
294 int rc;
296 /* Allocate buffer for command iocb */
297 geniocb = lpfc_sli_get_iocbq(phba);
299 if (geniocb == NULL)
300 return 1;
302 icmd = &geniocb->iocb;
303 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
304 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
305 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
306 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
307 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
309 if (usr_flg)
310 geniocb->context3 = NULL;
311 else
312 geniocb->context3 = (uint8_t *) bmp;
314 /* Save for completion so we can release these resources */
315 geniocb->context1 = (uint8_t *) inp;
316 geniocb->context2 = (uint8_t *) outp;
318 /* Fill in payload, bp points to frame payload */
319 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
321 /* Fill in rest of iocb */
322 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
323 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
324 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
325 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
327 if (!tmo) {
328 /* FC spec states we need 3 * ratov for CT requests */
329 tmo = (3 * phba->fc_ratov);
331 icmd->ulpTimeout = tmo;
332 icmd->ulpBdeCount = 1;
333 icmd->ulpLe = 1;
334 icmd->ulpClass = CLASS3;
335 icmd->ulpContext = ndlp->nlp_rpi;
337 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
338 /* For GEN_REQUEST64_CR, use the RPI */
339 icmd->ulpCt_h = 0;
340 icmd->ulpCt_l = 0;
343 /* Issue GEN REQ IOCB for NPORT <did> */
344 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
345 "%d (%d):0119 Issue GEN REQ IOCB to NPORT x%x "
346 "Data: x%x x%x\n", phba->brd_no, vport->vpi,
347 ndlp->nlp_DID, icmd->ulpIoTag,
348 vport->port_state);
349 geniocb->iocb_cmpl = cmpl;
350 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
351 geniocb->vport = vport;
352 geniocb->retry = retry;
353 rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
355 if (rc == IOCB_ERROR) {
356 lpfc_sli_release_iocbq(phba, geniocb);
357 return 1;
360 return 0;
363 static int
364 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
365 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
366 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
367 struct lpfc_iocbq *),
368 uint32_t rsp_size, uint8_t retry)
370 struct lpfc_hba *phba = vport->phba;
371 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
372 struct lpfc_dmabuf *outmp;
373 int cnt = 0, status;
374 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
375 CommandResponse.bits.CmdRsp;
377 bpl++; /* Skip past ct request */
379 /* Put buffer(s) for ct rsp in bpl */
380 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
381 if (!outmp)
382 return -ENOMEM;
384 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
385 cnt+1, 0, retry);
386 if (status) {
387 lpfc_free_ct_rsp(phba, outmp);
388 return -ENOMEM;
390 return 0;
393 struct lpfc_vport *
394 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
395 struct lpfc_vport *vport_curr;
396 unsigned long flags;
398 spin_lock_irqsave(&phba->hbalock, flags);
399 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
400 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
401 spin_unlock_irqrestore(&phba->hbalock, flags);
402 return vport_curr;
405 spin_unlock_irqrestore(&phba->hbalock, flags);
406 return NULL;
409 static int
410 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
412 struct lpfc_hba *phba = vport->phba;
413 struct lpfc_sli_ct_request *Response =
414 (struct lpfc_sli_ct_request *) mp->virt;
415 struct lpfc_nodelist *ndlp = NULL;
416 struct lpfc_dmabuf *mlast, *next_mp;
417 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
418 uint32_t Did, CTentry;
419 int Cnt;
420 struct list_head head;
422 lpfc_set_disctmo(vport);
423 vport->num_disc_nodes = 0;
426 list_add_tail(&head, &mp->list);
427 list_for_each_entry_safe(mp, next_mp, &head, list) {
428 mlast = mp;
430 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
432 Size -= Cnt;
434 if (!ctptr) {
435 ctptr = (uint32_t *) mlast->virt;
436 } else
437 Cnt -= 16; /* subtract length of CT header */
439 /* Loop through entire NameServer list of DIDs */
440 while (Cnt >= sizeof (uint32_t)) {
441 /* Get next DID from NameServer List */
442 CTentry = *ctptr++;
443 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
445 ndlp = NULL;
448 * Check for rscn processing or not
449 * To conserve rpi's, filter out addresses for other
450 * vports on the same physical HBAs.
452 if ((Did != vport->fc_myDID) &&
453 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
454 phba->cfg_peer_port_login)) {
455 if ((vport->port_type != LPFC_NPIV_PORT) ||
456 (vport->fc_flag & FC_RFF_NOT_SUPPORTED) ||
457 (!phba->cfg_vport_restrict_login)) {
458 ndlp = lpfc_setup_disc_node(vport, Did);
459 if (ndlp) {
460 lpfc_debugfs_disc_trc(vport,
461 LPFC_DISC_TRC_CT,
462 "Parse GID_FTrsp: "
463 "did:x%x flg:x%x x%x",
464 Did, ndlp->nlp_flag,
465 vport->fc_flag);
467 lpfc_printf_log(phba, KERN_INFO,
468 LOG_DISCOVERY,
469 "%d (%d):0238 Process "
470 "x%x NameServer Rsp"
471 "Data: x%x x%x x%x\n",
472 phba->brd_no,
473 vport->vpi, Did,
474 ndlp->nlp_flag,
475 vport->fc_flag,
476 vport->fc_rscn_id_cnt);
477 } else {
478 lpfc_debugfs_disc_trc(vport,
479 LPFC_DISC_TRC_CT,
480 "Skip1 GID_FTrsp: "
481 "did:x%x flg:x%x cnt:%d",
482 Did, vport->fc_flag,
483 vport->fc_rscn_id_cnt);
485 lpfc_printf_log(phba, KERN_INFO,
486 LOG_DISCOVERY,
487 "%d (%d):0239 Skip x%x "
488 "NameServer Rsp Data: "
489 "x%x x%x\n",
490 phba->brd_no,
491 vport->vpi, Did,
492 vport->fc_flag,
493 vport->fc_rscn_id_cnt);
496 } else {
497 if (!(vport->fc_flag & FC_RSCN_MODE) ||
498 (lpfc_rscn_payload_check(vport, Did))) {
499 lpfc_debugfs_disc_trc(vport,
500 LPFC_DISC_TRC_CT,
501 "Query GID_FTrsp: "
502 "did:x%x flg:x%x cnt:%d",
503 Did, vport->fc_flag,
504 vport->fc_rscn_id_cnt);
506 if (lpfc_ns_cmd(vport,
507 SLI_CTNS_GFF_ID,
508 0, Did) == 0)
509 vport->num_disc_nodes++;
511 else {
512 lpfc_debugfs_disc_trc(vport,
513 LPFC_DISC_TRC_CT,
514 "Skip2 GID_FTrsp: "
515 "did:x%x flg:x%x cnt:%d",
516 Did, vport->fc_flag,
517 vport->fc_rscn_id_cnt);
519 lpfc_printf_log(phba, KERN_INFO,
520 LOG_DISCOVERY,
521 "%d (%d):0245 Skip x%x "
522 "NameServer Rsp Data: "
523 "x%x x%x\n",
524 phba->brd_no,
525 vport->vpi, Did,
526 vport->fc_flag,
527 vport->fc_rscn_id_cnt);
531 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
532 goto nsout1;
533 Cnt -= sizeof (uint32_t);
535 ctptr = NULL;
539 nsout1:
540 list_del(&head);
541 return 0;
544 static void
545 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
546 struct lpfc_iocbq *rspiocb)
548 struct lpfc_vport *vport = cmdiocb->vport;
549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
550 IOCB_t *irsp;
551 struct lpfc_dmabuf *bmp;
552 struct lpfc_dmabuf *outp;
553 struct lpfc_sli_ct_request *CTrsp;
554 int rc;
556 /* we pass cmdiocb to state machine which needs rspiocb as well */
557 cmdiocb->context_un.rsp_iocb = rspiocb;
559 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
560 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
561 irsp = &rspiocb->iocb;
563 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
564 "GID_FT cmpl: status:x%x/x%x rtry:%d",
565 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
567 /* Don't bother processing response if vport is being torn down. */
568 if (vport->load_flag & FC_UNLOADING)
569 goto out;
572 if (lpfc_els_chk_latt(vport) || lpfc_error_lost_link(irsp)) {
573 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
574 "%d (%d):0216 Link event during NS query\n",
575 phba->brd_no, vport->vpi);
576 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
577 goto out;
580 if (irsp->ulpStatus) {
581 /* Check for retry */
582 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
583 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
584 (irsp->un.ulpWord[4] != IOERR_NO_RESOURCES))
585 vport->fc_ns_retry++;
586 /* CT command is being retried */
587 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
588 vport->fc_ns_retry, 0);
589 if (rc == 0)
590 goto out;
592 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
593 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
594 "%d (%d):0257 GID_FT Query error: 0x%x 0x%x\n",
595 phba->brd_no, vport->vpi, irsp->ulpStatus,
596 vport->fc_ns_retry);
597 } else {
598 /* Good status, continue checking */
599 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
600 if (CTrsp->CommandResponse.bits.CmdRsp ==
601 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
602 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
603 "%d (%d):0208 NameServer Rsp "
604 "Data: x%x\n",
605 phba->brd_no, vport->vpi,
606 vport->fc_flag);
607 lpfc_ns_rsp(vport, outp,
608 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
609 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
610 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
611 /* NameServer Rsp Error */
612 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
613 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
614 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
615 "%d (%d):0269 No NameServer Entries "
616 "Data: x%x x%x x%x x%x\n",
617 phba->brd_no, vport->vpi,
618 CTrsp->CommandResponse.bits.CmdRsp,
619 (uint32_t) CTrsp->ReasonCode,
620 (uint32_t) CTrsp->Explanation,
621 vport->fc_flag);
623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
624 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
625 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
626 (uint32_t) CTrsp->ReasonCode,
627 (uint32_t) CTrsp->Explanation);
629 else {
630 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
631 "%d (%d):0240 NameServer Rsp Error "
632 "Data: x%x x%x x%x x%x\n",
633 phba->brd_no, vport->vpi,
634 CTrsp->CommandResponse.bits.CmdRsp,
635 (uint32_t) CTrsp->ReasonCode,
636 (uint32_t) CTrsp->Explanation,
637 vport->fc_flag);
639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
640 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
641 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
642 (uint32_t) CTrsp->ReasonCode,
643 (uint32_t) CTrsp->Explanation);
647 } else {
648 /* NameServer Rsp Error */
649 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
650 "%d (%d):0241 NameServer Rsp Error "
651 "Data: x%x x%x x%x x%x\n",
652 phba->brd_no, vport->vpi,
653 CTrsp->CommandResponse.bits.CmdRsp,
654 (uint32_t) CTrsp->ReasonCode,
655 (uint32_t) CTrsp->Explanation,
656 vport->fc_flag);
658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
659 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
660 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
661 (uint32_t) CTrsp->ReasonCode,
662 (uint32_t) CTrsp->Explanation);
665 /* Link up / RSCN discovery */
666 if (vport->num_disc_nodes == 0) {
668 * The driver has cycled through all Nports in the RSCN payload.
669 * Complete the handling by cleaning up and marking the
670 * current driver state.
672 if (vport->port_state >= LPFC_DISC_AUTH) {
673 if (vport->fc_flag & FC_RSCN_MODE) {
674 lpfc_els_flush_rscn(vport);
675 spin_lock_irq(shost->host_lock);
676 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
677 spin_unlock_irq(shost->host_lock);
679 else
680 lpfc_els_flush_rscn(vport);
683 lpfc_disc_start(vport);
685 out:
686 lpfc_ct_free_iocb(phba, cmdiocb);
687 return;
690 void
691 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
692 struct lpfc_iocbq *rspiocb)
694 struct lpfc_vport *vport = cmdiocb->vport;
695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
696 IOCB_t *irsp = &rspiocb->iocb;
697 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
698 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
699 struct lpfc_sli_ct_request *CTrsp;
700 int did;
701 uint8_t fbits;
702 struct lpfc_nodelist *ndlp;
704 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
705 did = be32_to_cpu(did);
707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
708 "GFF_ID cmpl: status:x%x/x%x did:x%x",
709 irsp->ulpStatus, irsp->un.ulpWord[4], did);
711 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
712 /* Good status, continue checking */
713 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
714 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
716 if (CTrsp->CommandResponse.bits.CmdRsp ==
717 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
718 if ((fbits & FC4_FEATURE_INIT) &&
719 !(fbits & FC4_FEATURE_TARGET)) {
720 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
721 "%d (%d):0270 Skip x%x GFF "
722 "NameServer Rsp Data: (init) "
723 "x%x x%x\n", phba->brd_no,
724 vport->vpi, did, fbits,
725 vport->fc_rscn_id_cnt);
726 goto out;
730 else {
731 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
732 "%d (%d):0267 NameServer GFF Rsp"
733 " x%x Error (%d %d) Data: x%x x%x\n",
734 phba->brd_no, vport->vpi, did,
735 irsp->ulpStatus, irsp->un.ulpWord[4],
736 vport->fc_flag, vport->fc_rscn_id_cnt)
739 /* This is a target port, unregistered port, or the GFF_ID failed */
740 ndlp = lpfc_setup_disc_node(vport, did);
741 if (ndlp) {
742 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
743 "%d (%d):0242 Process x%x GFF "
744 "NameServer Rsp Data: x%x x%x x%x\n",
745 phba->brd_no, vport->vpi,
746 did, ndlp->nlp_flag, vport->fc_flag,
747 vport->fc_rscn_id_cnt);
748 } else {
749 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
750 "%d (%d):0243 Skip x%x GFF "
751 "NameServer Rsp Data: x%x x%x\n",
752 phba->brd_no, vport->vpi, did,
753 vport->fc_flag, vport->fc_rscn_id_cnt);
755 out:
756 /* Link up / RSCN discovery */
757 if (vport->num_disc_nodes)
758 vport->num_disc_nodes--;
759 if (vport->num_disc_nodes == 0) {
761 * The driver has cycled through all Nports in the RSCN payload.
762 * Complete the handling by cleaning up and marking the
763 * current driver state.
765 if (vport->port_state >= LPFC_DISC_AUTH) {
766 if (vport->fc_flag & FC_RSCN_MODE) {
767 lpfc_els_flush_rscn(vport);
768 spin_lock_irq(shost->host_lock);
769 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
770 spin_unlock_irq(shost->host_lock);
772 else
773 lpfc_els_flush_rscn(vport);
775 lpfc_disc_start(vport);
777 lpfc_ct_free_iocb(phba, cmdiocb);
778 return;
782 static void
783 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
784 struct lpfc_iocbq *rspiocb)
786 struct lpfc_vport *vport = cmdiocb->vport;
787 struct lpfc_dmabuf *inp;
788 struct lpfc_dmabuf *outp;
789 IOCB_t *irsp;
790 struct lpfc_sli_ct_request *CTrsp;
791 int cmdcode, rc;
792 uint8_t retry;
793 uint32_t latt;
795 /* we pass cmdiocb to state machine which needs rspiocb as well */
796 cmdiocb->context_un.rsp_iocb = rspiocb;
798 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
799 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
800 irsp = &rspiocb->iocb;
802 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
803 CommandResponse.bits.CmdRsp);
804 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
806 latt = lpfc_els_chk_latt(vport);
808 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
809 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
810 "%d (%d):0209 RFT request completes, latt %d, "
811 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
812 phba->brd_no, vport->vpi, latt, irsp->ulpStatus,
813 CTrsp->CommandResponse.bits.CmdRsp,
814 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
817 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
818 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
820 if (irsp->ulpStatus) {
821 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
822 "%d (%d):0268 NS cmd %x Error (%d %d)\n",
823 phba->brd_no, vport->vpi, cmdcode,
824 irsp->ulpStatus, irsp->un.ulpWord[4]);
826 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
827 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
828 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
829 goto out;
831 retry = cmdiocb->retry;
832 if (retry >= LPFC_MAX_NS_RETRY)
833 goto out;
835 retry++;
836 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
837 "%d (%d):0216 Retrying NS cmd %x\n",
838 phba->brd_no, vport->vpi, cmdcode);
839 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
840 if (rc == 0)
841 goto out;
844 out:
845 lpfc_ct_free_iocb(phba, cmdiocb);
846 return;
849 static void
850 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
851 struct lpfc_iocbq *rspiocb)
853 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
854 return;
857 static void
858 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
859 struct lpfc_iocbq *rspiocb)
861 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
862 return;
865 static void
866 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
867 struct lpfc_iocbq *rspiocb)
869 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
870 return;
873 static void
874 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
875 struct lpfc_iocbq *rspiocb)
877 IOCB_t *irsp = &rspiocb->iocb;
878 struct lpfc_vport *vport = cmdiocb->vport;
880 if (irsp->ulpStatus != IOSTAT_SUCCESS)
881 vport->fc_flag |= FC_RFF_NOT_SUPPORTED;
883 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
884 return;
888 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
889 size_t size)
891 int n;
892 uint8_t *wwn = vport->phba->wwpn;
894 n = snprintf(symbol, size,
895 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
896 wwn[0], wwn[1], wwn[2], wwn[3],
897 wwn[4], wwn[5], wwn[6], wwn[7]);
899 if (vport->port_type == LPFC_PHYSICAL_PORT)
900 return n;
902 if (n < size)
903 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
905 if (n < size && vport->vname)
906 n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
907 return n;
911 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
912 size_t size)
914 char fwrev[16];
915 int n;
917 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
919 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
920 vport->phba->ModelName, fwrev, lpfc_release_version);
921 return n;
925 * lpfc_ns_cmd
926 * Description:
927 * Issue Cmd to NameServer
928 * SLI_CTNS_GID_FT
929 * LI_CTNS_RFT_ID
932 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
933 uint8_t retry, uint32_t context)
935 struct lpfc_nodelist * ndlp;
936 struct lpfc_hba *phba = vport->phba;
937 struct lpfc_dmabuf *mp, *bmp;
938 struct lpfc_sli_ct_request *CtReq;
939 struct ulp_bde64 *bpl;
940 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
941 struct lpfc_iocbq *) = NULL;
942 uint32_t rsp_size = 1024;
943 size_t size;
944 int rc = 0;
946 ndlp = lpfc_findnode_did(vport, NameServer_DID);
947 if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
948 rc=1;
949 goto ns_cmd_exit;
952 /* fill in BDEs for command */
953 /* Allocate buffer for command payload */
954 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
955 if (!mp) {
956 rc=2;
957 goto ns_cmd_exit;
960 INIT_LIST_HEAD(&mp->list);
961 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
962 if (!mp->virt) {
963 rc=3;
964 goto ns_cmd_free_mp;
967 /* Allocate buffer for Buffer ptr list */
968 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
969 if (!bmp) {
970 rc=4;
971 goto ns_cmd_free_mpvirt;
974 INIT_LIST_HEAD(&bmp->list);
975 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
976 if (!bmp->virt) {
977 rc=5;
978 goto ns_cmd_free_bmp;
981 /* NameServer Req */
982 lpfc_printf_log(phba, KERN_INFO ,LOG_DISCOVERY,
983 "%d (%d):0236 NameServer Req Data: x%x x%x x%x\n",
984 phba->brd_no, vport->vpi, cmdcode, vport->fc_flag,
985 vport->fc_rscn_id_cnt);
987 bpl = (struct ulp_bde64 *) bmp->virt;
988 memset(bpl, 0, sizeof(struct ulp_bde64));
989 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
990 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
991 bpl->tus.f.bdeFlags = 0;
992 if (cmdcode == SLI_CTNS_GID_FT)
993 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
994 else if (cmdcode == SLI_CTNS_GFF_ID)
995 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
996 else if (cmdcode == SLI_CTNS_RFT_ID)
997 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
998 else if (cmdcode == SLI_CTNS_RNN_ID)
999 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1000 else if (cmdcode == SLI_CTNS_RSPN_ID)
1001 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1002 else if (cmdcode == SLI_CTNS_RSNN_NN)
1003 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1004 else if (cmdcode == SLI_CTNS_RFF_ID)
1005 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1006 else
1007 bpl->tus.f.bdeSize = 0;
1008 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1010 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1011 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1012 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1013 CtReq->RevisionId.bits.InId = 0;
1014 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1015 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1016 CtReq->CommandResponse.bits.Size = 0;
1017 switch (cmdcode) {
1018 case SLI_CTNS_GID_FT:
1019 CtReq->CommandResponse.bits.CmdRsp =
1020 be16_to_cpu(SLI_CTNS_GID_FT);
1021 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
1022 if (vport->port_state < LPFC_NS_QRY)
1023 vport->port_state = LPFC_NS_QRY;
1024 lpfc_set_disctmo(vport);
1025 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1026 rsp_size = FC_MAX_NS_RSP;
1027 break;
1029 case SLI_CTNS_GFF_ID:
1030 CtReq->CommandResponse.bits.CmdRsp =
1031 be16_to_cpu(SLI_CTNS_GFF_ID);
1032 CtReq->un.gff.PortId = be32_to_cpu(context);
1033 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1034 break;
1036 case SLI_CTNS_RFT_ID:
1037 CtReq->CommandResponse.bits.CmdRsp =
1038 be16_to_cpu(SLI_CTNS_RFT_ID);
1039 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
1040 CtReq->un.rft.fcpReg = 1;
1041 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1042 break;
1044 case SLI_CTNS_RNN_ID:
1045 CtReq->CommandResponse.bits.CmdRsp =
1046 be16_to_cpu(SLI_CTNS_RNN_ID);
1047 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
1048 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1049 sizeof (struct lpfc_name));
1050 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1051 break;
1053 case SLI_CTNS_RSPN_ID:
1054 CtReq->CommandResponse.bits.CmdRsp =
1055 be16_to_cpu(SLI_CTNS_RSPN_ID);
1056 CtReq->un.rspn.PortId = be32_to_cpu(vport->fc_myDID);
1057 size = sizeof(CtReq->un.rspn.symbname);
1058 CtReq->un.rspn.len =
1059 lpfc_vport_symbolic_port_name(vport,
1060 CtReq->un.rspn.symbname, size);
1061 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1062 break;
1063 case SLI_CTNS_RSNN_NN:
1064 CtReq->CommandResponse.bits.CmdRsp =
1065 be16_to_cpu(SLI_CTNS_RSNN_NN);
1066 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1067 sizeof (struct lpfc_name));
1068 size = sizeof(CtReq->un.rsnn.symbname);
1069 CtReq->un.rsnn.len =
1070 lpfc_vport_symbolic_node_name(vport,
1071 CtReq->un.rsnn.symbname, size);
1072 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1073 break;
1074 case SLI_CTNS_RFF_ID:
1075 vport->fc_flag &= ~FC_RFF_NOT_SUPPORTED;
1076 CtReq->CommandResponse.bits.CmdRsp =
1077 be16_to_cpu(SLI_CTNS_RFF_ID);
1078 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);;
1079 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1080 CtReq->un.rff.type_code = FC_FCP_DATA;
1081 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1082 break;
1085 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1086 /* On success, The cmpl function will free the buffers */
1087 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1088 "Issue CT cmd: cmd:x%x did:x%x",
1089 cmdcode, ndlp->nlp_DID, 0);
1090 return 0;
1093 rc=6;
1094 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1095 ns_cmd_free_bmp:
1096 kfree(bmp);
1097 ns_cmd_free_mpvirt:
1098 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1099 ns_cmd_free_mp:
1100 kfree(mp);
1101 ns_cmd_exit:
1102 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
1103 "%d (%d):0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1104 phba->brd_no, vport->vpi, cmdcode, rc, vport->fc_flag,
1105 vport->fc_rscn_id_cnt);
1106 return 1;
1109 static void
1110 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1111 struct lpfc_iocbq * rspiocb)
1113 struct lpfc_dmabuf *inp = cmdiocb->context1;
1114 struct lpfc_dmabuf *outp = cmdiocb->context2;
1115 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1116 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1117 struct lpfc_nodelist *ndlp;
1118 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1119 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1120 struct lpfc_vport *vport = cmdiocb->vport;
1121 IOCB_t *irsp = &rspiocb->iocb;
1122 uint32_t latt;
1124 latt = lpfc_els_chk_latt(vport);
1126 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1127 "FDMI cmpl: status:x%x/x%x latt:%d",
1128 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1130 if (latt || irsp->ulpStatus) {
1131 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1132 "%d (%d):0229 FDMI cmd %04x failed, latt = %d "
1133 "ulpStatus: x%x, rid x%x\n",
1134 phba->brd_no, vport->vpi,
1135 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1136 irsp->un.ulpWord[4]);
1137 lpfc_ct_free_iocb(phba, cmdiocb);
1138 return;
1141 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1142 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1143 /* FDMI rsp failed */
1144 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1145 "%d (%d):0220 FDMI rsp failed Data: x%x\n",
1146 phba->brd_no, vport->vpi,
1147 be16_to_cpu(fdmi_cmd));
1150 switch (be16_to_cpu(fdmi_cmd)) {
1151 case SLI_MGMT_RHBA:
1152 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
1153 break;
1155 case SLI_MGMT_RPA:
1156 break;
1158 case SLI_MGMT_DHBA:
1159 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
1160 break;
1162 case SLI_MGMT_DPRT:
1163 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
1164 break;
1166 lpfc_ct_free_iocb(phba, cmdiocb);
1167 return;
1171 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
1173 struct lpfc_hba *phba = vport->phba;
1174 struct lpfc_dmabuf *mp, *bmp;
1175 struct lpfc_sli_ct_request *CtReq;
1176 struct ulp_bde64 *bpl;
1177 uint32_t size;
1178 REG_HBA *rh;
1179 PORT_ENTRY *pe;
1180 REG_PORT_ATTRIBUTE *pab;
1181 ATTRIBUTE_BLOCK *ab;
1182 ATTRIBUTE_ENTRY *ae;
1183 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1184 struct lpfc_iocbq *);
1187 /* fill in BDEs for command */
1188 /* Allocate buffer for command payload */
1189 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1190 if (!mp)
1191 goto fdmi_cmd_exit;
1193 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1194 if (!mp->virt)
1195 goto fdmi_cmd_free_mp;
1197 /* Allocate buffer for Buffer ptr list */
1198 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1199 if (!bmp)
1200 goto fdmi_cmd_free_mpvirt;
1202 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1203 if (!bmp->virt)
1204 goto fdmi_cmd_free_bmp;
1206 INIT_LIST_HEAD(&mp->list);
1207 INIT_LIST_HEAD(&bmp->list);
1209 /* FDMI request */
1210 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1211 "%d (%d):0218 FDMI Request Data: x%x x%x x%x\n",
1212 phba->brd_no, vport->vpi, vport->fc_flag,
1213 vport->port_state, cmdcode);
1215 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1217 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1218 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1219 CtReq->RevisionId.bits.InId = 0;
1221 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1222 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1223 size = 0;
1225 switch (cmdcode) {
1226 case SLI_MGMT_RHBA:
1228 lpfc_vpd_t *vp = &phba->vpd;
1229 uint32_t i, j, incr;
1230 int len;
1232 CtReq->CommandResponse.bits.CmdRsp =
1233 be16_to_cpu(SLI_MGMT_RHBA);
1234 CtReq->CommandResponse.bits.Size = 0;
1235 rh = (REG_HBA *) & CtReq->un.PortID;
1236 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
1237 sizeof (struct lpfc_name));
1238 /* One entry (port) per adapter */
1239 rh->rpl.EntryCnt = be32_to_cpu(1);
1240 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
1241 sizeof (struct lpfc_name));
1243 /* point to the HBA attribute block */
1244 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1245 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1246 ab->EntryCnt = 0;
1248 /* Point to the beginning of the first HBA attribute
1249 entry */
1250 /* #1 HBA attribute entry */
1251 size += FOURBYTES;
1252 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1253 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1254 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1255 + sizeof (struct lpfc_name));
1256 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
1257 sizeof (struct lpfc_name));
1258 ab->EntryCnt++;
1259 size += FOURBYTES + sizeof (struct lpfc_name);
1261 /* #2 HBA attribute entry */
1262 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1263 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1264 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1265 len = strlen(ae->un.Manufacturer);
1266 len += (len & 3) ? (4 - (len & 3)) : 4;
1267 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1268 ab->EntryCnt++;
1269 size += FOURBYTES + len;
1271 /* #3 HBA attribute entry */
1272 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1273 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1274 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1275 len = strlen(ae->un.SerialNumber);
1276 len += (len & 3) ? (4 - (len & 3)) : 4;
1277 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1278 ab->EntryCnt++;
1279 size += FOURBYTES + len;
1281 /* #4 HBA attribute entry */
1282 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1283 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1284 strcpy(ae->un.Model, phba->ModelName);
1285 len = strlen(ae->un.Model);
1286 len += (len & 3) ? (4 - (len & 3)) : 4;
1287 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1288 ab->EntryCnt++;
1289 size += FOURBYTES + len;
1291 /* #5 HBA attribute entry */
1292 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1293 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1294 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1295 len = strlen(ae->un.ModelDescription);
1296 len += (len & 3) ? (4 - (len & 3)) : 4;
1297 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1298 ab->EntryCnt++;
1299 size += FOURBYTES + len;
1301 /* #6 HBA attribute entry */
1302 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1303 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1304 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1305 /* Convert JEDEC ID to ascii for hardware version */
1306 incr = vp->rev.biuRev;
1307 for (i = 0; i < 8; i++) {
1308 j = (incr & 0xf);
1309 if (j <= 9)
1310 ae->un.HardwareVersion[7 - i] =
1311 (char)((uint8_t) 0x30 +
1312 (uint8_t) j);
1313 else
1314 ae->un.HardwareVersion[7 - i] =
1315 (char)((uint8_t) 0x61 +
1316 (uint8_t) (j - 10));
1317 incr = (incr >> 4);
1319 ab->EntryCnt++;
1320 size += FOURBYTES + 8;
1322 /* #7 HBA attribute entry */
1323 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1324 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1325 strcpy(ae->un.DriverVersion, lpfc_release_version);
1326 len = strlen(ae->un.DriverVersion);
1327 len += (len & 3) ? (4 - (len & 3)) : 4;
1328 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1329 ab->EntryCnt++;
1330 size += FOURBYTES + len;
1332 /* #8 HBA attribute entry */
1333 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1334 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1335 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1336 len = strlen(ae->un.OptionROMVersion);
1337 len += (len & 3) ? (4 - (len & 3)) : 4;
1338 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1339 ab->EntryCnt++;
1340 size += FOURBYTES + len;
1342 /* #9 HBA attribute entry */
1343 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1344 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1345 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1347 len = strlen(ae->un.FirmwareVersion);
1348 len += (len & 3) ? (4 - (len & 3)) : 4;
1349 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1350 ab->EntryCnt++;
1351 size += FOURBYTES + len;
1353 /* #10 HBA attribute entry */
1354 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1355 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1356 sprintf(ae->un.OsNameVersion, "%s %s %s",
1357 init_utsname()->sysname,
1358 init_utsname()->release,
1359 init_utsname()->version);
1360 len = strlen(ae->un.OsNameVersion);
1361 len += (len & 3) ? (4 - (len & 3)) : 4;
1362 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1363 ab->EntryCnt++;
1364 size += FOURBYTES + len;
1366 /* #11 HBA attribute entry */
1367 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1368 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1369 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1370 ae->un.MaxCTPayloadLen = (65 * 4096);
1371 ab->EntryCnt++;
1372 size += FOURBYTES + 4;
1374 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1375 /* Total size */
1376 size = GID_REQUEST_SZ - 4 + size;
1378 break;
1380 case SLI_MGMT_RPA:
1382 lpfc_vpd_t *vp;
1383 struct serv_parm *hsp;
1384 int len;
1386 vp = &phba->vpd;
1388 CtReq->CommandResponse.bits.CmdRsp =
1389 be16_to_cpu(SLI_MGMT_RPA);
1390 CtReq->CommandResponse.bits.Size = 0;
1391 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1392 size = sizeof (struct lpfc_name) + FOURBYTES;
1393 memcpy((uint8_t *) & pab->PortName,
1394 (uint8_t *) & vport->fc_sparam.portName,
1395 sizeof (struct lpfc_name));
1396 pab->ab.EntryCnt = 0;
1398 /* #1 Port attribute entry */
1399 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1400 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1401 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1402 ae->un.SupportFC4Types[2] = 1;
1403 ae->un.SupportFC4Types[7] = 1;
1404 pab->ab.EntryCnt++;
1405 size += FOURBYTES + 32;
1407 /* #2 Port attribute entry */
1408 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1409 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1410 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1412 ae->un.SupportSpeed = 0;
1413 if (phba->lmt & LMT_10Gb)
1414 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1415 if (phba->lmt & LMT_8Gb)
1416 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1417 if (phba->lmt & LMT_4Gb)
1418 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1419 if (phba->lmt & LMT_2Gb)
1420 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1421 if (phba->lmt & LMT_1Gb)
1422 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1424 pab->ab.EntryCnt++;
1425 size += FOURBYTES + 4;
1427 /* #3 Port attribute entry */
1428 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1429 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1430 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1431 switch(phba->fc_linkspeed) {
1432 case LA_1GHZ_LINK:
1433 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1434 break;
1435 case LA_2GHZ_LINK:
1436 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1437 break;
1438 case LA_4GHZ_LINK:
1439 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1440 break;
1441 case LA_8GHZ_LINK:
1442 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1443 break;
1444 default:
1445 ae->un.PortSpeed =
1446 HBA_PORTSPEED_UNKNOWN;
1447 break;
1449 pab->ab.EntryCnt++;
1450 size += FOURBYTES + 4;
1452 /* #4 Port attribute entry */
1453 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1454 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1455 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1456 hsp = (struct serv_parm *) & vport->fc_sparam;
1457 ae->un.MaxFrameSize =
1458 (((uint32_t) hsp->cmn.
1459 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1460 bbRcvSizeLsb;
1461 pab->ab.EntryCnt++;
1462 size += FOURBYTES + 4;
1464 /* #5 Port attribute entry */
1465 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1466 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1467 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1468 len = strlen((char *)ae->un.OsDeviceName);
1469 len += (len & 3) ? (4 - (len & 3)) : 4;
1470 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1471 pab->ab.EntryCnt++;
1472 size += FOURBYTES + len;
1474 if (phba->cfg_fdmi_on == 2) {
1475 /* #6 Port attribute entry */
1476 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1477 size);
1478 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1479 sprintf(ae->un.HostName, "%s",
1480 init_utsname()->nodename);
1481 len = strlen(ae->un.HostName);
1482 len += (len & 3) ? (4 - (len & 3)) : 4;
1483 ae->ad.bits.AttrLen =
1484 be16_to_cpu(FOURBYTES + len);
1485 pab->ab.EntryCnt++;
1486 size += FOURBYTES + len;
1489 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1490 /* Total size */
1491 size = GID_REQUEST_SZ - 4 + size;
1493 break;
1495 case SLI_MGMT_DHBA:
1496 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1497 CtReq->CommandResponse.bits.Size = 0;
1498 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1499 memcpy((uint8_t *) & pe->PortName,
1500 (uint8_t *) & vport->fc_sparam.portName,
1501 sizeof (struct lpfc_name));
1502 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1503 break;
1505 case SLI_MGMT_DPRT:
1506 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1507 CtReq->CommandResponse.bits.Size = 0;
1508 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1509 memcpy((uint8_t *) & pe->PortName,
1510 (uint8_t *) & vport->fc_sparam.portName,
1511 sizeof (struct lpfc_name));
1512 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1513 break;
1516 bpl = (struct ulp_bde64 *) bmp->virt;
1517 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1518 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1519 bpl->tus.f.bdeFlags = 0;
1520 bpl->tus.f.bdeSize = size;
1521 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1523 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1525 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
1526 return 0;
1528 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1529 fdmi_cmd_free_bmp:
1530 kfree(bmp);
1531 fdmi_cmd_free_mpvirt:
1532 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1533 fdmi_cmd_free_mp:
1534 kfree(mp);
1535 fdmi_cmd_exit:
1536 /* Issue FDMI request failed */
1537 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1538 "%d (%d):0244 Issue FDMI request failed Data: x%x\n",
1539 phba->brd_no, vport->vpi, cmdcode);
1540 return 1;
1543 void
1544 lpfc_fdmi_tmo(unsigned long ptr)
1546 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1547 struct lpfc_hba *phba = vport->phba;
1548 unsigned long iflag;
1550 spin_lock_irqsave(&vport->work_port_lock, iflag);
1551 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1552 vport->work_port_events |= WORKER_FDMI_TMO;
1553 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1555 spin_lock_irqsave(&phba->hbalock, iflag);
1556 if (phba->work_wait)
1557 lpfc_worker_wake_up(phba);
1558 spin_unlock_irqrestore(&phba->hbalock, iflag);
1560 else
1561 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1564 void
1565 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1567 struct lpfc_nodelist *ndlp;
1569 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1570 if (ndlp) {
1571 if (init_utsname()->nodename[0] != '\0')
1572 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1573 else
1574 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1576 return;
1579 void
1580 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1582 struct lpfc_sli *psli = &phba->sli;
1583 lpfc_vpd_t *vp = &phba->vpd;
1584 uint32_t b1, b2, b3, b4, i, rev;
1585 char c;
1586 uint32_t *ptr, str[4];
1587 uint8_t *fwname;
1589 if (vp->rev.rBit) {
1590 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1591 rev = vp->rev.sli2FwRev;
1592 else
1593 rev = vp->rev.sli1FwRev;
1595 b1 = (rev & 0x0000f000) >> 12;
1596 b2 = (rev & 0x00000f00) >> 8;
1597 b3 = (rev & 0x000000c0) >> 6;
1598 b4 = (rev & 0x00000030) >> 4;
1600 switch (b4) {
1601 case 0:
1602 c = 'N';
1603 break;
1604 case 1:
1605 c = 'A';
1606 break;
1607 case 2:
1608 c = 'B';
1609 break;
1610 default:
1611 c = 0;
1612 break;
1614 b4 = (rev & 0x0000000f);
1616 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1617 fwname = vp->rev.sli2FwName;
1618 else
1619 fwname = vp->rev.sli1FwName;
1621 for (i = 0; i < 16; i++)
1622 if (fwname[i] == 0x20)
1623 fwname[i] = 0;
1625 ptr = (uint32_t*)fwname;
1627 for (i = 0; i < 3; i++)
1628 str[i] = be32_to_cpu(*ptr++);
1630 if (c == 0) {
1631 if (flag)
1632 sprintf(fwrevision, "%d.%d%d (%s)",
1633 b1, b2, b3, (char *)str);
1634 else
1635 sprintf(fwrevision, "%d.%d%d", b1,
1636 b2, b3);
1637 } else {
1638 if (flag)
1639 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1640 b1, b2, b3, c,
1641 b4, (char *)str);
1642 else
1643 sprintf(fwrevision, "%d.%d%d%c%d",
1644 b1, b2, b3, c, b4);
1646 } else {
1647 rev = vp->rev.smFwRev;
1649 b1 = (rev & 0xff000000) >> 24;
1650 b2 = (rev & 0x00f00000) >> 20;
1651 b3 = (rev & 0x000f0000) >> 16;
1652 c = (rev & 0x0000ff00) >> 8;
1653 b4 = (rev & 0x000000ff);
1655 if (flag)
1656 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1657 b2, b3, c, b4);
1658 else
1659 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1660 b2, b3, c, b4);
1662 return;