1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
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 *******************************************************************/
21 #include <linux/interrupt.h>
22 #include <linux/mempool.h>
23 #include <linux/pci.h>
24 #include <linux/delay.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_host.h>
28 #include <scsi/scsi_transport_fc.h>
29 #include <scsi/scsi_bsg_fc.h>
30 #include <scsi/fc/fc_fs.h>
35 #include "lpfc_sli4.h"
38 #include "lpfc_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_vport.h"
44 #include "lpfc_version.h"
46 struct lpfc_bsg_event
{
47 struct list_head node
;
51 /* Event type and waiter identifiers */
56 /* next two flags are here for the auto-delete logic */
57 unsigned long wait_time_stamp
;
60 /* seen and not seen events */
61 struct list_head events_to_get
;
62 struct list_head events_to_see
;
64 /* job waiting for this event to finish */
65 struct fc_bsg_job
*set_job
;
68 struct lpfc_bsg_iocb
{
69 struct lpfc_iocbq
*cmdiocbq
;
70 struct lpfc_iocbq
*rspiocbq
;
71 struct lpfc_dmabuf
*bmp
;
72 struct lpfc_nodelist
*ndlp
;
74 /* job waiting for this iocb to finish */
75 struct fc_bsg_job
*set_job
;
78 struct lpfc_bsg_mbox
{
82 /* job waiting for this mbox command to finish */
83 struct fc_bsg_job
*set_job
;
92 struct lpfc_bsg_event
*evt
;
93 struct lpfc_bsg_iocb iocb
;
94 struct lpfc_bsg_mbox mbox
;
99 struct list_head node
;
106 #define BUF_SZ_4K 4096
107 #define SLI_CT_ELX_LOOPBACK 0x10
109 enum ELX_LOOPBACK_CMD
{
110 ELX_LOOPBACK_XRI_SETUP
,
114 #define ELX_LOOPBACK_HEADER_SZ \
115 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
117 struct lpfc_dmabufext
{
118 struct lpfc_dmabuf dma
;
124 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
125 * @phba: Pointer to HBA context object.
126 * @cmdiocbq: Pointer to command iocb.
127 * @rspiocbq: Pointer to response iocb.
129 * This function is the completion handler for iocbs issued using
130 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
131 * ring event handler function without any lock held. This function
132 * can be called from both worker thread context and interrupt
133 * context. This function also can be called from another thread which
134 * cleans up the SLI layer objects.
135 * This function copies the contents of the response iocb to the
136 * response iocb memory object provided by the caller of
137 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
138 * sleeps for the iocb completion.
141 lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba
*phba
,
142 struct lpfc_iocbq
*cmdiocbq
,
143 struct lpfc_iocbq
*rspiocbq
)
145 unsigned long iflags
;
146 struct bsg_job_data
*dd_data
;
147 struct fc_bsg_job
*job
;
149 struct lpfc_dmabuf
*bmp
;
150 struct lpfc_nodelist
*ndlp
;
151 struct lpfc_bsg_iocb
*iocb
;
155 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
156 dd_data
= cmdiocbq
->context1
;
158 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
162 iocb
= &dd_data
->context_un
.iocb
;
164 job
->dd_data
= NULL
; /* so timeout handler does not reply */
166 spin_lock_irqsave(&phba
->hbalock
, iflags
);
167 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
168 if (cmdiocbq
->context2
&& rspiocbq
)
169 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
170 &rspiocbq
->iocb
, sizeof(IOCB_t
));
171 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
174 rspiocbq
= iocb
->rspiocbq
;
175 rsp
= &rspiocbq
->iocb
;
178 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
179 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
180 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
181 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
183 if (rsp
->ulpStatus
) {
184 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
185 switch (rsp
->un
.ulpWord
[4] & 0xff) {
186 case IOERR_SEQUENCE_TIMEOUT
:
189 case IOERR_INVALID_RPI
:
199 job
->reply
->reply_payload_rcv_len
=
200 rsp
->un
.genreq64
.bdl
.bdeSize
;
202 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
203 lpfc_sli_release_iocbq(phba
, rspiocbq
);
204 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
208 /* make error code available to userspace */
209 job
->reply
->result
= rc
;
210 /* complete the job back to userspace */
212 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
217 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
218 * @job: fc_bsg_job to handle
221 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job
*job
)
223 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
224 struct lpfc_hba
*phba
= vport
->phba
;
225 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
226 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
227 struct ulp_bde64
*bpl
= NULL
;
229 struct lpfc_iocbq
*cmdiocbq
= NULL
;
230 struct lpfc_iocbq
*rspiocbq
= NULL
;
233 struct lpfc_dmabuf
*bmp
= NULL
;
236 struct scatterlist
*sgel
= NULL
;
239 struct bsg_job_data
*dd_data
;
243 /* in case no data is transferred */
244 job
->reply
->reply_payload_rcv_len
= 0;
246 /* allocate our bsg tracking structure */
247 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
249 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
250 "2733 Failed allocation of dd_data\n");
255 if (!lpfc_nlp_get(ndlp
)) {
260 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
266 if (ndlp
->nlp_flag
& NLP_ELS_SND_MASK
) {
271 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
277 cmd
= &cmdiocbq
->iocb
;
278 rspiocbq
= lpfc_sli_get_iocbq(phba
);
284 rsp
= &rspiocbq
->iocb
;
285 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
291 INIT_LIST_HEAD(&bmp
->list
);
292 bpl
= (struct ulp_bde64
*) bmp
->virt
;
293 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
294 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
295 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
296 busaddr
= sg_dma_address(sgel
);
297 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
298 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
299 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
300 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
301 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
305 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
306 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
307 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
308 busaddr
= sg_dma_address(sgel
);
309 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
310 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
311 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
312 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
313 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
317 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
318 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
319 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
320 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
321 cmd
->un
.genreq64
.bdl
.bdeSize
=
322 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
323 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
324 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
325 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
326 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
327 cmd
->un
.genreq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
328 cmd
->ulpBdeCount
= 1;
330 cmd
->ulpClass
= CLASS3
;
331 cmd
->ulpContext
= ndlp
->nlp_rpi
;
332 cmd
->ulpOwner
= OWN_CHIP
;
333 cmdiocbq
->vport
= phba
->pport
;
334 cmdiocbq
->context3
= bmp
;
335 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
336 timeout
= phba
->fc_ratov
* 2;
337 cmd
->ulpTimeout
= timeout
;
339 cmdiocbq
->iocb_cmpl
= lpfc_bsg_send_mgmt_cmd_cmp
;
340 cmdiocbq
->context1
= dd_data
;
341 cmdiocbq
->context2
= rspiocbq
;
342 dd_data
->type
= TYPE_IOCB
;
343 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
344 dd_data
->context_un
.iocb
.rspiocbq
= rspiocbq
;
345 dd_data
->context_un
.iocb
.set_job
= job
;
346 dd_data
->context_un
.iocb
.bmp
= bmp
;
347 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
349 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
350 creg_val
= readl(phba
->HCregaddr
);
351 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
352 writel(creg_val
, phba
->HCregaddr
);
353 readl(phba
->HCregaddr
); /* flush */
356 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
358 if (rc
== IOCB_SUCCESS
)
359 return 0; /* done for now */
361 /* iocb failed so cleanup */
362 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
363 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
364 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
365 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
367 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
370 lpfc_sli_release_iocbq(phba
, rspiocbq
);
372 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
380 /* make error code available to userspace */
381 job
->reply
->result
= rc
;
387 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
388 * @phba: Pointer to HBA context object.
389 * @cmdiocbq: Pointer to command iocb.
390 * @rspiocbq: Pointer to response iocb.
392 * This function is the completion handler for iocbs issued using
393 * lpfc_bsg_rport_els_cmp function. This function is called by the
394 * ring event handler function without any lock held. This function
395 * can be called from both worker thread context and interrupt
396 * context. This function also can be called from other thread which
397 * cleans up the SLI layer objects.
398 * This function copies the contents of the response iocb to the
399 * response iocb memory object provided by the caller of
400 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
401 * sleeps for the iocb completion.
404 lpfc_bsg_rport_els_cmp(struct lpfc_hba
*phba
,
405 struct lpfc_iocbq
*cmdiocbq
,
406 struct lpfc_iocbq
*rspiocbq
)
408 struct bsg_job_data
*dd_data
;
409 struct fc_bsg_job
*job
;
411 struct lpfc_nodelist
*ndlp
;
412 struct lpfc_dmabuf
*pbuflist
= NULL
;
413 struct fc_bsg_ctels_reply
*els_reply
;
418 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
419 dd_data
= cmdiocbq
->context1
;
420 /* normal completion and timeout crossed paths, already done */
422 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
426 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
427 if (cmdiocbq
->context2
&& rspiocbq
)
428 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
429 &rspiocbq
->iocb
, sizeof(IOCB_t
));
431 job
= dd_data
->context_un
.iocb
.set_job
;
432 cmdiocbq
= dd_data
->context_un
.iocb
.cmdiocbq
;
433 rspiocbq
= dd_data
->context_un
.iocb
.rspiocbq
;
434 rsp
= &rspiocbq
->iocb
;
435 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
437 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
438 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
439 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
440 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
442 if (job
->reply
->result
== -EAGAIN
)
444 else if (rsp
->ulpStatus
== IOSTAT_SUCCESS
)
445 job
->reply
->reply_payload_rcv_len
=
446 rsp
->un
.elsreq64
.bdl
.bdeSize
;
447 else if (rsp
->ulpStatus
== IOSTAT_LS_RJT
) {
448 job
->reply
->reply_payload_rcv_len
=
449 sizeof(struct fc_bsg_ctels_reply
);
450 /* LS_RJT data returned in word 4 */
451 rjt_data
= (uint8_t *)&rsp
->un
.ulpWord
[4];
452 els_reply
= &job
->reply
->reply_data
.ctels_reply
;
453 els_reply
->status
= FC_CTELS_STATUS_REJECT
;
454 els_reply
->rjt_data
.action
= rjt_data
[3];
455 els_reply
->rjt_data
.reason_code
= rjt_data
[2];
456 els_reply
->rjt_data
.reason_explanation
= rjt_data
[1];
457 els_reply
->rjt_data
.vendor_unique
= rjt_data
[0];
461 pbuflist
= (struct lpfc_dmabuf
*) cmdiocbq
->context3
;
462 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
463 lpfc_sli_release_iocbq(phba
, rspiocbq
);
464 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
467 /* make error code available to userspace */
468 job
->reply
->result
= rc
;
470 /* complete the job back to userspace */
472 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
477 * lpfc_bsg_rport_els - send an ELS command from a bsg request
478 * @job: fc_bsg_job to handle
481 lpfc_bsg_rport_els(struct fc_bsg_job
*job
)
483 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
484 struct lpfc_hba
*phba
= vport
->phba
;
485 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
486 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
490 struct lpfc_iocbq
*rspiocbq
;
491 struct lpfc_iocbq
*cmdiocbq
;
494 struct lpfc_dmabuf
*pcmd
;
495 struct lpfc_dmabuf
*prsp
;
496 struct lpfc_dmabuf
*pbuflist
= NULL
;
497 struct ulp_bde64
*bpl
;
500 struct scatterlist
*sgel
= NULL
;
503 struct bsg_job_data
*dd_data
;
507 /* in case no data is transferred */
508 job
->reply
->reply_payload_rcv_len
= 0;
510 /* allocate our bsg tracking structure */
511 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
513 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
514 "2735 Failed allocation of dd_data\n");
519 if (!lpfc_nlp_get(ndlp
)) {
524 elscmd
= job
->request
->rqst_data
.r_els
.els_code
;
525 cmdsize
= job
->request_payload
.payload_len
;
526 rspsize
= job
->reply_payload
.payload_len
;
527 rspiocbq
= lpfc_sli_get_iocbq(phba
);
534 rsp
= &rspiocbq
->iocb
;
537 cmdiocbq
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
,
538 ndlp
->nlp_DID
, elscmd
);
544 /* prep els iocb set context1 to the ndlp, context2 to the command
545 * dmabuf, context3 holds the data dmabuf
547 pcmd
= (struct lpfc_dmabuf
*) cmdiocbq
->context2
;
548 prsp
= (struct lpfc_dmabuf
*) pcmd
->list
.next
;
549 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
551 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
553 cmdiocbq
->context2
= NULL
;
555 pbuflist
= (struct lpfc_dmabuf
*) cmdiocbq
->context3
;
556 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
558 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
559 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
560 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
561 busaddr
= sg_dma_address(sgel
);
562 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
563 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
564 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
565 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
566 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
570 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
571 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
572 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
573 busaddr
= sg_dma_address(sgel
);
574 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
575 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
576 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
577 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
578 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
581 cmdiocbq
->iocb
.un
.elsreq64
.bdl
.bdeSize
=
582 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
583 cmdiocbq
->iocb
.ulpContext
= rpi
;
584 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
585 cmdiocbq
->context1
= NULL
;
586 cmdiocbq
->context2
= NULL
;
588 cmdiocbq
->iocb_cmpl
= lpfc_bsg_rport_els_cmp
;
589 cmdiocbq
->context1
= dd_data
;
590 cmdiocbq
->context2
= rspiocbq
;
591 dd_data
->type
= TYPE_IOCB
;
592 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
593 dd_data
->context_un
.iocb
.rspiocbq
= rspiocbq
;
594 dd_data
->context_un
.iocb
.set_job
= job
;
595 dd_data
->context_un
.iocb
.bmp
= NULL
;;
596 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
598 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
599 creg_val
= readl(phba
->HCregaddr
);
600 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
601 writel(creg_val
, phba
->HCregaddr
);
602 readl(phba
->HCregaddr
); /* flush */
604 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
606 if (rc
== IOCB_SUCCESS
)
607 return 0; /* done for now */
609 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
610 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
611 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
612 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
614 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
616 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
619 lpfc_sli_release_iocbq(phba
, rspiocbq
);
625 /* make error code available to userspace */
626 job
->reply
->result
= rc
;
632 * lpfc_bsg_event_free - frees an allocated event structure
633 * @kref: Pointer to a kref.
635 * Called from kref_put. Back cast the kref into an event structure address.
636 * Free any events to get, delete associated nodes, free any events to see,
637 * free any data then free the event itself.
640 lpfc_bsg_event_free(struct kref
*kref
)
642 struct lpfc_bsg_event
*evt
= container_of(kref
, struct lpfc_bsg_event
,
644 struct event_data
*ed
;
646 list_del(&evt
->node
);
648 while (!list_empty(&evt
->events_to_get
)) {
649 ed
= list_entry(evt
->events_to_get
.next
, typeof(*ed
), node
);
655 while (!list_empty(&evt
->events_to_see
)) {
656 ed
= list_entry(evt
->events_to_see
.next
, typeof(*ed
), node
);
666 * lpfc_bsg_event_ref - increments the kref for an event
667 * @evt: Pointer to an event structure.
670 lpfc_bsg_event_ref(struct lpfc_bsg_event
*evt
)
672 kref_get(&evt
->kref
);
676 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
677 * @evt: Pointer to an event structure.
680 lpfc_bsg_event_unref(struct lpfc_bsg_event
*evt
)
682 kref_put(&evt
->kref
, lpfc_bsg_event_free
);
686 * lpfc_bsg_event_new - allocate and initialize a event structure
687 * @ev_mask: Mask of events.
688 * @ev_reg_id: Event reg id.
689 * @ev_req_id: Event request id.
691 static struct lpfc_bsg_event
*
692 lpfc_bsg_event_new(uint32_t ev_mask
, int ev_reg_id
, uint32_t ev_req_id
)
694 struct lpfc_bsg_event
*evt
= kzalloc(sizeof(*evt
), GFP_KERNEL
);
699 INIT_LIST_HEAD(&evt
->events_to_get
);
700 INIT_LIST_HEAD(&evt
->events_to_see
);
701 evt
->type_mask
= ev_mask
;
702 evt
->req_id
= ev_req_id
;
703 evt
->reg_id
= ev_reg_id
;
704 evt
->wait_time_stamp
= jiffies
;
705 init_waitqueue_head(&evt
->wq
);
706 kref_init(&evt
->kref
);
711 * diag_cmd_data_free - Frees an lpfc dma buffer extension
712 * @phba: Pointer to HBA context object.
713 * @mlist: Pointer to an lpfc dma buffer extension.
716 diag_cmd_data_free(struct lpfc_hba
*phba
, struct lpfc_dmabufext
*mlist
)
718 struct lpfc_dmabufext
*mlast
;
719 struct pci_dev
*pcidev
;
720 struct list_head head
, *curr
, *next
;
722 if ((!mlist
) || (!lpfc_is_link_up(phba
) &&
723 (phba
->link_flag
& LS_LOOPBACK_MODE
))) {
727 pcidev
= phba
->pcidev
;
728 list_add_tail(&head
, &mlist
->dma
.list
);
730 list_for_each_safe(curr
, next
, &head
) {
731 mlast
= list_entry(curr
, struct lpfc_dmabufext
, dma
.list
);
733 dma_free_coherent(&pcidev
->dev
,
743 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
748 * This function is called when an unsolicited CT command is received. It
749 * forwards the event to any processes registered to receive CT events.
752 lpfc_bsg_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
753 struct lpfc_iocbq
*piocbq
)
755 uint32_t evt_req_id
= 0;
758 struct lpfc_dmabuf
*dmabuf
= NULL
;
759 struct lpfc_bsg_event
*evt
;
760 struct event_data
*evt_dat
= NULL
;
761 struct lpfc_iocbq
*iocbq
;
763 struct list_head head
;
764 struct ulp_bde64
*bde
;
767 struct lpfc_dmabuf
*bdeBuf1
= piocbq
->context2
;
768 struct lpfc_dmabuf
*bdeBuf2
= piocbq
->context3
;
769 struct lpfc_hbq_entry
*hbqe
;
770 struct lpfc_sli_ct_request
*ct_req
;
771 struct fc_bsg_job
*job
= NULL
;
775 INIT_LIST_HEAD(&head
);
776 list_add_tail(&head
, &piocbq
->list
);
778 if (piocbq
->iocb
.ulpBdeCount
== 0 ||
779 piocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
== 0)
780 goto error_ct_unsol_exit
;
782 if (phba
->link_state
== LPFC_HBA_ERROR
||
783 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)))
784 goto error_ct_unsol_exit
;
786 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
789 dma_addr
= getPaddr(piocbq
->iocb
.un
.cont64
[0].addrHigh
,
790 piocbq
->iocb
.un
.cont64
[0].addrLow
);
791 dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
, dma_addr
);
794 goto error_ct_unsol_exit
;
795 ct_req
= (struct lpfc_sli_ct_request
*)dmabuf
->virt
;
796 evt_req_id
= ct_req
->FsType
;
797 cmd
= ct_req
->CommandResponse
.bits
.CmdRsp
;
798 len
= ct_req
->CommandResponse
.bits
.Size
;
799 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
800 lpfc_sli_ringpostbuf_put(phba
, pring
, dmabuf
);
802 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
803 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
804 if (!(evt
->type_mask
& FC_REG_CT_EVENT
) ||
805 evt
->req_id
!= evt_req_id
)
808 lpfc_bsg_event_ref(evt
);
809 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
810 evt_dat
= kzalloc(sizeof(*evt_dat
), GFP_KERNEL
);
811 if (evt_dat
== NULL
) {
812 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
813 lpfc_bsg_event_unref(evt
);
814 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
815 "2614 Memory allocation failed for "
820 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
821 /* take accumulated byte count from the last iocbq */
822 iocbq
= list_entry(head
.prev
, typeof(*iocbq
), list
);
823 evt_dat
->len
= iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
;
825 list_for_each_entry(iocbq
, &head
, list
) {
826 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++)
828 iocbq
->iocb
.un
.cont64
[i
].tus
.f
.bdeSize
;
832 evt_dat
->data
= kzalloc(evt_dat
->len
, GFP_KERNEL
);
833 if (evt_dat
->data
== NULL
) {
834 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
835 "2615 Memory allocation failed for "
836 "CT event data, size %d\n",
839 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
840 lpfc_bsg_event_unref(evt
);
841 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
842 goto error_ct_unsol_exit
;
845 list_for_each_entry(iocbq
, &head
, list
) {
847 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
848 bdeBuf1
= iocbq
->context2
;
849 bdeBuf2
= iocbq
->context3
;
851 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++) {
852 if (phba
->sli3_options
&
853 LPFC_SLI3_HBQ_ENABLED
) {
855 hbqe
= (struct lpfc_hbq_entry
*)
856 &iocbq
->iocb
.un
.ulpWord
[0];
857 size
= hbqe
->bde
.tus
.f
.bdeSize
;
860 hbqe
= (struct lpfc_hbq_entry
*)
863 size
= hbqe
->bde
.tus
.f
.bdeSize
;
866 if ((offset
+ size
) > evt_dat
->len
)
867 size
= evt_dat
->len
- offset
;
869 size
= iocbq
->iocb
.un
.cont64
[i
].
871 bde
= &iocbq
->iocb
.un
.cont64
[i
];
872 dma_addr
= getPaddr(bde
->addrHigh
,
874 dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
878 lpfc_printf_log(phba
, KERN_ERR
,
879 LOG_LIBDFC
, "2616 No dmabuf "
880 "found for iocbq 0x%p\n",
882 kfree(evt_dat
->data
);
884 spin_lock_irqsave(&phba
->ct_ev_lock
,
886 lpfc_bsg_event_unref(evt
);
887 spin_unlock_irqrestore(
888 &phba
->ct_ev_lock
, flags
);
889 goto error_ct_unsol_exit
;
891 memcpy((char *)(evt_dat
->data
) + offset
,
894 if (evt_req_id
!= SLI_CT_ELX_LOOPBACK
&&
895 !(phba
->sli3_options
&
896 LPFC_SLI3_HBQ_ENABLED
)) {
897 lpfc_sli_ringpostbuf_put(phba
, pring
,
901 case ELX_LOOPBACK_DATA
:
902 diag_cmd_data_free(phba
,
903 (struct lpfc_dmabufext
*)
906 case ELX_LOOPBACK_XRI_SETUP
:
907 if ((phba
->sli_rev
==
909 (phba
->sli3_options
&
910 LPFC_SLI3_HBQ_ENABLED
912 lpfc_in_buf_free(phba
,
915 lpfc_post_buffer(phba
,
921 if (!(phba
->sli3_options
&
922 LPFC_SLI3_HBQ_ENABLED
))
923 lpfc_post_buffer(phba
,
932 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
933 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
934 evt_dat
->immed_dat
= phba
->ctx_idx
;
935 phba
->ctx_idx
= (phba
->ctx_idx
+ 1) % 64;
936 phba
->ct_ctx
[evt_dat
->immed_dat
].oxid
=
937 piocbq
->iocb
.ulpContext
;
938 phba
->ct_ctx
[evt_dat
->immed_dat
].SID
=
939 piocbq
->iocb
.un
.rcvels
.remoteID
;
941 evt_dat
->immed_dat
= piocbq
->iocb
.ulpContext
;
943 evt_dat
->type
= FC_REG_CT_EVENT
;
944 list_add(&evt_dat
->node
, &evt
->events_to_see
);
945 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
) {
946 wake_up_interruptible(&evt
->wq
);
947 lpfc_bsg_event_unref(evt
);
951 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
952 lpfc_bsg_event_unref(evt
);
957 job
->reply
->reply_payload_rcv_len
= size
;
958 /* make error code available to userspace */
959 job
->reply
->result
= 0;
961 /* complete the job back to userspace */
962 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
964 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
967 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
970 if (!list_empty(&head
))
972 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
)
978 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
979 * @job: SET_EVENT fc_bsg_job
982 lpfc_bsg_hba_set_event(struct fc_bsg_job
*job
)
984 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
985 struct lpfc_hba
*phba
= vport
->phba
;
986 struct set_ct_event
*event_req
;
987 struct lpfc_bsg_event
*evt
;
989 struct bsg_job_data
*dd_data
= NULL
;
993 if (job
->request_len
<
994 sizeof(struct fc_bsg_request
) + sizeof(struct set_ct_event
)) {
995 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
996 "2612 Received SET_CT_EVENT below minimum "
1002 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1003 if (dd_data
== NULL
) {
1004 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1005 "2734 Failed allocation of dd_data\n");
1010 event_req
= (struct set_ct_event
*)
1011 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1012 ev_mask
= ((uint32_t)(unsigned long)event_req
->type_mask
&
1014 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1015 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1016 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1017 lpfc_bsg_event_ref(evt
);
1018 evt
->wait_time_stamp
= jiffies
;
1022 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1024 if (&evt
->node
== &phba
->ct_ev_waiters
) {
1025 /* no event waiting struct yet - first call */
1026 evt
= lpfc_bsg_event_new(ev_mask
, event_req
->ev_reg_id
,
1027 event_req
->ev_req_id
);
1029 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1030 "2617 Failed allocation of event "
1036 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1037 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1038 lpfc_bsg_event_ref(evt
);
1039 evt
->wait_time_stamp
= jiffies
;
1040 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1043 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1045 dd_data
->type
= TYPE_EVT
;
1046 dd_data
->context_un
.evt
= evt
;
1047 evt
->set_job
= job
; /* for unsolicited command */
1048 job
->dd_data
= dd_data
; /* for fc transport timeout callback*/
1049 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1050 return 0; /* call job done later */
1053 if (dd_data
!= NULL
)
1056 job
->dd_data
= NULL
;
1061 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1062 * @job: GET_EVENT fc_bsg_job
1065 lpfc_bsg_hba_get_event(struct fc_bsg_job
*job
)
1067 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1068 struct lpfc_hba
*phba
= vport
->phba
;
1069 struct get_ct_event
*event_req
;
1070 struct get_ct_event_reply
*event_reply
;
1071 struct lpfc_bsg_event
*evt
;
1072 struct event_data
*evt_dat
= NULL
;
1073 unsigned long flags
;
1076 if (job
->request_len
<
1077 sizeof(struct fc_bsg_request
) + sizeof(struct get_ct_event
)) {
1078 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1079 "2613 Received GET_CT_EVENT request below "
1085 event_req
= (struct get_ct_event
*)
1086 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1088 event_reply
= (struct get_ct_event_reply
*)
1089 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
1090 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1091 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1092 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1093 if (list_empty(&evt
->events_to_get
))
1095 lpfc_bsg_event_ref(evt
);
1096 evt
->wait_time_stamp
= jiffies
;
1097 evt_dat
= list_entry(evt
->events_to_get
.prev
,
1098 struct event_data
, node
);
1099 list_del(&evt_dat
->node
);
1103 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1105 /* The app may continue to ask for event data until it gets
1106 * an error indicating that there isn't anymore
1108 if (evt_dat
== NULL
) {
1109 job
->reply
->reply_payload_rcv_len
= 0;
1114 if (evt_dat
->len
> job
->request_payload
.payload_len
) {
1115 evt_dat
->len
= job
->request_payload
.payload_len
;
1116 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1117 "2618 Truncated event data at %d "
1119 job
->request_payload
.payload_len
);
1122 event_reply
->type
= evt_dat
->type
;
1123 event_reply
->immed_data
= evt_dat
->immed_dat
;
1124 if (evt_dat
->len
> 0)
1125 job
->reply
->reply_payload_rcv_len
=
1126 sg_copy_from_buffer(job
->request_payload
.sg_list
,
1127 job
->request_payload
.sg_cnt
,
1128 evt_dat
->data
, evt_dat
->len
);
1130 job
->reply
->reply_payload_rcv_len
= 0;
1133 kfree(evt_dat
->data
);
1137 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1138 lpfc_bsg_event_unref(evt
);
1139 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1140 job
->dd_data
= NULL
;
1141 job
->reply
->result
= 0;
1146 job
->dd_data
= NULL
;
1147 job
->reply
->result
= rc
;
1152 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1153 * @phba: Pointer to HBA context object.
1154 * @cmdiocbq: Pointer to command iocb.
1155 * @rspiocbq: Pointer to response iocb.
1157 * This function is the completion handler for iocbs issued using
1158 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1159 * ring event handler function without any lock held. This function
1160 * can be called from both worker thread context and interrupt
1161 * context. This function also can be called from other thread which
1162 * cleans up the SLI layer objects.
1163 * This function copy the contents of the response iocb to the
1164 * response iocb memory object provided by the caller of
1165 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1166 * sleeps for the iocb completion.
1169 lpfc_issue_ct_rsp_cmp(struct lpfc_hba
*phba
,
1170 struct lpfc_iocbq
*cmdiocbq
,
1171 struct lpfc_iocbq
*rspiocbq
)
1173 struct bsg_job_data
*dd_data
;
1174 struct fc_bsg_job
*job
;
1176 struct lpfc_dmabuf
*bmp
;
1177 struct lpfc_nodelist
*ndlp
;
1178 unsigned long flags
;
1181 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1182 dd_data
= cmdiocbq
->context1
;
1183 /* normal completion and timeout crossed paths, already done */
1185 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1189 job
= dd_data
->context_un
.iocb
.set_job
;
1190 bmp
= dd_data
->context_un
.iocb
.bmp
;
1191 rsp
= &rspiocbq
->iocb
;
1192 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
1194 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1195 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1197 if (rsp
->ulpStatus
) {
1198 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1199 switch (rsp
->un
.ulpWord
[4] & 0xff) {
1200 case IOERR_SEQUENCE_TIMEOUT
:
1203 case IOERR_INVALID_RPI
:
1213 job
->reply
->reply_payload_rcv_len
=
1214 rsp
->un
.genreq64
.bdl
.bdeSize
;
1216 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1217 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1221 /* make error code available to userspace */
1222 job
->reply
->result
= rc
;
1223 job
->dd_data
= NULL
;
1224 /* complete the job back to userspace */
1226 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1231 * lpfc_issue_ct_rsp - issue a ct response
1232 * @phba: Pointer to HBA context object.
1233 * @job: Pointer to the job object.
1234 * @tag: tag index value into the ports context exchange array.
1235 * @bmp: Pointer to a dma buffer descriptor.
1236 * @num_entry: Number of enties in the bde.
1239 lpfc_issue_ct_rsp(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
, uint32_t tag
,
1240 struct lpfc_dmabuf
*bmp
, int num_entry
)
1243 struct lpfc_iocbq
*ctiocb
= NULL
;
1245 struct lpfc_nodelist
*ndlp
= NULL
;
1246 struct bsg_job_data
*dd_data
;
1249 /* allocate our bsg tracking structure */
1250 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1252 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1253 "2736 Failed allocation of dd_data\n");
1258 /* Allocate buffer for command iocb */
1259 ctiocb
= lpfc_sli_get_iocbq(phba
);
1265 icmd
= &ctiocb
->iocb
;
1266 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
1267 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
1268 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
1269 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1270 icmd
->un
.xseq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
1271 icmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
1272 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1273 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_SOL_CTL
;
1274 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1276 /* Fill in rest of iocb */
1277 icmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
1278 icmd
->ulpBdeCount
= 1;
1280 icmd
->ulpClass
= CLASS3
;
1281 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1282 /* Do not issue unsol response if oxid not marked as valid */
1283 if (!(phba
->ct_ctx
[tag
].flags
& UNSOL_VALID
)) {
1285 goto issue_ct_rsp_exit
;
1287 icmd
->ulpContext
= phba
->ct_ctx
[tag
].oxid
;
1288 ndlp
= lpfc_findnode_did(phba
->pport
, phba
->ct_ctx
[tag
].SID
);
1290 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1291 "2721 ndlp null for oxid %x SID %x\n",
1293 phba
->ct_ctx
[tag
].SID
);
1295 goto issue_ct_rsp_exit
;
1297 icmd
->un
.ulpWord
[3] = ndlp
->nlp_rpi
;
1298 /* The exchange is done, mark the entry as invalid */
1299 phba
->ct_ctx
[tag
].flags
&= ~UNSOL_VALID
;
1301 icmd
->ulpContext
= (ushort
) tag
;
1303 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
1305 /* Xmit CT response on exchange <xid> */
1306 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1307 "2722 Xmit CT response on exchange x%x Data: x%x x%x\n",
1308 icmd
->ulpContext
, icmd
->ulpIoTag
, phba
->link_state
);
1310 ctiocb
->iocb_cmpl
= NULL
;
1311 ctiocb
->iocb_flag
|= LPFC_IO_LIBDFC
;
1312 ctiocb
->vport
= phba
->pport
;
1313 ctiocb
->context3
= bmp
;
1315 ctiocb
->iocb_cmpl
= lpfc_issue_ct_rsp_cmp
;
1316 ctiocb
->context1
= dd_data
;
1317 ctiocb
->context2
= NULL
;
1318 dd_data
->type
= TYPE_IOCB
;
1319 dd_data
->context_un
.iocb
.cmdiocbq
= ctiocb
;
1320 dd_data
->context_un
.iocb
.rspiocbq
= NULL
;
1321 dd_data
->context_un
.iocb
.set_job
= job
;
1322 dd_data
->context_un
.iocb
.bmp
= bmp
;
1323 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
1325 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1326 creg_val
= readl(phba
->HCregaddr
);
1327 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1328 writel(creg_val
, phba
->HCregaddr
);
1329 readl(phba
->HCregaddr
); /* flush */
1332 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
1334 if (rc
== IOCB_SUCCESS
)
1335 return 0; /* done for now */
1338 lpfc_sli_release_iocbq(phba
, ctiocb
);
1346 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1347 * @job: SEND_MGMT_RESP fc_bsg_job
1350 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job
*job
)
1352 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1353 struct lpfc_hba
*phba
= vport
->phba
;
1354 struct send_mgmt_resp
*mgmt_resp
= (struct send_mgmt_resp
*)
1355 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1356 struct ulp_bde64
*bpl
;
1357 struct lpfc_dmabuf
*bmp
= NULL
;
1358 struct scatterlist
*sgel
= NULL
;
1362 uint32_t tag
= mgmt_resp
->tag
;
1363 unsigned long reqbfrcnt
=
1364 (unsigned long)job
->request_payload
.payload_len
;
1367 /* in case no data is transferred */
1368 job
->reply
->reply_payload_rcv_len
= 0;
1370 if (!reqbfrcnt
|| (reqbfrcnt
> (80 * BUF_SZ_4K
))) {
1372 goto send_mgmt_rsp_exit
;
1375 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1378 goto send_mgmt_rsp_exit
;
1381 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
1384 goto send_mgmt_rsp_free_bmp
;
1387 INIT_LIST_HEAD(&bmp
->list
);
1388 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1389 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1390 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1391 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
1392 busaddr
= sg_dma_address(sgel
);
1393 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1394 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1395 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
1396 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
1397 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
1401 rc
= lpfc_issue_ct_rsp(phba
, job
, tag
, bmp
, request_nseg
);
1403 if (rc
== IOCB_SUCCESS
)
1404 return 0; /* done for now */
1406 /* TBD need to handle a timeout */
1407 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1408 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1410 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1412 send_mgmt_rsp_free_bmp
:
1415 /* make error code available to userspace */
1416 job
->reply
->result
= rc
;
1417 job
->dd_data
= NULL
;
1422 * lpfc_bsg_diag_mode - process a LPFC_BSG_VENDOR_DIAG_MODE bsg vendor command
1423 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1425 * This function is responsible for placing a port into diagnostic loopback
1426 * mode in order to perform a diagnostic loopback test.
1427 * All new scsi requests are blocked, a small delay is used to allow the
1428 * scsi requests to complete then the link is brought down. If the link is
1429 * is placed in loopback mode then scsi requests are again allowed
1430 * so the scsi mid-layer doesn't give up on the port.
1431 * All of this is done in-line.
1434 lpfc_bsg_diag_mode(struct fc_bsg_job
*job
)
1436 struct Scsi_Host
*shost
= job
->shost
;
1437 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1438 struct lpfc_hba
*phba
= vport
->phba
;
1439 struct diag_mode_set
*loopback_mode
;
1440 struct lpfc_sli
*psli
= &phba
->sli
;
1441 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_FCP_RING
];
1442 uint32_t link_flags
;
1444 struct lpfc_vport
**vports
;
1445 LPFC_MBOXQ_t
*pmboxq
;
1450 /* no data to return just the return code */
1451 job
->reply
->reply_payload_rcv_len
= 0;
1453 if (job
->request_len
<
1454 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_set
)) {
1455 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1456 "2738 Received DIAG MODE request below minimum "
1462 loopback_mode
= (struct diag_mode_set
*)
1463 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1464 link_flags
= loopback_mode
->type
;
1465 timeout
= loopback_mode
->timeout
;
1467 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1468 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
1469 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
1474 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1480 vports
= lpfc_create_vport_work_array(phba
);
1482 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1483 shost
= lpfc_shost_from_vport(vports
[i
]);
1484 scsi_block_requests(shost
);
1487 lpfc_destroy_vport_work_array(phba
, vports
);
1489 shost
= lpfc_shost_from_vport(phba
->pport
);
1490 scsi_block_requests(shost
);
1493 while (pring
->txcmplq_cnt
) {
1494 if (i
++ > 500) /* wait up to 5 seconds */
1500 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1501 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1502 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1504 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1506 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0)) {
1507 /* wait for link down before proceeding */
1509 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1510 if (i
++ > timeout
) {
1512 goto loopback_mode_exit
;
1518 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1519 if (link_flags
== INTERNAL_LOOP_BACK
)
1520 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
1522 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
=
1523 FLAGS_TOPOLOGY_MODE_LOOP
;
1525 pmboxq
->u
.mb
.mbxCommand
= MBX_INIT_LINK
;
1526 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1528 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1531 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1534 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1535 /* wait for the link attention interrupt */
1539 while (phba
->link_state
!= LPFC_HBA_READY
) {
1540 if (i
++ > timeout
) {
1553 vports
= lpfc_create_vport_work_array(phba
);
1555 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1556 shost
= lpfc_shost_from_vport(vports
[i
]);
1557 scsi_unblock_requests(shost
);
1559 lpfc_destroy_vport_work_array(phba
, vports
);
1561 shost
= lpfc_shost_from_vport(phba
->pport
);
1562 scsi_unblock_requests(shost
);
1566 * Let SLI layer release mboxq if mbox command completed after timeout.
1568 if (mbxstatus
!= MBX_TIMEOUT
)
1569 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1572 /* make error code available to userspace */
1573 job
->reply
->result
= rc
;
1574 /* complete the job back to userspace if no error */
1581 * lpfcdiag_loop_self_reg - obtains a remote port login id
1582 * @phba: Pointer to HBA context object
1583 * @rpi: Pointer to a remote port login id
1585 * This function obtains a remote port login id so the diag loopback test
1586 * can send and receive its own unsolicited CT command.
1588 static int lpfcdiag_loop_self_reg(struct lpfc_hba
*phba
, uint16_t * rpi
)
1591 struct lpfc_dmabuf
*dmabuff
;
1594 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1598 status
= lpfc_reg_rpi(phba
, 0, phba
->pport
->fc_myDID
,
1599 (uint8_t *)&phba
->pport
->fc_sparam
, mbox
, 0);
1601 mempool_free(mbox
, phba
->mbox_mem_pool
);
1605 dmabuff
= (struct lpfc_dmabuf
*) mbox
->context1
;
1606 mbox
->context1
= NULL
;
1607 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
1609 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
1610 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
1612 if (status
!= MBX_TIMEOUT
)
1613 mempool_free(mbox
, phba
->mbox_mem_pool
);
1617 *rpi
= mbox
->u
.mb
.un
.varWords
[0];
1619 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
1621 mempool_free(mbox
, phba
->mbox_mem_pool
);
1626 * lpfcdiag_loop_self_unreg - unregs from the rpi
1627 * @phba: Pointer to HBA context object
1628 * @rpi: Remote port login id
1630 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
1632 static int lpfcdiag_loop_self_unreg(struct lpfc_hba
*phba
, uint16_t rpi
)
1637 /* Allocate mboxq structure */
1638 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1642 lpfc_unreg_login(phba
, 0, rpi
, mbox
);
1643 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
1645 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
1646 if (status
!= MBX_TIMEOUT
)
1647 mempool_free(mbox
, phba
->mbox_mem_pool
);
1651 mempool_free(mbox
, phba
->mbox_mem_pool
);
1656 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
1657 * @phba: Pointer to HBA context object
1658 * @rpi: Remote port login id
1659 * @txxri: Pointer to transmit exchange id
1660 * @rxxri: Pointer to response exchabge id
1662 * This function obtains the transmit and receive ids required to send
1663 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
1664 * flags are used to the unsolicted response handler is able to process
1665 * the ct command sent on the same port.
1667 static int lpfcdiag_loop_get_xri(struct lpfc_hba
*phba
, uint16_t rpi
,
1668 uint16_t *txxri
, uint16_t * rxxri
)
1670 struct lpfc_bsg_event
*evt
;
1671 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
1673 struct lpfc_dmabuf
*dmabuf
;
1674 struct ulp_bde64
*bpl
= NULL
;
1675 struct lpfc_sli_ct_request
*ctreq
= NULL
;
1677 unsigned long flags
;
1681 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
1682 SLI_CT_ELX_LOOPBACK
);
1686 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1687 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1688 lpfc_bsg_event_ref(evt
);
1689 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1691 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
1692 rspiocbq
= lpfc_sli_get_iocbq(phba
);
1694 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1696 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, 0, &dmabuf
->phys
);
1697 INIT_LIST_HEAD(&dmabuf
->list
);
1698 bpl
= (struct ulp_bde64
*) dmabuf
->virt
;
1699 memset(bpl
, 0, sizeof(*bpl
));
1700 ctreq
= (struct lpfc_sli_ct_request
*)(bpl
+ 1);
1702 le32_to_cpu(putPaddrHigh(dmabuf
->phys
+ sizeof(*bpl
)));
1704 le32_to_cpu(putPaddrLow(dmabuf
->phys
+ sizeof(*bpl
)));
1705 bpl
->tus
.f
.bdeFlags
= 0;
1706 bpl
->tus
.f
.bdeSize
= ELX_LOOPBACK_HEADER_SZ
;
1707 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1710 if (cmdiocbq
== NULL
|| rspiocbq
== NULL
||
1711 dmabuf
== NULL
|| bpl
== NULL
|| ctreq
== NULL
) {
1713 goto err_get_xri_exit
;
1716 cmd
= &cmdiocbq
->iocb
;
1717 rsp
= &rspiocbq
->iocb
;
1719 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
1721 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
1722 ctreq
->RevisionId
.bits
.InId
= 0;
1723 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
1724 ctreq
->FsSubType
= 0;
1725 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_XRI_SETUP
;
1726 ctreq
->CommandResponse
.bits
.Size
= 0;
1729 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(dmabuf
->phys
);
1730 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(dmabuf
->phys
);
1731 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1732 cmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(*bpl
);
1734 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= LA
;
1735 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1736 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
1737 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1739 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CR
;
1740 cmd
->ulpBdeCount
= 1;
1742 cmd
->ulpClass
= CLASS3
;
1743 cmd
->ulpContext
= rpi
;
1745 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
1746 cmdiocbq
->vport
= phba
->pport
;
1748 ret_val
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
1750 (phba
->fc_ratov
* 2)
1751 + LPFC_DRVR_TIMEOUT
);
1753 goto err_get_xri_exit
;
1755 *txxri
= rsp
->ulpContext
;
1758 evt
->wait_time_stamp
= jiffies
;
1759 ret_val
= wait_event_interruptible_timeout(
1760 evt
->wq
, !list_empty(&evt
->events_to_see
),
1761 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
1762 if (list_empty(&evt
->events_to_see
))
1763 ret_val
= (ret_val
) ? EINTR
: ETIMEDOUT
;
1765 ret_val
= IOCB_SUCCESS
;
1766 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1767 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
1768 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1769 *rxxri
= (list_entry(evt
->events_to_get
.prev
,
1770 typeof(struct event_data
),
1776 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1777 lpfc_bsg_event_unref(evt
); /* release ref */
1778 lpfc_bsg_event_unref(evt
); /* delete */
1779 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1783 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
1787 if (cmdiocbq
&& (ret_val
!= IOCB_TIMEDOUT
))
1788 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1790 lpfc_sli_release_iocbq(phba
, rspiocbq
);
1795 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
1796 * @phba: Pointer to HBA context object
1797 * @bpl: Pointer to 64 bit bde structure
1798 * @size: Number of bytes to process
1799 * @nocopydata: Flag to copy user data into the allocated buffer
1801 * This function allocates page size buffers and populates an lpfc_dmabufext.
1802 * If allowed the user data pointed to with indataptr is copied into the kernel
1803 * memory. The chained list of page size buffers is returned.
1805 static struct lpfc_dmabufext
*
1806 diag_cmd_data_alloc(struct lpfc_hba
*phba
,
1807 struct ulp_bde64
*bpl
, uint32_t size
,
1810 struct lpfc_dmabufext
*mlist
= NULL
;
1811 struct lpfc_dmabufext
*dmp
;
1812 int cnt
, offset
= 0, i
= 0;
1813 struct pci_dev
*pcidev
;
1815 pcidev
= phba
->pcidev
;
1818 /* We get chunks of 4K */
1819 if (size
> BUF_SZ_4K
)
1824 /* allocate struct lpfc_dmabufext buffer header */
1825 dmp
= kmalloc(sizeof(struct lpfc_dmabufext
), GFP_KERNEL
);
1829 INIT_LIST_HEAD(&dmp
->dma
.list
);
1831 /* Queue it to a linked list */
1833 list_add_tail(&dmp
->dma
.list
, &mlist
->dma
.list
);
1837 /* allocate buffer */
1838 dmp
->dma
.virt
= dma_alloc_coherent(&pcidev
->dev
,
1849 bpl
->tus
.f
.bdeFlags
= 0;
1850 pci_dma_sync_single_for_device(phba
->pcidev
,
1851 dmp
->dma
.phys
, LPFC_BPL_SIZE
, PCI_DMA_TODEVICE
);
1854 memset((uint8_t *)dmp
->dma
.virt
, 0, cnt
);
1855 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
1858 /* build buffer ptr list for IOCB */
1859 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dmp
->dma
.phys
));
1860 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dmp
->dma
.phys
));
1861 bpl
->tus
.f
.bdeSize
= (ushort
) cnt
;
1862 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1873 diag_cmd_data_free(phba
, mlist
);
1878 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
1879 * @phba: Pointer to HBA context object
1880 * @rxxri: Receive exchange id
1881 * @len: Number of data bytes
1883 * This function allocates and posts a data buffer of sufficient size to recieve
1884 * an unsolicted CT command.
1886 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba
*phba
, uint16_t rxxri
,
1889 struct lpfc_sli
*psli
= &phba
->sli
;
1890 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
1891 struct lpfc_iocbq
*cmdiocbq
;
1893 struct list_head head
, *curr
, *next
;
1894 struct lpfc_dmabuf
*rxbmp
;
1895 struct lpfc_dmabuf
*dmp
;
1896 struct lpfc_dmabuf
*mp
[2] = {NULL
, NULL
};
1897 struct ulp_bde64
*rxbpl
= NULL
;
1899 struct lpfc_dmabufext
*rxbuffer
= NULL
;
1903 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
1904 rxbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1905 if (rxbmp
!= NULL
) {
1906 rxbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &rxbmp
->phys
);
1907 INIT_LIST_HEAD(&rxbmp
->list
);
1908 rxbpl
= (struct ulp_bde64
*) rxbmp
->virt
;
1909 rxbuffer
= diag_cmd_data_alloc(phba
, rxbpl
, len
, 0);
1912 if (!cmdiocbq
|| !rxbmp
|| !rxbpl
|| !rxbuffer
) {
1914 goto err_post_rxbufs_exit
;
1917 /* Queue buffers for the receive exchange */
1918 num_bde
= (uint32_t)rxbuffer
->flag
;
1919 dmp
= &rxbuffer
->dma
;
1921 cmd
= &cmdiocbq
->iocb
;
1924 INIT_LIST_HEAD(&head
);
1925 list_add_tail(&head
, &dmp
->list
);
1926 list_for_each_safe(curr
, next
, &head
) {
1927 mp
[i
] = list_entry(curr
, struct lpfc_dmabuf
, list
);
1930 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
1931 mp
[i
]->buffer_tag
= lpfc_sli_get_buffer_tag(phba
);
1932 cmd
->un
.quexri64cx
.buff
.bde
.addrHigh
=
1933 putPaddrHigh(mp
[i
]->phys
);
1934 cmd
->un
.quexri64cx
.buff
.bde
.addrLow
=
1935 putPaddrLow(mp
[i
]->phys
);
1936 cmd
->un
.quexri64cx
.buff
.bde
.tus
.f
.bdeSize
=
1937 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
1938 cmd
->un
.quexri64cx
.buff
.buffer_tag
= mp
[i
]->buffer_tag
;
1939 cmd
->ulpCommand
= CMD_QUE_XRI64_CX
;
1942 cmd
->ulpBdeCount
= 1;
1943 cmd
->unsli3
.que_xri64cx_ext_words
.ebde_count
= 0;
1946 cmd
->un
.cont64
[i
].addrHigh
= putPaddrHigh(mp
[i
]->phys
);
1947 cmd
->un
.cont64
[i
].addrLow
= putPaddrLow(mp
[i
]->phys
);
1948 cmd
->un
.cont64
[i
].tus
.f
.bdeSize
=
1949 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
1950 cmd
->ulpBdeCount
= ++i
;
1952 if ((--num_bde
> 0) && (i
< 2))
1955 cmd
->ulpCommand
= CMD_QUE_XRI_BUF64_CX
;
1959 cmd
->ulpClass
= CLASS3
;
1960 cmd
->ulpContext
= rxxri
;
1962 ret_val
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
1964 if (ret_val
== IOCB_ERROR
) {
1965 diag_cmd_data_free(phba
,
1966 (struct lpfc_dmabufext
*)mp
[0]);
1968 diag_cmd_data_free(phba
,
1969 (struct lpfc_dmabufext
*)mp
[1]);
1970 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
1972 goto err_post_rxbufs_exit
;
1975 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[0]);
1977 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[1]);
1981 /* The iocb was freed by lpfc_sli_issue_iocb */
1982 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
1984 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
1986 goto err_post_rxbufs_exit
;
1989 cmd
= &cmdiocbq
->iocb
;
1994 err_post_rxbufs_exit
:
1998 lpfc_mbuf_free(phba
, rxbmp
->virt
, rxbmp
->phys
);
2003 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2008 * lpfc_bsg_diag_test - with a port in loopback issues a Ct cmd to itself
2009 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2011 * This function receives a user data buffer to be transmitted and received on
2012 * the same port, the link must be up and in loopback mode prior
2014 * 1. A kernel buffer is allocated to copy the user data into.
2015 * 2. The port registers with "itself".
2016 * 3. The transmit and receive exchange ids are obtained.
2017 * 4. The receive exchange id is posted.
2018 * 5. A new els loopback event is created.
2019 * 6. The command and response iocbs are allocated.
2020 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2022 * This function is meant to be called n times while the port is in loopback
2023 * so it is the apps responsibility to issue a reset to take the port out
2027 lpfc_bsg_diag_test(struct fc_bsg_job
*job
)
2029 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2030 struct lpfc_hba
*phba
= vport
->phba
;
2031 struct diag_mode_test
*diag_mode
;
2032 struct lpfc_bsg_event
*evt
;
2033 struct event_data
*evdat
;
2034 struct lpfc_sli
*psli
= &phba
->sli
;
2037 size_t segment_len
= 0, segment_offset
= 0, current_offset
= 0;
2039 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2041 struct lpfc_sli_ct_request
*ctreq
;
2042 struct lpfc_dmabuf
*txbmp
;
2043 struct ulp_bde64
*txbpl
= NULL
;
2044 struct lpfc_dmabufext
*txbuffer
= NULL
;
2045 struct list_head head
;
2046 struct lpfc_dmabuf
*curr
;
2047 uint16_t txxri
, rxxri
;
2049 uint8_t *ptr
= NULL
, *rx_databuf
= NULL
;
2051 unsigned long flags
;
2052 void *dataout
= NULL
;
2055 /* in case no data is returned return just the return code */
2056 job
->reply
->reply_payload_rcv_len
= 0;
2058 if (job
->request_len
<
2059 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_test
)) {
2060 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2061 "2739 Received DIAG TEST request below minimum "
2064 goto loopback_test_exit
;
2067 if (job
->request_payload
.payload_len
!=
2068 job
->reply_payload
.payload_len
) {
2070 goto loopback_test_exit
;
2073 diag_mode
= (struct diag_mode_test
*)
2074 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2076 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
2077 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
2078 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
2080 goto loopback_test_exit
;
2083 if (!lpfc_is_link_up(phba
) || !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
2085 goto loopback_test_exit
;
2088 size
= job
->request_payload
.payload_len
;
2089 full_size
= size
+ ELX_LOOPBACK_HEADER_SZ
; /* plus the header */
2091 if ((size
== 0) || (size
> 80 * BUF_SZ_4K
)) {
2093 goto loopback_test_exit
;
2096 if (size
>= BUF_SZ_4K
) {
2098 * Allocate memory for ioctl data. If buffer is bigger than 64k,
2099 * then we allocate 64k and re-use that buffer over and over to
2100 * xfer the whole block. This is because Linux kernel has a
2101 * problem allocating more than 120k of kernel space memory. Saw
2102 * problem with GET_FCPTARGETMAPPING...
2104 if (size
<= (64 * 1024))
2107 total_mem
= 64 * 1024;
2109 /* Allocate memory for ioctl data */
2110 total_mem
= BUF_SZ_4K
;
2112 dataout
= kmalloc(total_mem
, GFP_KERNEL
);
2113 if (dataout
== NULL
) {
2115 goto loopback_test_exit
;
2119 ptr
+= ELX_LOOPBACK_HEADER_SZ
;
2120 sg_copy_to_buffer(job
->request_payload
.sg_list
,
2121 job
->request_payload
.sg_cnt
,
2124 rc
= lpfcdiag_loop_self_reg(phba
, &rpi
);
2127 goto loopback_test_exit
;
2130 rc
= lpfcdiag_loop_get_xri(phba
, rpi
, &txxri
, &rxxri
);
2132 lpfcdiag_loop_self_unreg(phba
, rpi
);
2134 goto loopback_test_exit
;
2137 rc
= lpfcdiag_loop_post_rxbufs(phba
, rxxri
, full_size
);
2139 lpfcdiag_loop_self_unreg(phba
, rpi
);
2141 goto loopback_test_exit
;
2144 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2145 SLI_CT_ELX_LOOPBACK
);
2147 lpfcdiag_loop_self_unreg(phba
, rpi
);
2149 goto loopback_test_exit
;
2152 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2153 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2154 lpfc_bsg_event_ref(evt
);
2155 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2157 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2158 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2159 txbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2162 txbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &txbmp
->phys
);
2163 INIT_LIST_HEAD(&txbmp
->list
);
2164 txbpl
= (struct ulp_bde64
*) txbmp
->virt
;
2166 txbuffer
= diag_cmd_data_alloc(phba
,
2167 txbpl
, full_size
, 0);
2170 if (!cmdiocbq
|| !rspiocbq
|| !txbmp
|| !txbpl
|| !txbuffer
) {
2172 goto err_loopback_test_exit
;
2175 cmd
= &cmdiocbq
->iocb
;
2176 rsp
= &rspiocbq
->iocb
;
2178 INIT_LIST_HEAD(&head
);
2179 list_add_tail(&head
, &txbuffer
->dma
.list
);
2180 list_for_each_entry(curr
, &head
, list
) {
2181 segment_len
= ((struct lpfc_dmabufext
*)curr
)->size
;
2182 if (current_offset
== 0) {
2184 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2185 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2186 ctreq
->RevisionId
.bits
.InId
= 0;
2187 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2188 ctreq
->FsSubType
= 0;
2189 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_DATA
;
2190 ctreq
->CommandResponse
.bits
.Size
= size
;
2191 segment_offset
= ELX_LOOPBACK_HEADER_SZ
;
2195 BUG_ON(segment_offset
>= segment_len
);
2196 memcpy(curr
->virt
+ segment_offset
,
2197 ptr
+ current_offset
,
2198 segment_len
- segment_offset
);
2200 current_offset
+= segment_len
- segment_offset
;
2201 BUG_ON(current_offset
> size
);
2205 /* Build the XMIT_SEQUENCE iocb */
2207 num_bde
= (uint32_t)txbuffer
->flag
;
2209 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(txbmp
->phys
);
2210 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(txbmp
->phys
);
2211 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2212 cmd
->un
.xseq64
.bdl
.bdeSize
= (num_bde
* sizeof(struct ulp_bde64
));
2214 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
2215 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2216 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2217 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2219 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
2220 cmd
->ulpBdeCount
= 1;
2222 cmd
->ulpClass
= CLASS3
;
2223 cmd
->ulpContext
= txxri
;
2225 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2226 cmdiocbq
->vport
= phba
->pport
;
2228 rc
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
, rspiocbq
,
2229 (phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
);
2231 if ((rc
!= IOCB_SUCCESS
) || (rsp
->ulpStatus
!= IOCB_SUCCESS
)) {
2233 goto err_loopback_test_exit
;
2237 rc
= wait_event_interruptible_timeout(
2238 evt
->wq
, !list_empty(&evt
->events_to_see
),
2239 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
2241 if (list_empty(&evt
->events_to_see
))
2242 rc
= (rc
) ? -EINTR
: -ETIMEDOUT
;
2244 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2245 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2246 evdat
= list_entry(evt
->events_to_get
.prev
,
2247 typeof(*evdat
), node
);
2248 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2249 rx_databuf
= evdat
->data
;
2250 if (evdat
->len
!= full_size
) {
2251 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2252 "1603 Loopback test did not receive expected "
2253 "data length. actual length 0x%x expected "
2255 evdat
->len
, full_size
);
2257 } else if (rx_databuf
== NULL
)
2261 /* skip over elx loopback header */
2262 rx_databuf
+= ELX_LOOPBACK_HEADER_SZ
;
2263 job
->reply
->reply_payload_rcv_len
=
2264 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
2265 job
->reply_payload
.sg_cnt
,
2267 job
->reply
->reply_payload_rcv_len
= size
;
2271 err_loopback_test_exit
:
2272 lpfcdiag_loop_self_unreg(phba
, rpi
);
2274 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2275 lpfc_bsg_event_unref(evt
); /* release ref */
2276 lpfc_bsg_event_unref(evt
); /* delete */
2277 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2279 if (cmdiocbq
!= NULL
)
2280 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2282 if (rspiocbq
!= NULL
)
2283 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2285 if (txbmp
!= NULL
) {
2286 if (txbpl
!= NULL
) {
2287 if (txbuffer
!= NULL
)
2288 diag_cmd_data_free(phba
, txbuffer
);
2289 lpfc_mbuf_free(phba
, txbmp
->virt
, txbmp
->phys
);
2296 /* make error code available to userspace */
2297 job
->reply
->result
= rc
;
2298 job
->dd_data
= NULL
;
2299 /* complete the job back to userspace if no error */
2306 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
2307 * @job: GET_DFC_REV fc_bsg_job
2310 lpfc_bsg_get_dfc_rev(struct fc_bsg_job
*job
)
2312 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2313 struct lpfc_hba
*phba
= vport
->phba
;
2314 struct get_mgmt_rev
*event_req
;
2315 struct get_mgmt_rev_reply
*event_reply
;
2318 if (job
->request_len
<
2319 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev
)) {
2320 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2321 "2740 Received GET_DFC_REV request below "
2327 event_req
= (struct get_mgmt_rev
*)
2328 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2330 event_reply
= (struct get_mgmt_rev_reply
*)
2331 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
2333 if (job
->reply_len
<
2334 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev_reply
)) {
2335 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2336 "2741 Received GET_DFC_REV reply below "
2342 event_reply
->info
.a_Major
= MANAGEMENT_MAJOR_REV
;
2343 event_reply
->info
.a_Minor
= MANAGEMENT_MINOR_REV
;
2345 job
->reply
->result
= rc
;
2352 * lpfc_bsg_wake_mbox_wait - lpfc_bsg_issue_mbox mbox completion handler
2353 * @phba: Pointer to HBA context object.
2354 * @pmboxq: Pointer to mailbox command.
2356 * This is completion handler function for mailbox commands issued from
2357 * lpfc_bsg_issue_mbox function. This function is called by the
2358 * mailbox event handler function with no lock held. This function
2359 * will wake up thread waiting on the wait queue pointed by context1
2363 lpfc_bsg_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2365 struct bsg_job_data
*dd_data
;
2368 struct fc_bsg_job
*job
;
2370 unsigned long flags
;
2372 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2373 dd_data
= pmboxq
->context1
;
2375 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2379 pmb
= &dd_data
->context_un
.mbox
.pmboxq
->u
.mb
;
2380 mb
= dd_data
->context_un
.mbox
.mb
;
2381 job
= dd_data
->context_un
.mbox
.set_job
;
2382 memcpy(mb
, pmb
, sizeof(*pmb
));
2383 size
= job
->request_payload
.payload_len
;
2384 job
->reply
->reply_payload_rcv_len
=
2385 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
2386 job
->reply_payload
.sg_cnt
,
2388 job
->reply
->result
= 0;
2389 dd_data
->context_un
.mbox
.set_job
= NULL
;
2390 job
->dd_data
= NULL
;
2392 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2393 mempool_free(dd_data
->context_un
.mbox
.pmboxq
, phba
->mbox_mem_pool
);
2400 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
2401 * @phba: Pointer to HBA context object.
2402 * @mb: Pointer to a mailbox object.
2403 * @vport: Pointer to a vport object.
2405 * Some commands require the port to be offline, some may not be called from
2408 static int lpfc_bsg_check_cmd_access(struct lpfc_hba
*phba
,
2409 MAILBOX_t
*mb
, struct lpfc_vport
*vport
)
2411 /* return negative error values for bsg job */
2412 switch (mb
->mbxCommand
) {
2416 case MBX_CONFIG_LINK
:
2417 case MBX_CONFIG_RING
:
2418 case MBX_RESET_RING
:
2419 case MBX_UNREG_LOGIN
:
2421 case MBX_DUMP_CONTEXT
:
2425 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
2426 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2427 "2743 Command 0x%x is illegal in on-line "
2433 case MBX_WRITE_VPARMS
:
2436 case MBX_READ_CONFIG
:
2437 case MBX_READ_RCONFIG
:
2438 case MBX_READ_STATUS
:
2441 case MBX_READ_LNK_STAT
:
2442 case MBX_DUMP_MEMORY
:
2444 case MBX_UPDATE_CFG
:
2445 case MBX_KILL_BOARD
:
2447 case MBX_LOAD_EXP_ROM
:
2449 case MBX_DEL_LD_ENTRY
:
2452 case MBX_SLI4_CONFIG
:
2453 case MBX_READ_EVENT_LOG_STATUS
:
2454 case MBX_WRITE_EVENT_LOG
:
2455 case MBX_PORT_CAPABILITIES
:
2456 case MBX_PORT_IOV_CONTROL
:
2458 case MBX_SET_VARIABLE
:
2459 case MBX_RUN_BIU_DIAG64
:
2460 case MBX_READ_EVENT_LOG
:
2461 case MBX_READ_SPARM64
:
2465 case MBX_REG_LOGIN64
:
2466 case MBX_CONFIG_PORT
:
2467 case MBX_RUN_BIU_DIAG
:
2469 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2470 "2742 Unknown Command 0x%x\n",
2479 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
2480 * @phba: Pointer to HBA context object.
2481 * @mb: Pointer to a mailbox object.
2482 * @vport: Pointer to a vport object.
2484 * Allocate a tracking object, mailbox command memory, get a mailbox
2485 * from the mailbox pool, copy the caller mailbox command.
2487 * If offline and the sli is active we need to poll for the command (port is
2488 * being reset) and com-plete the job, otherwise issue the mailbox command and
2489 * let our completion handler finish the command.
2492 lpfc_bsg_issue_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
2493 struct lpfc_vport
*vport
)
2495 LPFC_MBOXQ_t
*pmboxq
;
2498 struct bsg_job_data
*dd_data
;
2502 /* allocate our bsg tracking structure */
2503 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
2505 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2506 "2727 Failed allocation of dd_data\n");
2510 mb
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
2516 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2523 size
= job
->request_payload
.payload_len
;
2524 job
->reply
->reply_payload_rcv_len
=
2525 sg_copy_to_buffer(job
->request_payload
.sg_list
,
2526 job
->request_payload
.sg_cnt
,
2529 rc
= lpfc_bsg_check_cmd_access(phba
, mb
, vport
);
2533 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2534 return rc
; /* must be negative */
2537 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
2538 pmb
= &pmboxq
->u
.mb
;
2539 memcpy(pmb
, mb
, sizeof(*pmb
));
2540 pmb
->mbxOwner
= OWN_HOST
;
2541 pmboxq
->context1
= NULL
;
2542 pmboxq
->vport
= vport
;
2544 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
2545 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
2546 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2547 if (rc
!= MBX_SUCCESS
) {
2548 if (rc
!= MBX_TIMEOUT
) {
2551 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2553 return (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
2556 memcpy(mb
, pmb
, sizeof(*pmb
));
2557 job
->reply
->reply_payload_rcv_len
=
2558 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
2559 job
->reply_payload
.sg_cnt
,
2563 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2564 /* not waiting mbox already done */
2568 /* setup wake call as IOCB callback */
2569 pmboxq
->mbox_cmpl
= lpfc_bsg_wake_mbox_wait
;
2570 /* setup context field to pass wait_queue pointer to wake function */
2571 pmboxq
->context1
= dd_data
;
2572 dd_data
->type
= TYPE_MBOX
;
2573 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
2574 dd_data
->context_un
.mbox
.mb
= mb
;
2575 dd_data
->context_un
.mbox
.set_job
= job
;
2576 job
->dd_data
= dd_data
;
2577 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
2578 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
2581 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2589 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
2590 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
2593 lpfc_bsg_mbox_cmd(struct fc_bsg_job
*job
)
2595 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2596 struct lpfc_hba
*phba
= vport
->phba
;
2599 /* in case no data is transferred */
2600 job
->reply
->reply_payload_rcv_len
= 0;
2601 if (job
->request_len
<
2602 sizeof(struct fc_bsg_request
) + sizeof(struct dfc_mbox_req
)) {
2603 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2604 "2737 Received MBOX_REQ request below "
2610 if (job
->request_payload
.payload_len
!= PAGE_SIZE
) {
2615 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
2620 rc
= lpfc_bsg_issue_mbox(phba
, job
, vport
);
2625 job
->reply
->result
= 0;
2626 job
->dd_data
= NULL
;
2629 /* job submitted, will complete later*/
2630 rc
= 0; /* return zero, no error */
2632 /* some error occurred */
2633 job
->reply
->result
= rc
;
2634 job
->dd_data
= NULL
;
2641 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
2642 * @job: fc_bsg_job to handle
2645 lpfc_bsg_hst_vendor(struct fc_bsg_job
*job
)
2647 int command
= job
->request
->rqst_data
.h_vendor
.vendor_cmd
[0];
2651 case LPFC_BSG_VENDOR_SET_CT_EVENT
:
2652 rc
= lpfc_bsg_hba_set_event(job
);
2654 case LPFC_BSG_VENDOR_GET_CT_EVENT
:
2655 rc
= lpfc_bsg_hba_get_event(job
);
2657 case LPFC_BSG_VENDOR_SEND_MGMT_RESP
:
2658 rc
= lpfc_bsg_send_mgmt_rsp(job
);
2660 case LPFC_BSG_VENDOR_DIAG_MODE
:
2661 rc
= lpfc_bsg_diag_mode(job
);
2663 case LPFC_BSG_VENDOR_DIAG_TEST
:
2664 rc
= lpfc_bsg_diag_test(job
);
2666 case LPFC_BSG_VENDOR_GET_MGMT_REV
:
2667 rc
= lpfc_bsg_get_dfc_rev(job
);
2669 case LPFC_BSG_VENDOR_MBOX
:
2670 rc
= lpfc_bsg_mbox_cmd(job
);
2674 job
->reply
->reply_payload_rcv_len
= 0;
2675 /* make error code available to userspace */
2676 job
->reply
->result
= rc
;
2684 * lpfc_bsg_request - handle a bsg request from the FC transport
2685 * @job: fc_bsg_job to handle
2688 lpfc_bsg_request(struct fc_bsg_job
*job
)
2693 msgcode
= job
->request
->msgcode
;
2695 case FC_BSG_HST_VENDOR
:
2696 rc
= lpfc_bsg_hst_vendor(job
);
2698 case FC_BSG_RPT_ELS
:
2699 rc
= lpfc_bsg_rport_els(job
);
2702 rc
= lpfc_bsg_send_mgmt_cmd(job
);
2706 job
->reply
->reply_payload_rcv_len
= 0;
2707 /* make error code available to userspace */
2708 job
->reply
->result
= rc
;
2716 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
2717 * @job: fc_bsg_job that has timed out
2719 * This function just aborts the job's IOCB. The aborted IOCB will return to
2720 * the waiting function which will handle passing the error back to userspace
2723 lpfc_bsg_timeout(struct fc_bsg_job
*job
)
2725 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2726 struct lpfc_hba
*phba
= vport
->phba
;
2727 struct lpfc_iocbq
*cmdiocb
;
2728 struct lpfc_bsg_event
*evt
;
2729 struct lpfc_bsg_iocb
*iocb
;
2730 struct lpfc_bsg_mbox
*mbox
;
2731 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
2732 struct bsg_job_data
*dd_data
;
2733 unsigned long flags
;
2735 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2736 dd_data
= (struct bsg_job_data
*)job
->dd_data
;
2737 /* timeout and completion crossed paths if no dd_data */
2739 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2743 switch (dd_data
->type
) {
2745 iocb
= &dd_data
->context_un
.iocb
;
2746 cmdiocb
= iocb
->cmdiocbq
;
2747 /* hint to completion handler that the job timed out */
2748 job
->reply
->result
= -EAGAIN
;
2749 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2750 /* this will call our completion handler */
2751 spin_lock_irq(&phba
->hbalock
);
2752 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
2753 spin_unlock_irq(&phba
->hbalock
);
2756 evt
= dd_data
->context_un
.evt
;
2757 /* this event has no job anymore */
2758 evt
->set_job
= NULL
;
2759 job
->dd_data
= NULL
;
2760 job
->reply
->reply_payload_rcv_len
= 0;
2761 /* Return -EAGAIN which is our way of signallying the
2764 job
->reply
->result
= -EAGAIN
;
2765 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2769 mbox
= &dd_data
->context_un
.mbox
;
2770 /* this mbox has no job anymore */
2771 mbox
->set_job
= NULL
;
2772 job
->dd_data
= NULL
;
2773 job
->reply
->reply_payload_rcv_len
= 0;
2774 job
->reply
->result
= -EAGAIN
;
2775 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2779 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2783 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
2784 * otherwise an error message will be displayed on the console
2785 * so always return success (zero)