[SCSI] aacraid: improve queue balancing
[linux-2.6-block.git] / drivers / scsi / lpfc / lpfc_ct.c
CommitLineData
dea3101e 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
9413afff 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
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. *
dea3101e 19 *******************************************************************/
20
21/*
dea3101e 22 * 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
91886523 30#include <scsi/scsi.h>
dea3101e 31#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h>
f888ba3c 33#include <scsi/scsi_transport_fc.h>
dea3101e 34
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"
92d7f7b0 43#include "lpfc_vport.h"
858c9f6c 44#include "lpfc_debugfs.h"
dea3101e 45
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 */
54
55#define FOURBYTES 4
56
57
58static char *lpfc_release_version = LPFC_DRIVER_VERSION;
59
60/*
61 * lpfc_ct_unsol_event
62 */
ed957684
JS
63static void
64lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
65 struct lpfc_dmabuf *mp, uint32_t size)
66{
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);
72 }
73
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);
92d7f7b0 79
ed957684
JS
80}
81
82static void
83lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
92d7f7b0 84 struct lpfc_dmabuf *mp, uint32_t size)
ed957684 85{
ed957684
JS
86 if (!mp) {
87 printk(KERN_ERR "%s (%d): Unsolited CT, no "
88 "HBQ buffer, piocbq = %p, status = x%x\n",
89 __FUNCTION__, __LINE__,
90 piocbq, piocbq->iocb.ulpStatus);
91 } else {
92 lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
93 printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
94 "piocbq = %p, buffer = %p, size = %d, "
95 "status = x%x\n",
96 __FUNCTION__, __LINE__,
97 piocbq, mp, size, piocbq->iocb.ulpStatus);
98 }
99}
100
dea3101e 101void
2e0fef85
JS
102lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
103 struct lpfc_iocbq *piocbq)
dea3101e 104{
92d7f7b0 105
ed957684 106 struct lpfc_dmabuf *mp = NULL;
dea3101e 107 IOCB_t *icmd = &piocbq->iocb;
ed957684
JS
108 int i;
109 struct lpfc_iocbq *iocbq;
110 dma_addr_t paddr;
111 uint32_t size;
92d7f7b0
JS
112 struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
113 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
114
115 piocbq->context2 = NULL;
116 piocbq->context3 = NULL;
dea3101e 117
92d7f7b0
JS
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)) {
dea3101e 122 /* Not enough posted buffers; Try posting more buffers */
123 phba->fc_stat.NoRcvBuf++;
92d7f7b0 124 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
ed957684 125 lpfc_post_buffer(phba, pring, 0, 1);
dea3101e 126 return;
127 }
128
129 /* If there are no BDEs associated with this IOCB,
130 * there is nothing to do.
131 */
132 if (icmd->ulpBdeCount == 0)
133 return;
134
ed957684
JS
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;
dea3101e 144 }
145
ed957684 146 size = icmd->un.cont64[0].tus.f.bdeSize;
92d7f7b0
JS
147 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf1, size);
148 lpfc_in_buf_free(phba, bdeBuf1);
ed957684 149 if (icmd->ulpBdeCount == 2) {
92d7f7b0 150 lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf2,
ed957684 151 size);
92d7f7b0 152 lpfc_in_buf_free(phba, bdeBuf2);
ed957684 153 }
dea3101e 154 }
ed957684
JS
155 } else {
156 struct lpfc_iocbq *next;
157
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;
166 }
dea3101e 167
ed957684
JS
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);
92d7f7b0 175 lpfc_in_buf_free(phba, mp);
ed957684
JS
176 }
177 list_del(&iocbq->list);
178 lpfc_sli_release_iocbq(phba, iocbq);
dea3101e 179 }
dea3101e 180 }
dea3101e 181}
182
183static void
2e0fef85 184lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
dea3101e 185{
186 struct lpfc_dmabuf *mlast, *next_mlast;
187
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);
192 }
193 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
194 kfree(mlist);
195 return;
196}
197
198static struct lpfc_dmabuf *
2e0fef85 199lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
dea3101e 200 uint32_t size, int *entries)
201{
202 struct lpfc_dmabuf *mlist = NULL;
203 struct lpfc_dmabuf *mp;
204 int cnt, i = 0;
205
206 /* We get chucks of FCELSSIZE */
207 cnt = size > FCELSSIZE ? FCELSSIZE: size;
208
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;
216 }
217
218 INIT_LIST_HEAD(&mp->list);
219
92d7f7b0
JS
220 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
221 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
dea3101e 222 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
223 else
224 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
225
226 if (!mp->virt) {
227 kfree(mp);
0b3a82d3
ES
228 if (mlist)
229 lpfc_free_ct_rsp(phba, mlist);
dea3101e 230 return NULL;
231 }
232
233 /* Queue it to a linked list */
234 if (!mlist)
235 mlist = mp;
236 else
237 list_add_tail(&mp->list, &mlist->list);
238
239 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
240 /* build buffer ptr list for IOCB */
92d7f7b0
JS
241 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
242 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
dea3101e 243 bpl->tus.f.bdeSize = (uint16_t) cnt;
244 bpl->tus.w = le32_to_cpu(bpl->tus.w);
245 bpl++;
246
247 i++;
248 size -= cnt;
249 }
250
251 *entries = i;
252 return mlist;
253}
254
858c9f6c
JS
255int
256lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
257{
258 struct lpfc_dmabuf *buf_ptr;
259
51ef4c26
JS
260 if (ctiocb->context_un.ndlp) {
261 lpfc_nlp_put(ctiocb->context_un.ndlp);
262 ctiocb->context_un.ndlp = NULL;
263 }
858c9f6c
JS
264 if (ctiocb->context1) {
265 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
266 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
267 kfree(buf_ptr);
268 ctiocb->context1 = NULL;
269 }
270 if (ctiocb->context2) {
271 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
272 ctiocb->context2 = NULL;
273 }
274
275 if (ctiocb->context3) {
276 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
277 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
278 kfree(buf_ptr);
279 ctiocb->context1 = NULL;
280 }
281 lpfc_sli_release_iocbq(phba, ctiocb);
282 return 0;
283}
284
dea3101e 285static int
2e0fef85 286lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
dea3101e 287 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
288 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
289 struct lpfc_iocbq *),
290 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
92d7f7b0 291 uint32_t tmo, uint8_t retry)
dea3101e 292{
2e0fef85
JS
293 struct lpfc_hba *phba = vport->phba;
294 struct lpfc_sli *psli = &phba->sli;
dea3101e 295 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea3101e 296 IOCB_t *icmd;
0bd4ca25 297 struct lpfc_iocbq *geniocb;
92d7f7b0 298 int rc;
dea3101e 299
300 /* Allocate buffer for command iocb */
0bd4ca25 301 geniocb = lpfc_sli_get_iocbq(phba);
dea3101e 302
303 if (geniocb == NULL)
304 return 1;
dea3101e 305
306 icmd = &geniocb->iocb;
307 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
308 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
309 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
310 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
311 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
312
313 if (usr_flg)
314 geniocb->context3 = NULL;
315 else
316 geniocb->context3 = (uint8_t *) bmp;
317
318 /* Save for completion so we can release these resources */
319 geniocb->context1 = (uint8_t *) inp;
320 geniocb->context2 = (uint8_t *) outp;
51ef4c26 321 geniocb->context_un.ndlp = ndlp;
dea3101e 322
323 /* Fill in payload, bp points to frame payload */
324 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
325
326 /* Fill in rest of iocb */
327 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
328 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
329 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
330 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
331
c9f8735b
JW
332 if (!tmo) {
333 /* FC spec states we need 3 * ratov for CT requests */
334 tmo = (3 * phba->fc_ratov);
335 }
dea3101e 336 icmd->ulpTimeout = tmo;
337 icmd->ulpBdeCount = 1;
338 icmd->ulpLe = 1;
339 icmd->ulpClass = CLASS3;
340 icmd->ulpContext = ndlp->nlp_rpi;
341
92d7f7b0
JS
342 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
343 /* For GEN_REQUEST64_CR, use the RPI */
344 icmd->ulpCt_h = 0;
345 icmd->ulpCt_l = 0;
346 }
347
dea3101e 348 /* Issue GEN REQ IOCB for NPORT <did> */
e8b62011
JS
349 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
350 "0119 Issue GEN REQ IOCB to NPORT x%x "
351 "Data: x%x x%x\n",
352 ndlp->nlp_DID, icmd->ulpIoTag,
353 vport->port_state);
dea3101e 354 geniocb->iocb_cmpl = cmpl;
355 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
2e0fef85 356 geniocb->vport = vport;
92d7f7b0
JS
357 geniocb->retry = retry;
358 rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
359
360 if (rc == IOCB_ERROR) {
604a3e30 361 lpfc_sli_release_iocbq(phba, geniocb);
dea3101e 362 return 1;
363 }
dea3101e 364
365 return 0;
366}
367
368static int
2e0fef85 369lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
dea3101e 370 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
371 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
372 struct lpfc_iocbq *),
92d7f7b0 373 uint32_t rsp_size, uint8_t retry)
dea3101e 374{
2e0fef85 375 struct lpfc_hba *phba = vport->phba;
dea3101e 376 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
377 struct lpfc_dmabuf *outmp;
378 int cnt = 0, status;
379 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
380 CommandResponse.bits.CmdRsp;
381
382 bpl++; /* Skip past ct request */
383
384 /* Put buffer(s) for ct rsp in bpl */
385 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
386 if (!outmp)
387 return -ENOMEM;
388
2e0fef85 389 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
92d7f7b0 390 cnt+1, 0, retry);
dea3101e 391 if (status) {
392 lpfc_free_ct_rsp(phba, outmp);
393 return -ENOMEM;
394 }
395 return 0;
396}
397
549e55cd 398struct lpfc_vport *
92d7f7b0 399lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
92d7f7b0 400 struct lpfc_vport *vport_curr;
549e55cd 401 unsigned long flags;
92d7f7b0 402
549e55cd 403 spin_lock_irqsave(&phba->hbalock, flags);
92d7f7b0 404 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
549e55cd
JS
405 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
406 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0 407 return vport_curr;
549e55cd 408 }
92d7f7b0 409 }
549e55cd 410 spin_unlock_irqrestore(&phba->hbalock, flags);
92d7f7b0
JS
411 return NULL;
412}
413
dea3101e 414static int
2e0fef85 415lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
dea3101e 416{
2e0fef85 417 struct lpfc_hba *phba = vport->phba;
dea3101e 418 struct lpfc_sli_ct_request *Response =
419 (struct lpfc_sli_ct_request *) mp->virt;
420 struct lpfc_nodelist *ndlp = NULL;
421 struct lpfc_dmabuf *mlast, *next_mp;
422 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
2e0fef85 423 uint32_t Did, CTentry;
dea3101e 424 int Cnt;
425 struct list_head head;
426
2e0fef85 427 lpfc_set_disctmo(vport);
92d7f7b0 428 vport->num_disc_nodes = 0;
dea3101e 429
dea3101e 430
431 list_add_tail(&head, &mp->list);
432 list_for_each_entry_safe(mp, next_mp, &head, list) {
433 mlast = mp;
434
7054a606
JS
435 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
436
dea3101e 437 Size -= Cnt;
438
1dcb58e5 439 if (!ctptr) {
dea3101e 440 ctptr = (uint32_t *) mlast->virt;
1dcb58e5 441 } else
dea3101e 442 Cnt -= 16; /* subtract length of CT header */
443
444 /* Loop through entire NameServer list of DIDs */
7054a606 445 while (Cnt >= sizeof (uint32_t)) {
dea3101e 446 /* Get next DID from NameServer List */
447 CTentry = *ctptr++;
448 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
92d7f7b0 449
dea3101e 450 ndlp = NULL;
92d7f7b0
JS
451
452 /*
453 * Check for rscn processing or not
454 * To conserve rpi's, filter out addresses for other
455 * vports on the same physical HBAs.
456 */
457 if ((Did != vport->fc_myDID) &&
458 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
3de2a653 459 vport->cfg_peer_port_login)) {
92d7f7b0 460 if ((vport->port_type != LPFC_NPIV_PORT) ||
98c9ea5c 461 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
3de2a653 462 (!vport->cfg_restrict_login)) {
92d7f7b0
JS
463 ndlp = lpfc_setup_disc_node(vport, Did);
464 if (ndlp) {
858c9f6c
JS
465 lpfc_debugfs_disc_trc(vport,
466 LPFC_DISC_TRC_CT,
467 "Parse GID_FTrsp: "
468 "did:x%x flg:x%x x%x",
469 Did, ndlp->nlp_flag,
470 vport->fc_flag);
471
e8b62011
JS
472 lpfc_printf_vlog(vport,
473 KERN_INFO,
92d7f7b0 474 LOG_DISCOVERY,
e8b62011 475 "0238 Process "
92d7f7b0
JS
476 "x%x NameServer Rsp"
477 "Data: x%x x%x x%x\n",
e8b62011 478 Did, ndlp->nlp_flag,
92d7f7b0
JS
479 vport->fc_flag,
480 vport->fc_rscn_id_cnt);
481 } else {
858c9f6c
JS
482 lpfc_debugfs_disc_trc(vport,
483 LPFC_DISC_TRC_CT,
484 "Skip1 GID_FTrsp: "
485 "did:x%x flg:x%x cnt:%d",
486 Did, vport->fc_flag,
487 vport->fc_rscn_id_cnt);
488
e8b62011
JS
489 lpfc_printf_vlog(vport,
490 KERN_INFO,
92d7f7b0 491 LOG_DISCOVERY,
e8b62011 492 "0239 Skip x%x "
92d7f7b0
JS
493 "NameServer Rsp Data: "
494 "x%x x%x\n",
e8b62011 495 Did, vport->fc_flag,
92d7f7b0
JS
496 vport->fc_rscn_id_cnt);
497 }
498
499 } else {
500 if (!(vport->fc_flag & FC_RSCN_MODE) ||
501 (lpfc_rscn_payload_check(vport, Did))) {
858c9f6c
JS
502 lpfc_debugfs_disc_trc(vport,
503 LPFC_DISC_TRC_CT,
504 "Query GID_FTrsp: "
505 "did:x%x flg:x%x cnt:%d",
506 Did, vport->fc_flag,
507 vport->fc_rscn_id_cnt);
508
92d7f7b0
JS
509 if (lpfc_ns_cmd(vport,
510 SLI_CTNS_GFF_ID,
511 0, Did) == 0)
512 vport->num_disc_nodes++;
513 }
514 else {
858c9f6c
JS
515 lpfc_debugfs_disc_trc(vport,
516 LPFC_DISC_TRC_CT,
517 "Skip2 GID_FTrsp: "
518 "did:x%x flg:x%x cnt:%d",
519 Did, vport->fc_flag,
520 vport->fc_rscn_id_cnt);
521
e8b62011
JS
522 lpfc_printf_vlog(vport,
523 KERN_INFO,
92d7f7b0 524 LOG_DISCOVERY,
e8b62011 525 "0245 Skip x%x "
92d7f7b0
JS
526 "NameServer Rsp Data: "
527 "x%x x%x\n",
e8b62011 528 Did, vport->fc_flag,
92d7f7b0
JS
529 vport->fc_rscn_id_cnt);
530 }
531 }
dea3101e 532 }
dea3101e 533 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
534 goto nsout1;
535 Cnt -= sizeof (uint32_t);
536 }
537 ctptr = NULL;
538
539 }
540
541nsout1:
542 list_del(&head);
dea3101e 543 return 0;
544}
545
dea3101e 546static void
2e0fef85
JS
547lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
548 struct lpfc_iocbq *rspiocb)
dea3101e 549{
2e0fef85 550 struct lpfc_vport *vport = cmdiocb->vport;
92d7f7b0 551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 552 IOCB_t *irsp;
dea3101e 553 struct lpfc_dmabuf *bmp;
dea3101e 554 struct lpfc_dmabuf *outp;
dea3101e 555 struct lpfc_sli_ct_request *CTrsp;
51ef4c26 556 struct lpfc_nodelist *ndlp;
2e0fef85 557 int rc;
dea3101e 558
51ef4c26
JS
559 /* First save ndlp, before we overwrite it */
560 ndlp = cmdiocb->context_un.ndlp;
561
dea3101e 562 /* we pass cmdiocb to state machine which needs rspiocb as well */
563 cmdiocb->context_un.rsp_iocb = rspiocb;
564
dea3101e 565 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
566 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
858c9f6c
JS
567 irsp = &rspiocb->iocb;
568
569 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
570 "GID_FT cmpl: status:x%x/x%x rtry:%d",
571 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
dea3101e 572
92d7f7b0
JS
573 /* Don't bother processing response if vport is being torn down. */
574 if (vport->load_flag & FC_UNLOADING)
575 goto out;
576
dea3101e 577
858c9f6c 578 if (lpfc_els_chk_latt(vport) || lpfc_error_lost_link(irsp)) {
e8b62011
JS
579 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
580 "0216 Link event during NS query\n");
858c9f6c
JS
581 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
582 goto out;
583 }
584
585 if (irsp->ulpStatus) {
dea3101e 586 /* Check for retry */
2e0fef85 587 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
858c9f6c
JS
588 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
589 (irsp->un.ulpWord[4] != IOERR_NO_RESOURCES))
590 vport->fc_ns_retry++;
dea3101e 591 /* CT command is being retried */
92d7f7b0
JS
592 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
593 vport->fc_ns_retry, 0);
594 if (rc == 0)
595 goto out;
596 }
92d7f7b0 597 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
e8b62011
JS
598 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
599 "0257 GID_FT Query error: 0x%x 0x%x\n",
600 irsp->ulpStatus, vport->fc_ns_retry);
dea3101e 601 } else {
602 /* Good status, continue checking */
603 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
604 if (CTrsp->CommandResponse.bits.CmdRsp ==
605 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
e8b62011
JS
606 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
607 "0208 NameServer Rsp Data: x%x\n",
608 vport->fc_flag);
2e0fef85 609 lpfc_ns_rsp(vport, outp,
dea3101e 610 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
611 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
612 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
613 /* NameServer Rsp Error */
a58cbd52
JS
614 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
615 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
e8b62011
JS
616 lpfc_printf_vlog(vport, KERN_INFO,
617 LOG_DISCOVERY,
618 "0269 No NameServer Entries "
a58cbd52 619 "Data: x%x x%x x%x x%x\n",
a58cbd52
JS
620 CTrsp->CommandResponse.bits.CmdRsp,
621 (uint32_t) CTrsp->ReasonCode,
622 (uint32_t) CTrsp->Explanation,
623 vport->fc_flag);
624
625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
626 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
627 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
628 (uint32_t) CTrsp->ReasonCode,
629 (uint32_t) CTrsp->Explanation);
e8b62011
JS
630 } else {
631 lpfc_printf_vlog(vport, KERN_INFO,
632 LOG_DISCOVERY,
633 "0240 NameServer Rsp Error "
dea3101e 634 "Data: x%x x%x x%x x%x\n",
dea3101e 635 CTrsp->CommandResponse.bits.CmdRsp,
636 (uint32_t) CTrsp->ReasonCode,
637 (uint32_t) CTrsp->Explanation,
2e0fef85 638 vport->fc_flag);
858c9f6c 639
a58cbd52 640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
858c9f6c
JS
641 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
642 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
643 (uint32_t) CTrsp->ReasonCode,
644 (uint32_t) CTrsp->Explanation);
a58cbd52
JS
645 }
646
858c9f6c 647
dea3101e 648 } else {
649 /* NameServer Rsp Error */
e8b62011
JS
650 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
651 "0241 NameServer Rsp Error "
dea3101e 652 "Data: x%x x%x x%x x%x\n",
dea3101e 653 CTrsp->CommandResponse.bits.CmdRsp,
654 (uint32_t) CTrsp->ReasonCode,
655 (uint32_t) CTrsp->Explanation,
2e0fef85 656 vport->fc_flag);
858c9f6c
JS
657
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);
dea3101e 663 }
664 }
665 /* Link up / RSCN discovery */
92d7f7b0
JS
666 if (vport->num_disc_nodes == 0) {
667 /*
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.
671 */
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);
678 }
679 else
680 lpfc_els_flush_rscn(vport);
681 }
682
683 lpfc_disc_start(vport);
684 }
685out:
51ef4c26 686 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 687 lpfc_ct_free_iocb(phba, cmdiocb);
92d7f7b0
JS
688 return;
689}
690
311464ec 691static void
92d7f7b0
JS
692lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
693 struct lpfc_iocbq *rspiocb)
694{
695 struct lpfc_vport *vport = cmdiocb->vport;
696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
697 IOCB_t *irsp = &rspiocb->iocb;
92d7f7b0
JS
698 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
699 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
700 struct lpfc_sli_ct_request *CTrsp;
701 int did;
702 uint8_t fbits;
703 struct lpfc_nodelist *ndlp;
704
705 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
706 did = be32_to_cpu(did);
707
858c9f6c
JS
708 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
709 "GFF_ID cmpl: status:x%x/x%x did:x%x",
710 irsp->ulpStatus, irsp->un.ulpWord[4], did);
711
92d7f7b0
JS
712 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
713 /* Good status, continue checking */
714 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
715 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
716
717 if (CTrsp->CommandResponse.bits.CmdRsp ==
718 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
719 if ((fbits & FC4_FEATURE_INIT) &&
720 !(fbits & FC4_FEATURE_TARGET)) {
e8b62011
JS
721 lpfc_printf_vlog(vport, KERN_INFO,
722 LOG_DISCOVERY,
723 "0270 Skip x%x GFF "
724 "NameServer Rsp Data: (init) "
725 "x%x x%x\n", did, fbits,
726 vport->fc_rscn_id_cnt);
92d7f7b0
JS
727 goto out;
728 }
729 }
730 }
858c9f6c 731 else {
e8b62011
JS
732 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
733 "0267 NameServer GFF Rsp "
734 "x%x Error (%d %d) Data: x%x x%x\n",
735 did, irsp->ulpStatus, irsp->un.ulpWord[4],
736 vport->fc_flag, vport->fc_rscn_id_cnt)
858c9f6c
JS
737 }
738
92d7f7b0
JS
739 /* This is a target port, unregistered port, or the GFF_ID failed */
740 ndlp = lpfc_setup_disc_node(vport, did);
741 if (ndlp) {
e8b62011
JS
742 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
743 "0242 Process x%x GFF "
744 "NameServer Rsp Data: x%x x%x x%x\n",
745 did, ndlp->nlp_flag, vport->fc_flag,
746 vport->fc_rscn_id_cnt);
92d7f7b0 747 } else {
e8b62011
JS
748 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
749 "0243 Skip x%x GFF "
750 "NameServer Rsp Data: x%x x%x\n", did,
751 vport->fc_flag, vport->fc_rscn_id_cnt);
92d7f7b0 752 }
dea3101e 753out:
92d7f7b0
JS
754 /* Link up / RSCN discovery */
755 if (vport->num_disc_nodes)
756 vport->num_disc_nodes--;
757 if (vport->num_disc_nodes == 0) {
758 /*
759 * The driver has cycled through all Nports in the RSCN payload.
760 * Complete the handling by cleaning up and marking the
761 * current driver state.
762 */
763 if (vport->port_state >= LPFC_DISC_AUTH) {
764 if (vport->fc_flag & FC_RSCN_MODE) {
765 lpfc_els_flush_rscn(vport);
766 spin_lock_irq(shost->host_lock);
767 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
768 spin_unlock_irq(shost->host_lock);
769 }
770 else
771 lpfc_els_flush_rscn(vport);
772 }
773 lpfc_disc_start(vport);
774 }
858c9f6c 775 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e 776 return;
777}
778
92d7f7b0 779
dea3101e 780static void
7ee5d43e
JS
781lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
782 struct lpfc_iocbq *rspiocb)
dea3101e 783{
92d7f7b0 784 struct lpfc_vport *vport = cmdiocb->vport;
dea3101e 785 struct lpfc_dmabuf *inp;
786 struct lpfc_dmabuf *outp;
787 IOCB_t *irsp;
788 struct lpfc_sli_ct_request *CTrsp;
51ef4c26 789 struct lpfc_nodelist *ndlp;
92d7f7b0
JS
790 int cmdcode, rc;
791 uint8_t retry;
858c9f6c 792 uint32_t latt;
dea3101e 793
51ef4c26
JS
794 /* First save ndlp, before we overwrite it */
795 ndlp = cmdiocb->context_un.ndlp;
796
dea3101e 797 /* we pass cmdiocb to state machine which needs rspiocb as well */
798 cmdiocb->context_un.rsp_iocb = rspiocb;
799
800 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
801 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
dea3101e 802 irsp = &rspiocb->iocb;
803
92d7f7b0
JS
804 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
805 CommandResponse.bits.CmdRsp);
dea3101e 806 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
807
858c9f6c
JS
808 latt = lpfc_els_chk_latt(vport);
809
810 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
e8b62011 811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7ee5d43e 812 "0209 CT Request completes, latt %d, "
e8b62011
JS
813 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
814 latt, irsp->ulpStatus,
815 CTrsp->CommandResponse.bits.CmdRsp,
816 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
dea3101e 817
858c9f6c
JS
818 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
819 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
820 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
821
92d7f7b0 822 if (irsp->ulpStatus) {
e8b62011
JS
823 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
824 "0268 NS cmd %x Error (%d %d)\n",
825 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
858c9f6c 826
92d7f7b0
JS
827 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
828 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
829 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
830 goto out;
831
832 retry = cmdiocb->retry;
833 if (retry >= LPFC_MAX_NS_RETRY)
834 goto out;
835
836 retry++;
e8b62011
JS
837 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
838 "0216 Retrying NS cmd %x\n", cmdcode);
92d7f7b0
JS
839 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
840 if (rc == 0)
841 goto out;
842 }
843
844out:
51ef4c26 845 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858c9f6c 846 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e 847 return;
848}
849
7ee5d43e
JS
850static void
851lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
852 struct lpfc_iocbq *rspiocb)
853{
854 IOCB_t *irsp = &rspiocb->iocb;
855 struct lpfc_vport *vport = cmdiocb->vport;
856
98c9ea5c
JS
857 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
858 struct lpfc_dmabuf *outp;
859 struct lpfc_sli_ct_request *CTrsp;
860
861 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
862 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
863 if (CTrsp->CommandResponse.bits.CmdRsp ==
864 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
865 vport->ct_flags |= FC_CT_RFT_ID;
866 }
7ee5d43e
JS
867 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
868 return;
869}
870
dea3101e 871static void
2e0fef85
JS
872lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
873 struct lpfc_iocbq *rspiocb)
dea3101e 874{
7ee5d43e
JS
875 IOCB_t *irsp = &rspiocb->iocb;
876 struct lpfc_vport *vport = cmdiocb->vport;
877
98c9ea5c
JS
878 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
879 struct lpfc_dmabuf *outp;
880 struct lpfc_sli_ct_request *CTrsp;
881
882 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
883 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
884 if (CTrsp->CommandResponse.bits.CmdRsp ==
885 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
886 vport->ct_flags |= FC_CT_RNN_ID;
887 }
7ee5d43e 888 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea3101e 889 return;
890}
891
92d7f7b0
JS
892static void
893lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
894 struct lpfc_iocbq *rspiocb)
895{
7ee5d43e
JS
896 IOCB_t *irsp = &rspiocb->iocb;
897 struct lpfc_vport *vport = cmdiocb->vport;
898
98c9ea5c
JS
899 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
900 struct lpfc_dmabuf *outp;
901 struct lpfc_sli_ct_request *CTrsp;
902
903 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
904 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
905 if (CTrsp->CommandResponse.bits.CmdRsp ==
906 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
907 vport->ct_flags |= FC_CT_RSPN_ID;
908 }
7ee5d43e 909 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
92d7f7b0
JS
910 return;
911}
912
dea3101e 913static void
2e0fef85
JS
914lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
915 struct lpfc_iocbq *rspiocb)
dea3101e 916{
7ee5d43e
JS
917 IOCB_t *irsp = &rspiocb->iocb;
918 struct lpfc_vport *vport = cmdiocb->vport;
919
98c9ea5c
JS
920 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
921 struct lpfc_dmabuf *outp;
922 struct lpfc_sli_ct_request *CTrsp;
923
924 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
925 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
926 if (CTrsp->CommandResponse.bits.CmdRsp ==
927 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
928 vport->ct_flags |= FC_CT_RSNN_NN;
929 }
7ee5d43e
JS
930 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
931 return;
932}
933
934static void
935lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
936 struct lpfc_iocbq *rspiocb)
937{
938 struct lpfc_vport *vport = cmdiocb->vport;
939
940 /* even if it fails we will act as though it succeeded. */
941 vport->ct_flags = 0;
942 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
dea3101e 943 return;
944}
945
2fb9bd8b 946static void
92d7f7b0
JS
947lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
948 struct lpfc_iocbq *rspiocb)
2fb9bd8b 949{
92d7f7b0
JS
950 IOCB_t *irsp = &rspiocb->iocb;
951 struct lpfc_vport *vport = cmdiocb->vport;
952
98c9ea5c
JS
953 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
954 struct lpfc_dmabuf *outp;
955 struct lpfc_sli_ct_request *CTrsp;
956
957 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
958 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
959 if (CTrsp->CommandResponse.bits.CmdRsp ==
960 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
961 vport->ct_flags |= FC_CT_RFF_ID;
962 }
7ee5d43e 963 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
2fb9bd8b
JS
964 return;
965}
966
311464ec 967static int
92d7f7b0
JS
968lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
969 size_t size)
970{
971 int n;
972 uint8_t *wwn = vport->phba->wwpn;
973
974 n = snprintf(symbol, size,
975 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
976 wwn[0], wwn[1], wwn[2], wwn[3],
977 wwn[4], wwn[5], wwn[6], wwn[7]);
978
979 if (vport->port_type == LPFC_PHYSICAL_PORT)
980 return n;
981
982 if (n < size)
983 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
984
985 if (n < size && vport->vname)
986 n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
987 return n;
988}
989
990int
991lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
992 size_t size)
dea3101e 993{
994 char fwrev[16];
92d7f7b0 995 int n;
dea3101e 996
92d7f7b0 997 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
dea3101e 998
92d7f7b0
JS
999 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1000 vport->phba->ModelName, fwrev, lpfc_release_version);
1001 return n;
dea3101e 1002}
1003
1004/*
1005 * lpfc_ns_cmd
1006 * Description:
1007 * Issue Cmd to NameServer
1008 * SLI_CTNS_GID_FT
1009 * LI_CTNS_RFT_ID
1010 */
1011int
92d7f7b0
JS
1012lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1013 uint8_t retry, uint32_t context)
dea3101e 1014{
92d7f7b0 1015 struct lpfc_nodelist * ndlp;
2e0fef85 1016 struct lpfc_hba *phba = vport->phba;
dea3101e 1017 struct lpfc_dmabuf *mp, *bmp;
1018 struct lpfc_sli_ct_request *CtReq;
1019 struct ulp_bde64 *bpl;
1020 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1021 struct lpfc_iocbq *) = NULL;
1022 uint32_t rsp_size = 1024;
92d7f7b0 1023 size_t size;
858c9f6c 1024 int rc = 0;
92d7f7b0
JS
1025
1026 ndlp = lpfc_findnode_did(vport, NameServer_DID);
858c9f6c
JS
1027 if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1028 rc=1;
1029 goto ns_cmd_exit;
1030 }
dea3101e 1031
1032 /* fill in BDEs for command */
1033 /* Allocate buffer for command payload */
1034 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1035 if (!mp) {
1036 rc=2;
dea3101e 1037 goto ns_cmd_exit;
858c9f6c 1038 }
dea3101e 1039
1040 INIT_LIST_HEAD(&mp->list);
1041 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
858c9f6c
JS
1042 if (!mp->virt) {
1043 rc=3;
dea3101e 1044 goto ns_cmd_free_mp;
858c9f6c 1045 }
dea3101e 1046
1047 /* Allocate buffer for Buffer ptr list */
1048 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
858c9f6c
JS
1049 if (!bmp) {
1050 rc=4;
dea3101e 1051 goto ns_cmd_free_mpvirt;
858c9f6c 1052 }
dea3101e 1053
1054 INIT_LIST_HEAD(&bmp->list);
1055 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
858c9f6c
JS
1056 if (!bmp->virt) {
1057 rc=5;
dea3101e 1058 goto ns_cmd_free_bmp;
858c9f6c 1059 }
dea3101e 1060
1061 /* NameServer Req */
e8b62011
JS
1062 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1063 "0236 NameServer Req Data: x%x x%x x%x\n",
1064 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
dea3101e 1065
1066 bpl = (struct ulp_bde64 *) bmp->virt;
1067 memset(bpl, 0, sizeof(struct ulp_bde64));
92d7f7b0
JS
1068 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1069 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea3101e 1070 bpl->tus.f.bdeFlags = 0;
1071 if (cmdcode == SLI_CTNS_GID_FT)
1072 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
92d7f7b0
JS
1073 else if (cmdcode == SLI_CTNS_GFF_ID)
1074 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
dea3101e 1075 else if (cmdcode == SLI_CTNS_RFT_ID)
1076 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1077 else if (cmdcode == SLI_CTNS_RNN_ID)
1078 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
92d7f7b0
JS
1079 else if (cmdcode == SLI_CTNS_RSPN_ID)
1080 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
dea3101e 1081 else if (cmdcode == SLI_CTNS_RSNN_NN)
1082 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
7ee5d43e
JS
1083 else if (cmdcode == SLI_CTNS_DA_ID)
1084 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
2fb9bd8b
JS
1085 else if (cmdcode == SLI_CTNS_RFF_ID)
1086 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
dea3101e 1087 else
1088 bpl->tus.f.bdeSize = 0;
1089 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1090
1091 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1092 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1093 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1094 CtReq->RevisionId.bits.InId = 0;
1095 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1096 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1097 CtReq->CommandResponse.bits.Size = 0;
1098 switch (cmdcode) {
1099 case SLI_CTNS_GID_FT:
1100 CtReq->CommandResponse.bits.CmdRsp =
1101 be16_to_cpu(SLI_CTNS_GID_FT);
1102 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
92d7f7b0 1103 if (vport->port_state < LPFC_NS_QRY)
2e0fef85
JS
1104 vport->port_state = LPFC_NS_QRY;
1105 lpfc_set_disctmo(vport);
dea3101e 1106 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1107 rsp_size = FC_MAX_NS_RSP;
1108 break;
1109
92d7f7b0
JS
1110 case SLI_CTNS_GFF_ID:
1111 CtReq->CommandResponse.bits.CmdRsp =
1112 be16_to_cpu(SLI_CTNS_GFF_ID);
1113 CtReq->un.gff.PortId = be32_to_cpu(context);
1114 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1115 break;
1116
dea3101e 1117 case SLI_CTNS_RFT_ID:
7ee5d43e 1118 vport->ct_flags &= ~FC_CT_RFT_ID;
dea3101e 1119 CtReq->CommandResponse.bits.CmdRsp =
1120 be16_to_cpu(SLI_CTNS_RFT_ID);
2e0fef85 1121 CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
dea3101e 1122 CtReq->un.rft.fcpReg = 1;
1123 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1124 break;
1125
1126 case SLI_CTNS_RNN_ID:
7ee5d43e 1127 vport->ct_flags &= ~FC_CT_RNN_ID;
dea3101e 1128 CtReq->CommandResponse.bits.CmdRsp =
1129 be16_to_cpu(SLI_CTNS_RNN_ID);
2e0fef85
JS
1130 CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
1131 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
dea3101e 1132 sizeof (struct lpfc_name));
1133 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1134 break;
1135
92d7f7b0 1136 case SLI_CTNS_RSPN_ID:
7ee5d43e 1137 vport->ct_flags &= ~FC_CT_RSPN_ID;
92d7f7b0
JS
1138 CtReq->CommandResponse.bits.CmdRsp =
1139 be16_to_cpu(SLI_CTNS_RSPN_ID);
1140 CtReq->un.rspn.PortId = be32_to_cpu(vport->fc_myDID);
1141 size = sizeof(CtReq->un.rspn.symbname);
1142 CtReq->un.rspn.len =
1143 lpfc_vport_symbolic_port_name(vport,
1144 CtReq->un.rspn.symbname, size);
1145 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1146 break;
dea3101e 1147 case SLI_CTNS_RSNN_NN:
7ee5d43e 1148 vport->ct_flags &= ~FC_CT_RSNN_NN;
dea3101e 1149 CtReq->CommandResponse.bits.CmdRsp =
1150 be16_to_cpu(SLI_CTNS_RSNN_NN);
2e0fef85 1151 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
dea3101e 1152 sizeof (struct lpfc_name));
92d7f7b0
JS
1153 size = sizeof(CtReq->un.rsnn.symbname);
1154 CtReq->un.rsnn.len =
1155 lpfc_vport_symbolic_node_name(vport,
1156 CtReq->un.rsnn.symbname, size);
dea3101e 1157 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1158 break;
7ee5d43e
JS
1159 case SLI_CTNS_DA_ID:
1160 /* Implement DA_ID Nameserver request */
1161 CtReq->CommandResponse.bits.CmdRsp =
1162 be16_to_cpu(SLI_CTNS_DA_ID);
1163 CtReq->un.da_id.port_id = be32_to_cpu(vport->fc_myDID);
1164 cmpl = lpfc_cmpl_ct_cmd_da_id;
1165 break;
92d7f7b0 1166 case SLI_CTNS_RFF_ID:
7ee5d43e 1167 vport->ct_flags &= ~FC_CT_RFF_ID;
92d7f7b0
JS
1168 CtReq->CommandResponse.bits.CmdRsp =
1169 be16_to_cpu(SLI_CTNS_RFF_ID);
1170 CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);;
1171 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1172 CtReq->un.rff.type_code = FC_FCP_DATA;
1173 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1174 break;
dea3101e 1175 }
51ef4c26 1176 lpfc_nlp_get(ndlp);
dea3101e 1177
858c9f6c 1178 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
dea3101e 1179 /* On success, The cmpl function will free the buffers */
858c9f6c
JS
1180 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1181 "Issue CT cmd: cmd:x%x did:x%x",
1182 cmdcode, ndlp->nlp_DID, 0);
dea3101e 1183 return 0;
858c9f6c 1184 }
dea3101e 1185
858c9f6c 1186 rc=6;
51ef4c26 1187 lpfc_nlp_put(ndlp);
dea3101e 1188 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1189ns_cmd_free_bmp:
1190 kfree(bmp);
1191ns_cmd_free_mpvirt:
1192 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1193ns_cmd_free_mp:
1194 kfree(mp);
1195ns_cmd_exit:
e8b62011
JS
1196 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1197 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1198 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
dea3101e 1199 return 1;
1200}
1201
1202static void
2e0fef85
JS
1203lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1204 struct lpfc_iocbq * rspiocb)
dea3101e 1205{
dea3101e 1206 struct lpfc_dmabuf *inp = cmdiocb->context1;
1207 struct lpfc_dmabuf *outp = cmdiocb->context2;
1208 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1209 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1210 struct lpfc_nodelist *ndlp;
1211 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1212 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
2e0fef85 1213 struct lpfc_vport *vport = cmdiocb->vport;
858c9f6c
JS
1214 IOCB_t *irsp = &rspiocb->iocb;
1215 uint32_t latt;
1216
1217 latt = lpfc_els_chk_latt(vport);
1218
1219 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1220 "FDMI cmpl: status:x%x/x%x latt:%d",
1221 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1222
1223 if (latt || irsp->ulpStatus) {
e8b62011
JS
1224 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1225 "0229 FDMI cmd %04x failed, latt = %d "
1226 "ulpStatus: x%x, rid x%x\n",
1227 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1228 irsp->un.ulpWord[4]);
858c9f6c
JS
1229 lpfc_ct_free_iocb(phba, cmdiocb);
1230 return;
1231 }
dea3101e 1232
2e0fef85 1233 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea3101e 1234 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1235 /* FDMI rsp failed */
e8b62011
JS
1236 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1237 "0220 FDMI rsp failed Data: x%x\n",
1238 be16_to_cpu(fdmi_cmd));
dea3101e 1239 }
1240
1241 switch (be16_to_cpu(fdmi_cmd)) {
1242 case SLI_MGMT_RHBA:
2e0fef85 1243 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
dea3101e 1244 break;
1245
1246 case SLI_MGMT_RPA:
1247 break;
1248
1249 case SLI_MGMT_DHBA:
2e0fef85 1250 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
dea3101e 1251 break;
1252
1253 case SLI_MGMT_DPRT:
2e0fef85 1254 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
dea3101e 1255 break;
1256 }
858c9f6c 1257 lpfc_ct_free_iocb(phba, cmdiocb);
dea3101e 1258 return;
1259}
2e0fef85 1260
dea3101e 1261int
2e0fef85 1262lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
dea3101e 1263{
2e0fef85 1264 struct lpfc_hba *phba = vport->phba;
dea3101e 1265 struct lpfc_dmabuf *mp, *bmp;
1266 struct lpfc_sli_ct_request *CtReq;
1267 struct ulp_bde64 *bpl;
1268 uint32_t size;
1269 REG_HBA *rh;
1270 PORT_ENTRY *pe;
1271 REG_PORT_ATTRIBUTE *pab;
1272 ATTRIBUTE_BLOCK *ab;
1273 ATTRIBUTE_ENTRY *ae;
1274 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1275 struct lpfc_iocbq *);
1276
1277
1278 /* fill in BDEs for command */
1279 /* Allocate buffer for command payload */
1280 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1281 if (!mp)
1282 goto fdmi_cmd_exit;
1283
1284 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1285 if (!mp->virt)
1286 goto fdmi_cmd_free_mp;
1287
1288 /* Allocate buffer for Buffer ptr list */
1289 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1290 if (!bmp)
1291 goto fdmi_cmd_free_mpvirt;
1292
1293 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1294 if (!bmp->virt)
1295 goto fdmi_cmd_free_bmp;
1296
1297 INIT_LIST_HEAD(&mp->list);
1298 INIT_LIST_HEAD(&bmp->list);
1299
1300 /* FDMI request */
e8b62011
JS
1301 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1302 "0218 FDMI Request Data: x%x x%x x%x\n",
1303 vport->fc_flag, vport->port_state, cmdcode);
dea3101e 1304 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1305
1306 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1307 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1308 CtReq->RevisionId.bits.InId = 0;
1309
1310 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1311 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1312 size = 0;
1313
1314 switch (cmdcode) {
1315 case SLI_MGMT_RHBA:
1316 {
1317 lpfc_vpd_t *vp = &phba->vpd;
1318 uint32_t i, j, incr;
1319 int len;
1320
1321 CtReq->CommandResponse.bits.CmdRsp =
1322 be16_to_cpu(SLI_MGMT_RHBA);
1323 CtReq->CommandResponse.bits.Size = 0;
1324 rh = (REG_HBA *) & CtReq->un.PortID;
2e0fef85 1325 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
dea3101e 1326 sizeof (struct lpfc_name));
1327 /* One entry (port) per adapter */
1328 rh->rpl.EntryCnt = be32_to_cpu(1);
2e0fef85 1329 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
dea3101e 1330 sizeof (struct lpfc_name));
1331
1332 /* point to the HBA attribute block */
1333 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1334 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1335 ab->EntryCnt = 0;
1336
1337 /* Point to the beginning of the first HBA attribute
1338 entry */
1339 /* #1 HBA attribute entry */
1340 size += FOURBYTES;
1341 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1342 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1343 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1344 + sizeof (struct lpfc_name));
2e0fef85 1345 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
dea3101e 1346 sizeof (struct lpfc_name));
1347 ab->EntryCnt++;
1348 size += FOURBYTES + sizeof (struct lpfc_name);
1349
1350 /* #2 HBA attribute entry */
1351 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1352 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1353 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1354 len = strlen(ae->un.Manufacturer);
1355 len += (len & 3) ? (4 - (len & 3)) : 4;
1356 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1357 ab->EntryCnt++;
1358 size += FOURBYTES + len;
1359
1360 /* #3 HBA attribute entry */
1361 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1362 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1363 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1364 len = strlen(ae->un.SerialNumber);
1365 len += (len & 3) ? (4 - (len & 3)) : 4;
1366 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1367 ab->EntryCnt++;
1368 size += FOURBYTES + len;
1369
1370 /* #4 HBA attribute entry */
1371 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1372 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1373 strcpy(ae->un.Model, phba->ModelName);
1374 len = strlen(ae->un.Model);
1375 len += (len & 3) ? (4 - (len & 3)) : 4;
1376 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1377 ab->EntryCnt++;
1378 size += FOURBYTES + len;
1379
1380 /* #5 HBA attribute entry */
1381 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1382 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1383 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1384 len = strlen(ae->un.ModelDescription);
1385 len += (len & 3) ? (4 - (len & 3)) : 4;
1386 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1387 ab->EntryCnt++;
1388 size += FOURBYTES + len;
1389
1390 /* #6 HBA attribute entry */
1391 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1392 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1393 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1394 /* Convert JEDEC ID to ascii for hardware version */
1395 incr = vp->rev.biuRev;
1396 for (i = 0; i < 8; i++) {
1397 j = (incr & 0xf);
1398 if (j <= 9)
1399 ae->un.HardwareVersion[7 - i] =
1400 (char)((uint8_t) 0x30 +
1401 (uint8_t) j);
1402 else
1403 ae->un.HardwareVersion[7 - i] =
1404 (char)((uint8_t) 0x61 +
1405 (uint8_t) (j - 10));
1406 incr = (incr >> 4);
1407 }
1408 ab->EntryCnt++;
1409 size += FOURBYTES + 8;
1410
1411 /* #7 HBA attribute entry */
1412 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1413 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1414 strcpy(ae->un.DriverVersion, lpfc_release_version);
1415 len = strlen(ae->un.DriverVersion);
1416 len += (len & 3) ? (4 - (len & 3)) : 4;
1417 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1418 ab->EntryCnt++;
1419 size += FOURBYTES + len;
1420
1421 /* #8 HBA attribute entry */
1422 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1423 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1424 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1425 len = strlen(ae->un.OptionROMVersion);
1426 len += (len & 3) ? (4 - (len & 3)) : 4;
1427 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1428 ab->EntryCnt++;
1429 size += FOURBYTES + len;
1430
1431 /* #9 HBA attribute entry */
1432 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1433 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1434 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1435 1);
1436 len = strlen(ae->un.FirmwareVersion);
1437 len += (len & 3) ? (4 - (len & 3)) : 4;
1438 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1439 ab->EntryCnt++;
1440 size += FOURBYTES + len;
1441
1442 /* #10 HBA attribute entry */
1443 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1444 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1445 sprintf(ae->un.OsNameVersion, "%s %s %s",
2fb9bd8b
JS
1446 init_utsname()->sysname,
1447 init_utsname()->release,
96b644bd 1448 init_utsname()->version);
dea3101e 1449 len = strlen(ae->un.OsNameVersion);
1450 len += (len & 3) ? (4 - (len & 3)) : 4;
1451 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1452 ab->EntryCnt++;
1453 size += FOURBYTES + len;
1454
1455 /* #11 HBA attribute entry */
1456 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1457 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1458 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1459 ae->un.MaxCTPayloadLen = (65 * 4096);
1460 ab->EntryCnt++;
1461 size += FOURBYTES + 4;
1462
1463 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1464 /* Total size */
1465 size = GID_REQUEST_SZ - 4 + size;
1466 }
1467 break;
1468
1469 case SLI_MGMT_RPA:
1470 {
1471 lpfc_vpd_t *vp;
1472 struct serv_parm *hsp;
1473 int len;
1474
1475 vp = &phba->vpd;
1476
1477 CtReq->CommandResponse.bits.CmdRsp =
1478 be16_to_cpu(SLI_MGMT_RPA);
1479 CtReq->CommandResponse.bits.Size = 0;
1480 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1481 size = sizeof (struct lpfc_name) + FOURBYTES;
1482 memcpy((uint8_t *) & pab->PortName,
2e0fef85 1483 (uint8_t *) & vport->fc_sparam.portName,
dea3101e 1484 sizeof (struct lpfc_name));
1485 pab->ab.EntryCnt = 0;
1486
1487 /* #1 Port attribute entry */
1488 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1489 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1490 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1491 ae->un.SupportFC4Types[2] = 1;
1492 ae->un.SupportFC4Types[7] = 1;
1493 pab->ab.EntryCnt++;
1494 size += FOURBYTES + 32;
1495
1496 /* #2 Port attribute entry */
1497 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1498 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1499 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
74b72a59
JW
1500
1501 ae->un.SupportSpeed = 0;
1502 if (phba->lmt & LMT_10Gb)
dea3101e 1503 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
74b72a59
JW
1504 if (phba->lmt & LMT_8Gb)
1505 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1506 if (phba->lmt & LMT_4Gb)
1507 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1508 if (phba->lmt & LMT_2Gb)
1509 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1510 if (phba->lmt & LMT_1Gb)
1511 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1512
dea3101e 1513 pab->ab.EntryCnt++;
1514 size += FOURBYTES + 4;
1515
1516 /* #3 Port attribute entry */
1517 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1518 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1519 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1520 switch(phba->fc_linkspeed) {
1521 case LA_1GHZ_LINK:
1522 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1523 break;
1524 case LA_2GHZ_LINK:
1525 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1526 break;
1527 case LA_4GHZ_LINK:
1528 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1529 break;
b87eab38
JS
1530 case LA_8GHZ_LINK:
1531 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1532 break;
dea3101e 1533 default:
1534 ae->un.PortSpeed =
1535 HBA_PORTSPEED_UNKNOWN;
1536 break;
1537 }
1538 pab->ab.EntryCnt++;
1539 size += FOURBYTES + 4;
1540
1541 /* #4 Port attribute entry */
1542 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1543 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1544 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
2e0fef85 1545 hsp = (struct serv_parm *) & vport->fc_sparam;
dea3101e 1546 ae->un.MaxFrameSize =
1547 (((uint32_t) hsp->cmn.
1548 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1549 bbRcvSizeLsb;
1550 pab->ab.EntryCnt++;
1551 size += FOURBYTES + 4;
1552
1553 /* #5 Port attribute entry */
1554 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1555 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1556 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1557 len = strlen((char *)ae->un.OsDeviceName);
1558 len += (len & 3) ? (4 - (len & 3)) : 4;
1559 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1560 pab->ab.EntryCnt++;
1561 size += FOURBYTES + len;
1562
3de2a653 1563 if (vport->cfg_fdmi_on == 2) {
dea3101e 1564 /* #6 Port attribute entry */
1565 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1566 size);
1567 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1568 sprintf(ae->un.HostName, "%s",
96b644bd 1569 init_utsname()->nodename);
dea3101e 1570 len = strlen(ae->un.HostName);
1571 len += (len & 3) ? (4 - (len & 3)) : 4;
1572 ae->ad.bits.AttrLen =
1573 be16_to_cpu(FOURBYTES + len);
1574 pab->ab.EntryCnt++;
1575 size += FOURBYTES + len;
1576 }
1577
1578 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1579 /* Total size */
1580 size = GID_REQUEST_SZ - 4 + size;
1581 }
1582 break;
1583
1584 case SLI_MGMT_DHBA:
1585 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1586 CtReq->CommandResponse.bits.Size = 0;
1587 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1588 memcpy((uint8_t *) & pe->PortName,
2e0fef85 1589 (uint8_t *) & vport->fc_sparam.portName,
dea3101e 1590 sizeof (struct lpfc_name));
1591 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1592 break;
1593
1594 case SLI_MGMT_DPRT:
1595 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1596 CtReq->CommandResponse.bits.Size = 0;
1597 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1598 memcpy((uint8_t *) & pe->PortName,
2e0fef85 1599 (uint8_t *) & vport->fc_sparam.portName,
dea3101e 1600 sizeof (struct lpfc_name));
1601 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1602 break;
1603 }
1604
1605 bpl = (struct ulp_bde64 *) bmp->virt;
92d7f7b0
JS
1606 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1607 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
dea3101e 1608 bpl->tus.f.bdeFlags = 0;
1609 bpl->tus.f.bdeSize = size;
1610 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1611
1612 cmpl = lpfc_cmpl_ct_cmd_fdmi;
51ef4c26 1613 lpfc_nlp_get(ndlp);
dea3101e 1614
92d7f7b0 1615 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
dea3101e 1616 return 0;
1617
51ef4c26 1618 lpfc_nlp_put(ndlp);
dea3101e 1619 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1620fdmi_cmd_free_bmp:
1621 kfree(bmp);
1622fdmi_cmd_free_mpvirt:
1623 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1624fdmi_cmd_free_mp:
1625 kfree(mp);
1626fdmi_cmd_exit:
1627 /* Issue FDMI request failed */
e8b62011
JS
1628 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1629 "0244 Issue FDMI request failed Data: x%x\n",
1630 cmdcode);
dea3101e 1631 return 1;
1632}
1633
1634void
1635lpfc_fdmi_tmo(unsigned long ptr)
1636{
2e0fef85
JS
1637 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1638 struct lpfc_hba *phba = vport->phba;
dea3101e 1639 unsigned long iflag;
1640
2e0fef85
JS
1641 spin_lock_irqsave(&vport->work_port_lock, iflag);
1642 if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
1643 vport->work_port_events |= WORKER_FDMI_TMO;
92d7f7b0
JS
1644 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1645
1646 spin_lock_irqsave(&phba->hbalock, iflag);
dea3101e 1647 if (phba->work_wait)
92d7f7b0
JS
1648 lpfc_worker_wake_up(phba);
1649 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea3101e 1650 }
92d7f7b0
JS
1651 else
1652 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea3101e 1653}
1654
1655void
2e0fef85 1656lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
dea3101e 1657{
1658 struct lpfc_nodelist *ndlp;
1659
2e0fef85 1660 ndlp = lpfc_findnode_did(vport, FDMI_DID);
dea3101e 1661 if (ndlp) {
2e0fef85
JS
1662 if (init_utsname()->nodename[0] != '\0')
1663 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1664 else
1665 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea3101e 1666 }
dea3101e 1667 return;
1668}
1669
dea3101e 1670void
2e0fef85 1671lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
dea3101e 1672{
1673 struct lpfc_sli *psli = &phba->sli;
1674 lpfc_vpd_t *vp = &phba->vpd;
1675 uint32_t b1, b2, b3, b4, i, rev;
1676 char c;
1677 uint32_t *ptr, str[4];
1678 uint8_t *fwname;
1679
1680 if (vp->rev.rBit) {
1681 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1682 rev = vp->rev.sli2FwRev;
1683 else
1684 rev = vp->rev.sli1FwRev;
1685
1686 b1 = (rev & 0x0000f000) >> 12;
1687 b2 = (rev & 0x00000f00) >> 8;
1688 b3 = (rev & 0x000000c0) >> 6;
1689 b4 = (rev & 0x00000030) >> 4;
1690
1691 switch (b4) {
1692 case 0:
1693 c = 'N';
1694 break;
1695 case 1:
1696 c = 'A';
1697 break;
1698 case 2:
1699 c = 'B';
1700 break;
1701 default:
1702 c = 0;
1703 break;
1704 }
1705 b4 = (rev & 0x0000000f);
1706
1707 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1708 fwname = vp->rev.sli2FwName;
1709 else
1710 fwname = vp->rev.sli1FwName;
1711
1712 for (i = 0; i < 16; i++)
1713 if (fwname[i] == 0x20)
1714 fwname[i] = 0;
1715
1716 ptr = (uint32_t*)fwname;
1717
1718 for (i = 0; i < 3; i++)
1719 str[i] = be32_to_cpu(*ptr++);
1720
1721 if (c == 0) {
1722 if (flag)
1723 sprintf(fwrevision, "%d.%d%d (%s)",
1724 b1, b2, b3, (char *)str);
1725 else
1726 sprintf(fwrevision, "%d.%d%d", b1,
1727 b2, b3);
1728 } else {
1729 if (flag)
1730 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1731 b1, b2, b3, c,
1732 b4, (char *)str);
1733 else
1734 sprintf(fwrevision, "%d.%d%d%c%d",
1735 b1, b2, b3, c, b4);
1736 }
1737 } else {
1738 rev = vp->rev.smFwRev;
1739
1740 b1 = (rev & 0xff000000) >> 24;
1741 b2 = (rev & 0x00f00000) >> 20;
1742 b3 = (rev & 0x000f0000) >> 16;
1743 c = (rev & 0x0000ff00) >> 8;
1744 b4 = (rev & 0x000000ff);
1745
1746 if (flag)
1747 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1748 b2, b3, c, b4);
1749 else
1750 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1751 b2, b3, c, b4);
1752 }
1753 return;
1754}