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