1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009-2015 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/slab.h>
25 #include <linux/delay.h>
26 #include <linux/list.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
31 #include <scsi/scsi_bsg_fc.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_debugfs.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_version.h"
49 struct lpfc_bsg_event
{
50 struct list_head node
;
54 /* Event type and waiter identifiers */
59 /* next two flags are here for the auto-delete logic */
60 unsigned long wait_time_stamp
;
63 /* seen and not seen events */
64 struct list_head events_to_get
;
65 struct list_head events_to_see
;
67 /* driver data associated with the job */
71 struct lpfc_bsg_iocb
{
72 struct lpfc_iocbq
*cmdiocbq
;
73 struct lpfc_dmabuf
*rmp
;
74 struct lpfc_nodelist
*ndlp
;
77 struct lpfc_bsg_mbox
{
80 struct lpfc_dmabuf
*dmabuffers
; /* for BIU diags */
81 uint8_t *ext
; /* extended mailbox data */
82 uint32_t mbOffset
; /* from app */
83 uint32_t inExtWLen
; /* from app */
84 uint32_t outExtWLen
; /* from app */
87 #define MENLO_DID 0x0000FC0E
89 struct lpfc_bsg_menlo
{
90 struct lpfc_iocbq
*cmdiocbq
;
91 struct lpfc_dmabuf
*rmp
;
100 struct fc_bsg_job
*set_job
; /* job waiting for this iocb to finish */
102 struct lpfc_bsg_event
*evt
;
103 struct lpfc_bsg_iocb iocb
;
104 struct lpfc_bsg_mbox mbox
;
105 struct lpfc_bsg_menlo menlo
;
110 struct list_head node
;
117 #define BUF_SZ_4K 4096
118 #define SLI_CT_ELX_LOOPBACK 0x10
120 enum ELX_LOOPBACK_CMD
{
121 ELX_LOOPBACK_XRI_SETUP
,
125 #define ELX_LOOPBACK_HEADER_SZ \
126 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
128 struct lpfc_dmabufext
{
129 struct lpfc_dmabuf dma
;
135 lpfc_free_bsg_buffers(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*mlist
)
137 struct lpfc_dmabuf
*mlast
, *next_mlast
;
140 list_for_each_entry_safe(mlast
, next_mlast
, &mlist
->list
,
142 lpfc_mbuf_free(phba
, mlast
->virt
, mlast
->phys
);
143 list_del(&mlast
->list
);
146 lpfc_mbuf_free(phba
, mlist
->virt
, mlist
->phys
);
152 static struct lpfc_dmabuf
*
153 lpfc_alloc_bsg_buffers(struct lpfc_hba
*phba
, unsigned int size
,
154 int outbound_buffers
, struct ulp_bde64
*bpl
,
157 struct lpfc_dmabuf
*mlist
= NULL
;
158 struct lpfc_dmabuf
*mp
;
159 unsigned int bytes_left
= size
;
161 /* Verify we can support the size specified */
162 if (!size
|| (size
> (*bpl_entries
* LPFC_BPL_SIZE
)))
165 /* Determine the number of dma buffers to allocate */
166 *bpl_entries
= (size
% LPFC_BPL_SIZE
? size
/LPFC_BPL_SIZE
+ 1 :
169 /* Allocate dma buffer and place in BPL passed */
171 /* Allocate dma buffer */
172 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
175 lpfc_free_bsg_buffers(phba
, mlist
);
179 INIT_LIST_HEAD(&mp
->list
);
180 mp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &(mp
->phys
));
185 lpfc_free_bsg_buffers(phba
, mlist
);
189 /* Queue it to a linked list */
193 list_add_tail(&mp
->list
, &mlist
->list
);
195 /* Add buffer to buffer pointer list */
196 if (outbound_buffers
)
197 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
199 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
200 bpl
->addrLow
= le32_to_cpu(putPaddrLow(mp
->phys
));
201 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(mp
->phys
));
202 bpl
->tus
.f
.bdeSize
= (uint16_t)
203 (bytes_left
>= LPFC_BPL_SIZE
? LPFC_BPL_SIZE
:
205 bytes_left
-= bpl
->tus
.f
.bdeSize
;
206 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
213 lpfc_bsg_copy_data(struct lpfc_dmabuf
*dma_buffers
,
214 struct fc_bsg_buffer
*bsg_buffers
,
215 unsigned int bytes_to_transfer
, int to_buffers
)
218 struct lpfc_dmabuf
*mp
;
219 unsigned int transfer_bytes
, bytes_copied
= 0;
220 unsigned int sg_offset
, dma_offset
;
221 unsigned char *dma_address
, *sg_address
;
222 LIST_HEAD(temp_list
);
223 struct sg_mapping_iter miter
;
225 unsigned int sg_flags
= SG_MITER_ATOMIC
;
228 list_splice_init(&dma_buffers
->list
, &temp_list
);
229 list_add(&dma_buffers
->list
, &temp_list
);
232 sg_flags
|= SG_MITER_FROM_SG
;
234 sg_flags
|= SG_MITER_TO_SG
;
235 sg_miter_start(&miter
, bsg_buffers
->sg_list
, bsg_buffers
->sg_cnt
,
237 local_irq_save(flags
);
238 sg_valid
= sg_miter_next(&miter
);
239 list_for_each_entry(mp
, &temp_list
, list
) {
241 while (bytes_to_transfer
&& sg_valid
&&
242 (dma_offset
< LPFC_BPL_SIZE
)) {
243 dma_address
= mp
->virt
+ dma_offset
;
245 /* Continue previous partial transfer of sg */
246 sg_address
= miter
.addr
+ sg_offset
;
247 transfer_bytes
= miter
.length
- sg_offset
;
249 sg_address
= miter
.addr
;
250 transfer_bytes
= miter
.length
;
252 if (bytes_to_transfer
< transfer_bytes
)
253 transfer_bytes
= bytes_to_transfer
;
254 if (transfer_bytes
> (LPFC_BPL_SIZE
- dma_offset
))
255 transfer_bytes
= LPFC_BPL_SIZE
- dma_offset
;
257 memcpy(dma_address
, sg_address
, transfer_bytes
);
259 memcpy(sg_address
, dma_address
, transfer_bytes
);
260 dma_offset
+= transfer_bytes
;
261 sg_offset
+= transfer_bytes
;
262 bytes_to_transfer
-= transfer_bytes
;
263 bytes_copied
+= transfer_bytes
;
264 if (sg_offset
>= miter
.length
) {
266 sg_valid
= sg_miter_next(&miter
);
270 sg_miter_stop(&miter
);
271 local_irq_restore(flags
);
272 list_del_init(&dma_buffers
->list
);
273 list_splice(&temp_list
, &dma_buffers
->list
);
278 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
279 * @phba: Pointer to HBA context object.
280 * @cmdiocbq: Pointer to command iocb.
281 * @rspiocbq: Pointer to response iocb.
283 * This function is the completion handler for iocbs issued using
284 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
285 * ring event handler function without any lock held. This function
286 * can be called from both worker thread context and interrupt
287 * context. This function also can be called from another thread which
288 * cleans up the SLI layer objects.
289 * This function copies the contents of the response iocb to the
290 * response iocb memory object provided by the caller of
291 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
292 * sleeps for the iocb completion.
295 lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba
*phba
,
296 struct lpfc_iocbq
*cmdiocbq
,
297 struct lpfc_iocbq
*rspiocbq
)
299 struct bsg_job_data
*dd_data
;
300 struct fc_bsg_job
*job
;
302 struct lpfc_dmabuf
*bmp
, *cmp
, *rmp
;
303 struct lpfc_nodelist
*ndlp
;
304 struct lpfc_bsg_iocb
*iocb
;
306 unsigned int rsp_size
;
309 dd_data
= cmdiocbq
->context1
;
311 /* Determine if job has been aborted */
312 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
313 job
= dd_data
->set_job
;
315 /* Prevent timeout handling from trying to abort job */
318 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
320 /* Close the timeout handler abort window */
321 spin_lock_irqsave(&phba
->hbalock
, flags
);
322 cmdiocbq
->iocb_flag
&= ~LPFC_IO_CMD_OUTSTANDING
;
323 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
325 iocb
= &dd_data
->context_un
.iocb
;
328 cmp
= cmdiocbq
->context2
;
329 bmp
= cmdiocbq
->context3
;
330 rsp
= &rspiocbq
->iocb
;
332 /* Copy the completed data or set the error status */
335 if (rsp
->ulpStatus
) {
336 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
337 switch (rsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) {
338 case IOERR_SEQUENCE_TIMEOUT
:
341 case IOERR_INVALID_RPI
:
352 rsp_size
= rsp
->un
.genreq64
.bdl
.bdeSize
;
353 job
->reply
->reply_payload_rcv_len
=
354 lpfc_bsg_copy_data(rmp
, &job
->reply_payload
,
359 lpfc_free_bsg_buffers(phba
, cmp
);
360 lpfc_free_bsg_buffers(phba
, rmp
);
361 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
363 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
367 /* Complete the job if the job is still active */
370 job
->reply
->result
= rc
;
377 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
378 * @job: fc_bsg_job to handle
381 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job
*job
)
383 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
384 struct lpfc_hba
*phba
= vport
->phba
;
385 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
386 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
387 struct ulp_bde64
*bpl
= NULL
;
389 struct lpfc_iocbq
*cmdiocbq
= NULL
;
391 struct lpfc_dmabuf
*bmp
= NULL
, *cmp
= NULL
, *rmp
= NULL
;
394 struct bsg_job_data
*dd_data
;
400 /* in case no data is transferred */
401 job
->reply
->reply_payload_rcv_len
= 0;
403 /* allocate our bsg tracking structure */
404 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
406 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
407 "2733 Failed allocation of dd_data\n");
412 if (!lpfc_nlp_get(ndlp
)) {
417 if (ndlp
->nlp_flag
& NLP_ELS_SND_MASK
) {
422 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
428 cmd
= &cmdiocbq
->iocb
;
430 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
435 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
441 INIT_LIST_HEAD(&bmp
->list
);
443 bpl
= (struct ulp_bde64
*) bmp
->virt
;
444 request_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
);
445 cmp
= lpfc_alloc_bsg_buffers(phba
, job
->request_payload
.payload_len
,
446 1, bpl
, &request_nseg
);
451 lpfc_bsg_copy_data(cmp
, &job
->request_payload
,
452 job
->request_payload
.payload_len
, 1);
455 reply_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
) - request_nseg
;
456 rmp
= lpfc_alloc_bsg_buffers(phba
, job
->reply_payload
.payload_len
, 0,
463 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
464 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
465 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
466 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
467 cmd
->un
.genreq64
.bdl
.bdeSize
=
468 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
469 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
470 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
471 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
472 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
473 cmd
->un
.genreq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
474 cmd
->ulpBdeCount
= 1;
476 cmd
->ulpClass
= CLASS3
;
477 cmd
->ulpContext
= ndlp
->nlp_rpi
;
478 if (phba
->sli_rev
== LPFC_SLI_REV4
)
479 cmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
480 cmd
->ulpOwner
= OWN_CHIP
;
481 cmdiocbq
->vport
= phba
->pport
;
482 cmdiocbq
->context3
= bmp
;
483 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
484 timeout
= phba
->fc_ratov
* 2;
485 cmd
->ulpTimeout
= timeout
;
487 cmdiocbq
->iocb_cmpl
= lpfc_bsg_send_mgmt_cmd_cmp
;
488 cmdiocbq
->context1
= dd_data
;
489 cmdiocbq
->context2
= cmp
;
490 cmdiocbq
->context3
= bmp
;
491 cmdiocbq
->context_un
.ndlp
= ndlp
;
492 dd_data
->type
= TYPE_IOCB
;
493 dd_data
->set_job
= job
;
494 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
495 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
496 dd_data
->context_un
.iocb
.rmp
= rmp
;
497 job
->dd_data
= dd_data
;
499 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
500 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
504 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
505 writel(creg_val
, phba
->HCregaddr
);
506 readl(phba
->HCregaddr
); /* flush */
509 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
511 if (iocb_stat
== IOCB_SUCCESS
) {
512 spin_lock_irqsave(&phba
->hbalock
, flags
);
513 /* make sure the I/O had not been completed yet */
514 if (cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
515 /* open up abort window to timeout handler */
516 cmdiocbq
->iocb_flag
|= LPFC_IO_CMD_OUTSTANDING
;
518 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
519 return 0; /* done for now */
520 } else if (iocb_stat
== IOCB_BUSY
) {
526 /* iocb failed so cleanup */
530 lpfc_free_bsg_buffers(phba
, rmp
);
532 lpfc_free_bsg_buffers(phba
, cmp
);
535 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
538 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
544 /* make error code available to userspace */
545 job
->reply
->result
= rc
;
551 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
552 * @phba: Pointer to HBA context object.
553 * @cmdiocbq: Pointer to command iocb.
554 * @rspiocbq: Pointer to response iocb.
556 * This function is the completion handler for iocbs issued using
557 * lpfc_bsg_rport_els_cmp function. This function is called by the
558 * ring event handler function without any lock held. This function
559 * can be called from both worker thread context and interrupt
560 * context. This function also can be called from other thread which
561 * cleans up the SLI layer objects.
562 * This function copies the contents of the response iocb to the
563 * response iocb memory object provided by the caller of
564 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
565 * sleeps for the iocb completion.
568 lpfc_bsg_rport_els_cmp(struct lpfc_hba
*phba
,
569 struct lpfc_iocbq
*cmdiocbq
,
570 struct lpfc_iocbq
*rspiocbq
)
572 struct bsg_job_data
*dd_data
;
573 struct fc_bsg_job
*job
;
575 struct lpfc_nodelist
*ndlp
;
576 struct lpfc_dmabuf
*pcmd
= NULL
, *prsp
= NULL
;
577 struct fc_bsg_ctels_reply
*els_reply
;
580 unsigned int rsp_size
;
583 dd_data
= cmdiocbq
->context1
;
584 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
585 cmdiocbq
->context1
= ndlp
;
587 /* Determine if job has been aborted */
588 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
589 job
= dd_data
->set_job
;
591 /* Prevent timeout handling from trying to abort job */
594 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
596 /* Close the timeout handler abort window */
597 spin_lock_irqsave(&phba
->hbalock
, flags
);
598 cmdiocbq
->iocb_flag
&= ~LPFC_IO_CMD_OUTSTANDING
;
599 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
601 rsp
= &rspiocbq
->iocb
;
602 pcmd
= (struct lpfc_dmabuf
*)cmdiocbq
->context2
;
603 prsp
= (struct lpfc_dmabuf
*)pcmd
->list
.next
;
605 /* Copy the completed job data or determine the job status if job is
610 if (rsp
->ulpStatus
== IOSTAT_SUCCESS
) {
611 rsp_size
= rsp
->un
.elsreq64
.bdl
.bdeSize
;
612 job
->reply
->reply_payload_rcv_len
=
613 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
614 job
->reply_payload
.sg_cnt
,
617 } else if (rsp
->ulpStatus
== IOSTAT_LS_RJT
) {
618 job
->reply
->reply_payload_rcv_len
=
619 sizeof(struct fc_bsg_ctels_reply
);
620 /* LS_RJT data returned in word 4 */
621 rjt_data
= (uint8_t *)&rsp
->un
.ulpWord
[4];
622 els_reply
= &job
->reply
->reply_data
.ctels_reply
;
623 els_reply
->status
= FC_CTELS_STATUS_REJECT
;
624 els_reply
->rjt_data
.action
= rjt_data
[3];
625 els_reply
->rjt_data
.reason_code
= rjt_data
[2];
626 els_reply
->rjt_data
.reason_explanation
= rjt_data
[1];
627 els_reply
->rjt_data
.vendor_unique
= rjt_data
[0];
634 lpfc_els_free_iocb(phba
, cmdiocbq
);
637 /* Complete the job if the job is still active */
640 job
->reply
->result
= rc
;
647 * lpfc_bsg_rport_els - send an ELS command from a bsg request
648 * @job: fc_bsg_job to handle
651 lpfc_bsg_rport_els(struct fc_bsg_job
*job
)
653 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
654 struct lpfc_hba
*phba
= vport
->phba
;
655 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
656 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
659 struct lpfc_iocbq
*cmdiocbq
;
661 struct bsg_job_data
*dd_data
;
666 /* in case no data is transferred */
667 job
->reply
->reply_payload_rcv_len
= 0;
669 /* verify the els command is not greater than the
670 * maximum ELS transfer size.
673 if (job
->request_payload
.payload_len
> FCELSSIZE
) {
678 /* allocate our bsg tracking structure */
679 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
681 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
682 "2735 Failed allocation of dd_data\n");
687 elscmd
= job
->request
->rqst_data
.r_els
.els_code
;
688 cmdsize
= job
->request_payload
.payload_len
;
690 if (!lpfc_nlp_get(ndlp
)) {
695 /* We will use the allocated dma buffers by prep els iocb for command
696 * and response to ensure if the job times out and the request is freed,
697 * we won't be dma into memory that is no longer allocated to for the
701 cmdiocbq
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
,
702 ndlp
->nlp_DID
, elscmd
);
710 /* Transfer the request payload to allocated command dma buffer */
712 sg_copy_to_buffer(job
->request_payload
.sg_list
,
713 job
->request_payload
.sg_cnt
,
714 ((struct lpfc_dmabuf
*)cmdiocbq
->context2
)->virt
,
717 if (phba
->sli_rev
== LPFC_SLI_REV4
)
718 cmdiocbq
->iocb
.ulpContext
= phba
->sli4_hba
.rpi_ids
[rpi
];
720 cmdiocbq
->iocb
.ulpContext
= rpi
;
721 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
722 cmdiocbq
->context1
= dd_data
;
723 cmdiocbq
->context_un
.ndlp
= ndlp
;
724 cmdiocbq
->iocb_cmpl
= lpfc_bsg_rport_els_cmp
;
725 dd_data
->type
= TYPE_IOCB
;
726 dd_data
->set_job
= job
;
727 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
728 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
729 dd_data
->context_un
.iocb
.rmp
= NULL
;
730 job
->dd_data
= dd_data
;
732 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
733 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
737 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
738 writel(creg_val
, phba
->HCregaddr
);
739 readl(phba
->HCregaddr
); /* flush */
742 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
744 if (rc
== IOCB_SUCCESS
) {
745 spin_lock_irqsave(&phba
->hbalock
, flags
);
746 /* make sure the I/O had not been completed/released */
747 if (cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
748 /* open up abort window to timeout handler */
749 cmdiocbq
->iocb_flag
|= LPFC_IO_CMD_OUTSTANDING
;
751 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
752 return 0; /* done for now */
753 } else if (rc
== IOCB_BUSY
) {
759 /* iocb failed so cleanup */
763 cmdiocbq
->context1
= ndlp
;
764 lpfc_els_free_iocb(phba
, cmdiocbq
);
773 /* make error code available to userspace */
774 job
->reply
->result
= rc
;
780 * lpfc_bsg_event_free - frees an allocated event structure
781 * @kref: Pointer to a kref.
783 * Called from kref_put. Back cast the kref into an event structure address.
784 * Free any events to get, delete associated nodes, free any events to see,
785 * free any data then free the event itself.
788 lpfc_bsg_event_free(struct kref
*kref
)
790 struct lpfc_bsg_event
*evt
= container_of(kref
, struct lpfc_bsg_event
,
792 struct event_data
*ed
;
794 list_del(&evt
->node
);
796 while (!list_empty(&evt
->events_to_get
)) {
797 ed
= list_entry(evt
->events_to_get
.next
, typeof(*ed
), node
);
803 while (!list_empty(&evt
->events_to_see
)) {
804 ed
= list_entry(evt
->events_to_see
.next
, typeof(*ed
), node
);
815 * lpfc_bsg_event_ref - increments the kref for an event
816 * @evt: Pointer to an event structure.
819 lpfc_bsg_event_ref(struct lpfc_bsg_event
*evt
)
821 kref_get(&evt
->kref
);
825 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
826 * @evt: Pointer to an event structure.
829 lpfc_bsg_event_unref(struct lpfc_bsg_event
*evt
)
831 kref_put(&evt
->kref
, lpfc_bsg_event_free
);
835 * lpfc_bsg_event_new - allocate and initialize a event structure
836 * @ev_mask: Mask of events.
837 * @ev_reg_id: Event reg id.
838 * @ev_req_id: Event request id.
840 static struct lpfc_bsg_event
*
841 lpfc_bsg_event_new(uint32_t ev_mask
, int ev_reg_id
, uint32_t ev_req_id
)
843 struct lpfc_bsg_event
*evt
= kzalloc(sizeof(*evt
), GFP_KERNEL
);
848 INIT_LIST_HEAD(&evt
->events_to_get
);
849 INIT_LIST_HEAD(&evt
->events_to_see
);
850 evt
->type_mask
= ev_mask
;
851 evt
->req_id
= ev_req_id
;
852 evt
->reg_id
= ev_reg_id
;
853 evt
->wait_time_stamp
= jiffies
;
855 init_waitqueue_head(&evt
->wq
);
856 kref_init(&evt
->kref
);
861 * diag_cmd_data_free - Frees an lpfc dma buffer extension
862 * @phba: Pointer to HBA context object.
863 * @mlist: Pointer to an lpfc dma buffer extension.
866 diag_cmd_data_free(struct lpfc_hba
*phba
, struct lpfc_dmabufext
*mlist
)
868 struct lpfc_dmabufext
*mlast
;
869 struct pci_dev
*pcidev
;
870 struct list_head head
, *curr
, *next
;
872 if ((!mlist
) || (!lpfc_is_link_up(phba
) &&
873 (phba
->link_flag
& LS_LOOPBACK_MODE
))) {
877 pcidev
= phba
->pcidev
;
878 list_add_tail(&head
, &mlist
->dma
.list
);
880 list_for_each_safe(curr
, next
, &head
) {
881 mlast
= list_entry(curr
, struct lpfc_dmabufext
, dma
.list
);
883 dma_free_coherent(&pcidev
->dev
,
893 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
898 * This function is called when an unsolicited CT command is received. It
899 * forwards the event to any processes registered to receive CT events.
902 lpfc_bsg_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
903 struct lpfc_iocbq
*piocbq
)
905 uint32_t evt_req_id
= 0;
907 struct lpfc_dmabuf
*dmabuf
= NULL
;
908 struct lpfc_bsg_event
*evt
;
909 struct event_data
*evt_dat
= NULL
;
910 struct lpfc_iocbq
*iocbq
;
912 struct list_head head
;
913 struct ulp_bde64
*bde
;
916 struct lpfc_dmabuf
*bdeBuf1
= piocbq
->context2
;
917 struct lpfc_dmabuf
*bdeBuf2
= piocbq
->context3
;
918 struct lpfc_hbq_entry
*hbqe
;
919 struct lpfc_sli_ct_request
*ct_req
;
920 struct fc_bsg_job
*job
= NULL
;
921 struct bsg_job_data
*dd_data
= NULL
;
925 INIT_LIST_HEAD(&head
);
926 list_add_tail(&head
, &piocbq
->list
);
928 if (piocbq
->iocb
.ulpBdeCount
== 0 ||
929 piocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
== 0)
930 goto error_ct_unsol_exit
;
932 if (phba
->link_state
== LPFC_HBA_ERROR
||
933 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)))
934 goto error_ct_unsol_exit
;
936 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
939 dma_addr
= getPaddr(piocbq
->iocb
.un
.cont64
[0].addrHigh
,
940 piocbq
->iocb
.un
.cont64
[0].addrLow
);
941 dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
, dma_addr
);
944 goto error_ct_unsol_exit
;
945 ct_req
= (struct lpfc_sli_ct_request
*)dmabuf
->virt
;
946 evt_req_id
= ct_req
->FsType
;
947 cmd
= ct_req
->CommandResponse
.bits
.CmdRsp
;
948 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
949 lpfc_sli_ringpostbuf_put(phba
, pring
, dmabuf
);
951 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
952 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
953 if (!(evt
->type_mask
& FC_REG_CT_EVENT
) ||
954 evt
->req_id
!= evt_req_id
)
957 lpfc_bsg_event_ref(evt
);
958 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
959 evt_dat
= kzalloc(sizeof(*evt_dat
), GFP_KERNEL
);
960 if (evt_dat
== NULL
) {
961 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
962 lpfc_bsg_event_unref(evt
);
963 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
964 "2614 Memory allocation failed for "
969 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
970 /* take accumulated byte count from the last iocbq */
971 iocbq
= list_entry(head
.prev
, typeof(*iocbq
), list
);
972 evt_dat
->len
= iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
;
974 list_for_each_entry(iocbq
, &head
, list
) {
975 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++)
977 iocbq
->iocb
.un
.cont64
[i
].tus
.f
.bdeSize
;
981 evt_dat
->data
= kzalloc(evt_dat
->len
, GFP_KERNEL
);
982 if (evt_dat
->data
== NULL
) {
983 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
984 "2615 Memory allocation failed for "
985 "CT event data, size %d\n",
988 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
989 lpfc_bsg_event_unref(evt
);
990 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
991 goto error_ct_unsol_exit
;
994 list_for_each_entry(iocbq
, &head
, list
) {
996 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
997 bdeBuf1
= iocbq
->context2
;
998 bdeBuf2
= iocbq
->context3
;
1000 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++) {
1001 if (phba
->sli3_options
&
1002 LPFC_SLI3_HBQ_ENABLED
) {
1004 hbqe
= (struct lpfc_hbq_entry
*)
1005 &iocbq
->iocb
.un
.ulpWord
[0];
1006 size
= hbqe
->bde
.tus
.f
.bdeSize
;
1008 } else if (i
== 1) {
1009 hbqe
= (struct lpfc_hbq_entry
*)
1010 &iocbq
->iocb
.unsli3
.
1012 size
= hbqe
->bde
.tus
.f
.bdeSize
;
1015 if ((offset
+ size
) > evt_dat
->len
)
1016 size
= evt_dat
->len
- offset
;
1018 size
= iocbq
->iocb
.un
.cont64
[i
].
1020 bde
= &iocbq
->iocb
.un
.cont64
[i
];
1021 dma_addr
= getPaddr(bde
->addrHigh
,
1023 dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
1027 lpfc_printf_log(phba
, KERN_ERR
,
1028 LOG_LIBDFC
, "2616 No dmabuf "
1029 "found for iocbq 0x%p\n",
1031 kfree(evt_dat
->data
);
1033 spin_lock_irqsave(&phba
->ct_ev_lock
,
1035 lpfc_bsg_event_unref(evt
);
1036 spin_unlock_irqrestore(
1037 &phba
->ct_ev_lock
, flags
);
1038 goto error_ct_unsol_exit
;
1040 memcpy((char *)(evt_dat
->data
) + offset
,
1041 dmabuf
->virt
, size
);
1043 if (evt_req_id
!= SLI_CT_ELX_LOOPBACK
&&
1044 !(phba
->sli3_options
&
1045 LPFC_SLI3_HBQ_ENABLED
)) {
1046 lpfc_sli_ringpostbuf_put(phba
, pring
,
1050 case ELX_LOOPBACK_DATA
:
1053 diag_cmd_data_free(phba
,
1054 (struct lpfc_dmabufext
1057 case ELX_LOOPBACK_XRI_SETUP
:
1058 if ((phba
->sli_rev
==
1060 (phba
->sli3_options
&
1061 LPFC_SLI3_HBQ_ENABLED
1063 lpfc_in_buf_free(phba
,
1066 lpfc_post_buffer(phba
,
1072 if (!(phba
->sli3_options
&
1073 LPFC_SLI3_HBQ_ENABLED
))
1074 lpfc_post_buffer(phba
,
1083 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1084 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1085 evt_dat
->immed_dat
= phba
->ctx_idx
;
1086 phba
->ctx_idx
= (phba
->ctx_idx
+ 1) % LPFC_CT_CTX_MAX
;
1087 /* Provide warning for over-run of the ct_ctx array */
1088 if (phba
->ct_ctx
[evt_dat
->immed_dat
].valid
==
1090 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1091 "2717 CT context array entry "
1092 "[%d] over-run: oxid:x%x, "
1093 "sid:x%x\n", phba
->ctx_idx
,
1095 evt_dat
->immed_dat
].oxid
,
1097 evt_dat
->immed_dat
].SID
);
1098 phba
->ct_ctx
[evt_dat
->immed_dat
].rxid
=
1099 piocbq
->iocb
.ulpContext
;
1100 phba
->ct_ctx
[evt_dat
->immed_dat
].oxid
=
1101 piocbq
->iocb
.unsli3
.rcvsli3
.ox_id
;
1102 phba
->ct_ctx
[evt_dat
->immed_dat
].SID
=
1103 piocbq
->iocb
.un
.rcvels
.remoteID
;
1104 phba
->ct_ctx
[evt_dat
->immed_dat
].valid
= UNSOL_VALID
;
1106 evt_dat
->immed_dat
= piocbq
->iocb
.ulpContext
;
1108 evt_dat
->type
= FC_REG_CT_EVENT
;
1109 list_add(&evt_dat
->node
, &evt
->events_to_see
);
1110 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
) {
1111 wake_up_interruptible(&evt
->wq
);
1112 lpfc_bsg_event_unref(evt
);
1116 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
1118 dd_data
= (struct bsg_job_data
*)evt
->dd_data
;
1119 job
= dd_data
->set_job
;
1120 dd_data
->set_job
= NULL
;
1121 lpfc_bsg_event_unref(evt
);
1123 job
->reply
->reply_payload_rcv_len
= size
;
1124 /* make error code available to userspace */
1125 job
->reply
->result
= 0;
1126 job
->dd_data
= NULL
;
1127 /* complete the job back to userspace */
1128 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1130 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1133 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1135 error_ct_unsol_exit
:
1136 if (!list_empty(&head
))
1138 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
1139 (evt_req_id
== SLI_CT_ELX_LOOPBACK
))
1145 * lpfc_bsg_ct_unsol_abort - handler ct abort to management plane
1146 * @phba: Pointer to HBA context object.
1147 * @dmabuf: pointer to a dmabuf that describes the FC sequence
1149 * This function handles abort to the CT command toward management plane
1152 * If the pending context of a CT command to management plane present, clears
1153 * such context and returns 1 for handled; otherwise, it returns 0 indicating
1154 * no context exists.
1157 lpfc_bsg_ct_unsol_abort(struct lpfc_hba
*phba
, struct hbq_dmabuf
*dmabuf
)
1159 struct fc_frame_header fc_hdr
;
1160 struct fc_frame_header
*fc_hdr_ptr
= &fc_hdr
;
1161 int ctx_idx
, handled
= 0;
1162 uint16_t oxid
, rxid
;
1165 memcpy(fc_hdr_ptr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
1166 sid
= sli4_sid_from_fc_hdr(fc_hdr_ptr
);
1167 oxid
= be16_to_cpu(fc_hdr_ptr
->fh_ox_id
);
1168 rxid
= be16_to_cpu(fc_hdr_ptr
->fh_rx_id
);
1170 for (ctx_idx
= 0; ctx_idx
< LPFC_CT_CTX_MAX
; ctx_idx
++) {
1171 if (phba
->ct_ctx
[ctx_idx
].valid
!= UNSOL_VALID
)
1173 if (phba
->ct_ctx
[ctx_idx
].rxid
!= rxid
)
1175 if (phba
->ct_ctx
[ctx_idx
].oxid
!= oxid
)
1177 if (phba
->ct_ctx
[ctx_idx
].SID
!= sid
)
1179 phba
->ct_ctx
[ctx_idx
].valid
= UNSOL_INVALID
;
1186 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1187 * @job: SET_EVENT fc_bsg_job
1190 lpfc_bsg_hba_set_event(struct fc_bsg_job
*job
)
1192 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1193 struct lpfc_hba
*phba
= vport
->phba
;
1194 struct set_ct_event
*event_req
;
1195 struct lpfc_bsg_event
*evt
;
1197 struct bsg_job_data
*dd_data
= NULL
;
1199 unsigned long flags
;
1201 if (job
->request_len
<
1202 sizeof(struct fc_bsg_request
) + sizeof(struct set_ct_event
)) {
1203 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1204 "2612 Received SET_CT_EVENT below minimum "
1210 event_req
= (struct set_ct_event
*)
1211 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1212 ev_mask
= ((uint32_t)(unsigned long)event_req
->type_mask
&
1214 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1215 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1216 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1217 lpfc_bsg_event_ref(evt
);
1218 evt
->wait_time_stamp
= jiffies
;
1219 dd_data
= (struct bsg_job_data
*)evt
->dd_data
;
1223 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1225 if (&evt
->node
== &phba
->ct_ev_waiters
) {
1226 /* no event waiting struct yet - first call */
1227 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1228 if (dd_data
== NULL
) {
1229 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1230 "2734 Failed allocation of dd_data\n");
1234 evt
= lpfc_bsg_event_new(ev_mask
, event_req
->ev_reg_id
,
1235 event_req
->ev_req_id
);
1237 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1238 "2617 Failed allocation of event "
1243 dd_data
->type
= TYPE_EVT
;
1244 dd_data
->set_job
= NULL
;
1245 dd_data
->context_un
.evt
= evt
;
1246 evt
->dd_data
= (void *)dd_data
;
1247 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1248 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1249 lpfc_bsg_event_ref(evt
);
1250 evt
->wait_time_stamp
= jiffies
;
1251 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1254 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1256 dd_data
->set_job
= job
; /* for unsolicited command */
1257 job
->dd_data
= dd_data
; /* for fc transport timeout callback*/
1258 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1259 return 0; /* call job done later */
1262 if (dd_data
!= NULL
)
1265 job
->dd_data
= NULL
;
1270 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1271 * @job: GET_EVENT fc_bsg_job
1274 lpfc_bsg_hba_get_event(struct fc_bsg_job
*job
)
1276 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1277 struct lpfc_hba
*phba
= vport
->phba
;
1278 struct get_ct_event
*event_req
;
1279 struct get_ct_event_reply
*event_reply
;
1280 struct lpfc_bsg_event
*evt
, *evt_next
;
1281 struct event_data
*evt_dat
= NULL
;
1282 unsigned long flags
;
1285 if (job
->request_len
<
1286 sizeof(struct fc_bsg_request
) + sizeof(struct get_ct_event
)) {
1287 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1288 "2613 Received GET_CT_EVENT request below "
1294 event_req
= (struct get_ct_event
*)
1295 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1297 event_reply
= (struct get_ct_event_reply
*)
1298 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
1299 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1300 list_for_each_entry_safe(evt
, evt_next
, &phba
->ct_ev_waiters
, node
) {
1301 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1302 if (list_empty(&evt
->events_to_get
))
1304 lpfc_bsg_event_ref(evt
);
1305 evt
->wait_time_stamp
= jiffies
;
1306 evt_dat
= list_entry(evt
->events_to_get
.prev
,
1307 struct event_data
, node
);
1308 list_del(&evt_dat
->node
);
1312 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1314 /* The app may continue to ask for event data until it gets
1315 * an error indicating that there isn't anymore
1317 if (evt_dat
== NULL
) {
1318 job
->reply
->reply_payload_rcv_len
= 0;
1323 if (evt_dat
->len
> job
->request_payload
.payload_len
) {
1324 evt_dat
->len
= job
->request_payload
.payload_len
;
1325 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1326 "2618 Truncated event data at %d "
1328 job
->request_payload
.payload_len
);
1331 event_reply
->type
= evt_dat
->type
;
1332 event_reply
->immed_data
= evt_dat
->immed_dat
;
1333 if (evt_dat
->len
> 0)
1334 job
->reply
->reply_payload_rcv_len
=
1335 sg_copy_from_buffer(job
->request_payload
.sg_list
,
1336 job
->request_payload
.sg_cnt
,
1337 evt_dat
->data
, evt_dat
->len
);
1339 job
->reply
->reply_payload_rcv_len
= 0;
1342 kfree(evt_dat
->data
);
1346 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1347 lpfc_bsg_event_unref(evt
);
1348 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1349 job
->dd_data
= NULL
;
1350 job
->reply
->result
= 0;
1355 job
->dd_data
= NULL
;
1356 job
->reply
->result
= rc
;
1361 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1362 * @phba: Pointer to HBA context object.
1363 * @cmdiocbq: Pointer to command iocb.
1364 * @rspiocbq: Pointer to response iocb.
1366 * This function is the completion handler for iocbs issued using
1367 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1368 * ring event handler function without any lock held. This function
1369 * can be called from both worker thread context and interrupt
1370 * context. This function also can be called from other thread which
1371 * cleans up the SLI layer objects.
1372 * This function copy the contents of the response iocb to the
1373 * response iocb memory object provided by the caller of
1374 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1375 * sleeps for the iocb completion.
1378 lpfc_issue_ct_rsp_cmp(struct lpfc_hba
*phba
,
1379 struct lpfc_iocbq
*cmdiocbq
,
1380 struct lpfc_iocbq
*rspiocbq
)
1382 struct bsg_job_data
*dd_data
;
1383 struct fc_bsg_job
*job
;
1385 struct lpfc_dmabuf
*bmp
, *cmp
;
1386 struct lpfc_nodelist
*ndlp
;
1387 unsigned long flags
;
1390 dd_data
= cmdiocbq
->context1
;
1392 /* Determine if job has been aborted */
1393 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1394 job
= dd_data
->set_job
;
1396 /* Prevent timeout handling from trying to abort job */
1397 job
->dd_data
= NULL
;
1399 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1401 /* Close the timeout handler abort window */
1402 spin_lock_irqsave(&phba
->hbalock
, flags
);
1403 cmdiocbq
->iocb_flag
&= ~LPFC_IO_CMD_OUTSTANDING
;
1404 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1406 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
1407 cmp
= cmdiocbq
->context2
;
1408 bmp
= cmdiocbq
->context3
;
1409 rsp
= &rspiocbq
->iocb
;
1411 /* Copy the completed job data or set the error status */
1414 if (rsp
->ulpStatus
) {
1415 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1416 switch (rsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) {
1417 case IOERR_SEQUENCE_TIMEOUT
:
1420 case IOERR_INVALID_RPI
:
1431 job
->reply
->reply_payload_rcv_len
= 0;
1435 lpfc_free_bsg_buffers(phba
, cmp
);
1436 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1438 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1442 /* Complete the job if the job is still active */
1445 job
->reply
->result
= rc
;
1452 * lpfc_issue_ct_rsp - issue a ct response
1453 * @phba: Pointer to HBA context object.
1454 * @job: Pointer to the job object.
1455 * @tag: tag index value into the ports context exchange array.
1456 * @bmp: Pointer to a dma buffer descriptor.
1457 * @num_entry: Number of enties in the bde.
1460 lpfc_issue_ct_rsp(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
, uint32_t tag
,
1461 struct lpfc_dmabuf
*cmp
, struct lpfc_dmabuf
*bmp
,
1465 struct lpfc_iocbq
*ctiocb
= NULL
;
1467 struct lpfc_nodelist
*ndlp
= NULL
;
1468 struct bsg_job_data
*dd_data
;
1469 unsigned long flags
;
1472 /* allocate our bsg tracking structure */
1473 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1475 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1476 "2736 Failed allocation of dd_data\n");
1481 /* Allocate buffer for command iocb */
1482 ctiocb
= lpfc_sli_get_iocbq(phba
);
1488 icmd
= &ctiocb
->iocb
;
1489 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
1490 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
1491 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
1492 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1493 icmd
->un
.xseq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
1494 icmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
1495 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1496 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_SOL_CTL
;
1497 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1499 /* Fill in rest of iocb */
1500 icmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
1501 icmd
->ulpBdeCount
= 1;
1503 icmd
->ulpClass
= CLASS3
;
1504 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1505 /* Do not issue unsol response if oxid not marked as valid */
1506 if (phba
->ct_ctx
[tag
].valid
!= UNSOL_VALID
) {
1508 goto issue_ct_rsp_exit
;
1510 icmd
->ulpContext
= phba
->ct_ctx
[tag
].rxid
;
1511 icmd
->unsli3
.rcvsli3
.ox_id
= phba
->ct_ctx
[tag
].oxid
;
1512 ndlp
= lpfc_findnode_did(phba
->pport
, phba
->ct_ctx
[tag
].SID
);
1514 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1515 "2721 ndlp null for oxid %x SID %x\n",
1517 phba
->ct_ctx
[tag
].SID
);
1519 goto issue_ct_rsp_exit
;
1522 /* Check if the ndlp is active */
1523 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1525 goto issue_ct_rsp_exit
;
1528 /* get a refernece count so the ndlp doesn't go away while
1531 if (!lpfc_nlp_get(ndlp
)) {
1533 goto issue_ct_rsp_exit
;
1536 icmd
->un
.ulpWord
[3] =
1537 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
1539 /* The exchange is done, mark the entry as invalid */
1540 phba
->ct_ctx
[tag
].valid
= UNSOL_INVALID
;
1542 icmd
->ulpContext
= (ushort
) tag
;
1544 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
1546 /* Xmit CT response on exchange <xid> */
1547 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1548 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1549 icmd
->ulpContext
, icmd
->ulpIoTag
, tag
, phba
->link_state
);
1551 ctiocb
->iocb_cmpl
= NULL
;
1552 ctiocb
->iocb_flag
|= LPFC_IO_LIBDFC
;
1553 ctiocb
->vport
= phba
->pport
;
1554 ctiocb
->context1
= dd_data
;
1555 ctiocb
->context2
= cmp
;
1556 ctiocb
->context3
= bmp
;
1557 ctiocb
->context_un
.ndlp
= ndlp
;
1558 ctiocb
->iocb_cmpl
= lpfc_issue_ct_rsp_cmp
;
1560 dd_data
->type
= TYPE_IOCB
;
1561 dd_data
->set_job
= job
;
1562 dd_data
->context_un
.iocb
.cmdiocbq
= ctiocb
;
1563 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
1564 dd_data
->context_un
.iocb
.rmp
= NULL
;
1565 job
->dd_data
= dd_data
;
1567 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1568 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1570 goto issue_ct_rsp_exit
;
1572 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1573 writel(creg_val
, phba
->HCregaddr
);
1574 readl(phba
->HCregaddr
); /* flush */
1577 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
1579 if (rc
== IOCB_SUCCESS
) {
1580 spin_lock_irqsave(&phba
->hbalock
, flags
);
1581 /* make sure the I/O had not been completed/released */
1582 if (ctiocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
1583 /* open up abort window to timeout handler */
1584 ctiocb
->iocb_flag
|= LPFC_IO_CMD_OUTSTANDING
;
1586 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1587 return 0; /* done for now */
1590 /* iocb failed so cleanup */
1591 job
->dd_data
= NULL
;
1594 lpfc_sli_release_iocbq(phba
, ctiocb
);
1602 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1603 * @job: SEND_MGMT_RESP fc_bsg_job
1606 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job
*job
)
1608 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1609 struct lpfc_hba
*phba
= vport
->phba
;
1610 struct send_mgmt_resp
*mgmt_resp
= (struct send_mgmt_resp
*)
1611 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1612 struct ulp_bde64
*bpl
;
1613 struct lpfc_dmabuf
*bmp
= NULL
, *cmp
= NULL
;
1615 uint32_t tag
= mgmt_resp
->tag
;
1616 unsigned long reqbfrcnt
=
1617 (unsigned long)job
->request_payload
.payload_len
;
1620 /* in case no data is transferred */
1621 job
->reply
->reply_payload_rcv_len
= 0;
1623 if (!reqbfrcnt
|| (reqbfrcnt
> (80 * BUF_SZ_4K
))) {
1625 goto send_mgmt_rsp_exit
;
1628 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1631 goto send_mgmt_rsp_exit
;
1634 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
1637 goto send_mgmt_rsp_free_bmp
;
1640 INIT_LIST_HEAD(&bmp
->list
);
1641 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1642 bpl_entries
= (LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
));
1643 cmp
= lpfc_alloc_bsg_buffers(phba
, job
->request_payload
.payload_len
,
1644 1, bpl
, &bpl_entries
);
1647 goto send_mgmt_rsp_free_bmp
;
1649 lpfc_bsg_copy_data(cmp
, &job
->request_payload
,
1650 job
->request_payload
.payload_len
, 1);
1652 rc
= lpfc_issue_ct_rsp(phba
, job
, tag
, cmp
, bmp
, bpl_entries
);
1654 if (rc
== IOCB_SUCCESS
)
1655 return 0; /* done for now */
1659 lpfc_free_bsg_buffers(phba
, cmp
);
1661 send_mgmt_rsp_free_bmp
:
1663 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1666 /* make error code available to userspace */
1667 job
->reply
->result
= rc
;
1668 job
->dd_data
= NULL
;
1673 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1674 * @phba: Pointer to HBA context object.
1676 * This function is responsible for preparing driver for diag loopback
1680 lpfc_bsg_diag_mode_enter(struct lpfc_hba
*phba
)
1682 struct lpfc_vport
**vports
;
1683 struct Scsi_Host
*shost
;
1684 struct lpfc_sli
*psli
;
1685 struct lpfc_sli_ring
*pring
;
1692 pring
= &psli
->ring
[LPFC_FCP_RING
];
1696 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1697 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
1698 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
1701 vports
= lpfc_create_vport_work_array(phba
);
1703 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1704 shost
= lpfc_shost_from_vport(vports
[i
]);
1705 scsi_block_requests(shost
);
1707 lpfc_destroy_vport_work_array(phba
, vports
);
1709 shost
= lpfc_shost_from_vport(phba
->pport
);
1710 scsi_block_requests(shost
);
1713 while (!list_empty(&pring
->txcmplq
)) {
1714 if (i
++ > 500) /* wait up to 5 seconds */
1722 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1723 * @phba: Pointer to HBA context object.
1725 * This function is responsible for driver exit processing of setting up
1726 * diag loopback mode on device.
1729 lpfc_bsg_diag_mode_exit(struct lpfc_hba
*phba
)
1731 struct Scsi_Host
*shost
;
1732 struct lpfc_vport
**vports
;
1735 vports
= lpfc_create_vport_work_array(phba
);
1737 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1738 shost
= lpfc_shost_from_vport(vports
[i
]);
1739 scsi_unblock_requests(shost
);
1741 lpfc_destroy_vport_work_array(phba
, vports
);
1743 shost
= lpfc_shost_from_vport(phba
->pport
);
1744 scsi_unblock_requests(shost
);
1750 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1751 * @phba: Pointer to HBA context object.
1752 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1754 * This function is responsible for placing an sli3 port into diagnostic
1755 * loopback mode in order to perform a diagnostic loopback test.
1756 * All new scsi requests are blocked, a small delay is used to allow the
1757 * scsi requests to complete then the link is brought down. If the link is
1758 * is placed in loopback mode then scsi requests are again allowed
1759 * so the scsi mid-layer doesn't give up on the port.
1760 * All of this is done in-line.
1763 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1765 struct diag_mode_set
*loopback_mode
;
1766 uint32_t link_flags
;
1768 LPFC_MBOXQ_t
*pmboxq
= NULL
;
1769 int mbxstatus
= MBX_SUCCESS
;
1773 /* no data to return just the return code */
1774 job
->reply
->reply_payload_rcv_len
= 0;
1776 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1777 sizeof(struct diag_mode_set
)) {
1778 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1779 "2738 Received DIAG MODE request size:%d "
1780 "below the minimum size:%d\n",
1782 (int)(sizeof(struct fc_bsg_request
) +
1783 sizeof(struct diag_mode_set
)));
1788 rc
= lpfc_bsg_diag_mode_enter(phba
);
1792 /* bring the link to diagnostic mode */
1793 loopback_mode
= (struct diag_mode_set
*)
1794 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1795 link_flags
= loopback_mode
->type
;
1796 timeout
= loopback_mode
->timeout
* 100;
1798 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1801 goto loopback_mode_exit
;
1803 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1804 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1805 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1807 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1809 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0)) {
1810 /* wait for link down before proceeding */
1812 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1813 if (i
++ > timeout
) {
1815 goto loopback_mode_exit
;
1820 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1821 if (link_flags
== INTERNAL_LOOP_BACK
)
1822 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
1824 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
=
1825 FLAGS_TOPOLOGY_MODE_LOOP
;
1827 pmboxq
->u
.mb
.mbxCommand
= MBX_INIT_LINK
;
1828 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1830 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1833 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1836 spin_lock_irq(&phba
->hbalock
);
1837 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1838 spin_unlock_irq(&phba
->hbalock
);
1839 /* wait for the link attention interrupt */
1843 while (phba
->link_state
!= LPFC_HBA_READY
) {
1844 if (i
++ > timeout
) {
1857 lpfc_bsg_diag_mode_exit(phba
);
1860 * Let SLI layer release mboxq if mbox command completed after timeout.
1862 if (pmboxq
&& mbxstatus
!= MBX_TIMEOUT
)
1863 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1866 /* make error code available to userspace */
1867 job
->reply
->result
= rc
;
1868 /* complete the job back to userspace if no error */
1875 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1876 * @phba: Pointer to HBA context object.
1877 * @diag: Flag for set link to diag or nomral operation state.
1879 * This function is responsible for issuing a sli4 mailbox command for setting
1880 * link to either diag state or normal operation state.
1883 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba
*phba
, uint32_t diag
)
1885 LPFC_MBOXQ_t
*pmboxq
;
1886 struct lpfc_mbx_set_link_diag_state
*link_diag_state
;
1887 uint32_t req_len
, alloc_len
;
1888 int mbxstatus
= MBX_SUCCESS
, rc
;
1890 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1894 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
1895 sizeof(struct lpfc_sli4_cfg_mhdr
));
1896 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1897 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
1898 req_len
, LPFC_SLI4_MBX_EMBED
);
1899 if (alloc_len
!= req_len
) {
1901 goto link_diag_state_set_out
;
1903 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1904 "3128 Set link to diagnostic state:x%x (x%x/x%x)\n",
1905 diag
, phba
->sli4_hba
.lnk_info
.lnk_tp
,
1906 phba
->sli4_hba
.lnk_info
.lnk_no
);
1908 link_diag_state
= &pmboxq
->u
.mqe
.un
.link_diag_state
;
1909 bf_set(lpfc_mbx_set_diag_state_diag_bit_valid
, &link_diag_state
->u
.req
,
1910 LPFC_DIAG_STATE_DIAG_BIT_VALID_CHANGE
);
1911 bf_set(lpfc_mbx_set_diag_state_link_num
, &link_diag_state
->u
.req
,
1912 phba
->sli4_hba
.lnk_info
.lnk_no
);
1913 bf_set(lpfc_mbx_set_diag_state_link_type
, &link_diag_state
->u
.req
,
1914 phba
->sli4_hba
.lnk_info
.lnk_tp
);
1916 bf_set(lpfc_mbx_set_diag_state_diag
,
1917 &link_diag_state
->u
.req
, 1);
1919 bf_set(lpfc_mbx_set_diag_state_diag
,
1920 &link_diag_state
->u
.req
, 0);
1922 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1924 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0))
1929 link_diag_state_set_out
:
1930 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1931 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1937 * lpfc_sli4_bsg_set_internal_loopback - set sli4 internal loopback diagnostic
1938 * @phba: Pointer to HBA context object.
1940 * This function is responsible for issuing a sli4 mailbox command for setting
1941 * up internal loopback diagnostic.
1944 lpfc_sli4_bsg_set_internal_loopback(struct lpfc_hba
*phba
)
1946 LPFC_MBOXQ_t
*pmboxq
;
1947 uint32_t req_len
, alloc_len
;
1948 struct lpfc_mbx_set_link_diag_loopback
*link_diag_loopback
;
1949 int mbxstatus
= MBX_SUCCESS
, rc
= 0;
1951 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1954 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_loopback
) -
1955 sizeof(struct lpfc_sli4_cfg_mhdr
));
1956 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1957 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK
,
1958 req_len
, LPFC_SLI4_MBX_EMBED
);
1959 if (alloc_len
!= req_len
) {
1960 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1963 link_diag_loopback
= &pmboxq
->u
.mqe
.un
.link_diag_loopback
;
1964 bf_set(lpfc_mbx_set_diag_state_link_num
,
1965 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_no
);
1966 bf_set(lpfc_mbx_set_diag_state_link_type
,
1967 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_tp
);
1968 bf_set(lpfc_mbx_set_diag_lpbk_type
, &link_diag_loopback
->u
.req
,
1969 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL
);
1971 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1972 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
)) {
1973 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1974 "3127 Failed setup loopback mode mailbox "
1975 "command, rc:x%x, status:x%x\n", mbxstatus
,
1976 pmboxq
->u
.mb
.mbxStatus
);
1979 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1980 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1985 * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic
1986 * @phba: Pointer to HBA context object.
1988 * This function set up SLI4 FC port registrations for diagnostic run, which
1989 * includes all the rpis, vfi, and also vpi.
1992 lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba
*phba
)
1996 if (phba
->pport
->fc_flag
& FC_VFI_REGISTERED
) {
1997 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1998 "3136 Port still had vfi registered: "
1999 "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
2000 phba
->pport
->fc_myDID
, phba
->fcf
.fcfi
,
2001 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
],
2002 phba
->vpi_ids
[phba
->pport
->vpi
]);
2005 rc
= lpfc_issue_reg_vfi(phba
->pport
);
2010 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
2011 * @phba: Pointer to HBA context object.
2012 * @job: LPFC_BSG_VENDOR_DIAG_MODE
2014 * This function is responsible for placing an sli4 port into diagnostic
2015 * loopback mode in order to perform a diagnostic loopback test.
2018 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
2020 struct diag_mode_set
*loopback_mode
;
2021 uint32_t link_flags
, timeout
;
2024 /* no data to return just the return code */
2025 job
->reply
->reply_payload_rcv_len
= 0;
2027 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
2028 sizeof(struct diag_mode_set
)) {
2029 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2030 "3011 Received DIAG MODE request size:%d "
2031 "below the minimum size:%d\n",
2033 (int)(sizeof(struct fc_bsg_request
) +
2034 sizeof(struct diag_mode_set
)));
2039 rc
= lpfc_bsg_diag_mode_enter(phba
);
2043 /* indicate we are in loobpack diagnostic mode */
2044 spin_lock_irq(&phba
->hbalock
);
2045 phba
->link_flag
|= LS_LOOPBACK_MODE
;
2046 spin_unlock_irq(&phba
->hbalock
);
2048 /* reset port to start frome scratch */
2049 rc
= lpfc_selective_reset(phba
);
2053 /* bring the link to diagnostic mode */
2054 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2055 "3129 Bring link to diagnostic state.\n");
2056 loopback_mode
= (struct diag_mode_set
*)
2057 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2058 link_flags
= loopback_mode
->type
;
2059 timeout
= loopback_mode
->timeout
* 100;
2061 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
2063 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2064 "3130 Failed to bring link to diagnostic "
2065 "state, rc:x%x\n", rc
);
2066 goto loopback_mode_exit
;
2069 /* wait for link down before proceeding */
2071 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
2072 if (i
++ > timeout
) {
2074 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2075 "3131 Timeout waiting for link to "
2076 "diagnostic mode, timeout:%d ms\n",
2078 goto loopback_mode_exit
;
2083 /* set up loopback mode */
2084 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2085 "3132 Set up loopback mode:x%x\n", link_flags
);
2087 if (link_flags
== INTERNAL_LOOP_BACK
)
2088 rc
= lpfc_sli4_bsg_set_internal_loopback(phba
);
2089 else if (link_flags
== EXTERNAL_LOOP_BACK
)
2090 rc
= lpfc_hba_init_link_fc_topology(phba
,
2091 FLAGS_TOPOLOGY_MODE_PT_PT
,
2095 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2096 "3141 Loopback mode:x%x not supported\n",
2098 goto loopback_mode_exit
;
2102 /* wait for the link attention interrupt */
2105 while (phba
->link_state
< LPFC_LINK_UP
) {
2106 if (i
++ > timeout
) {
2108 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2109 "3137 Timeout waiting for link up "
2110 "in loopback mode, timeout:%d ms\n",
2118 /* port resource registration setup for loopback diagnostic */
2120 /* set up a none zero myDID for loopback test */
2121 phba
->pport
->fc_myDID
= 1;
2122 rc
= lpfc_sli4_diag_fcport_reg_setup(phba
);
2124 goto loopback_mode_exit
;
2127 /* wait for the port ready */
2130 while (phba
->link_state
!= LPFC_HBA_READY
) {
2131 if (i
++ > timeout
) {
2133 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2134 "3133 Timeout waiting for port "
2135 "loopback mode ready, timeout:%d ms\n",
2144 /* clear loopback diagnostic mode */
2146 spin_lock_irq(&phba
->hbalock
);
2147 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
2148 spin_unlock_irq(&phba
->hbalock
);
2150 lpfc_bsg_diag_mode_exit(phba
);
2153 /* make error code available to userspace */
2154 job
->reply
->result
= rc
;
2155 /* complete the job back to userspace if no error */
2162 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
2163 * @job: LPFC_BSG_VENDOR_DIAG_MODE
2165 * This function is responsible for responding to check and dispatch bsg diag
2166 * command from the user to proper driver action routines.
2169 lpfc_bsg_diag_loopback_mode(struct fc_bsg_job
*job
)
2171 struct Scsi_Host
*shost
;
2172 struct lpfc_vport
*vport
;
2173 struct lpfc_hba
*phba
;
2179 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2186 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2187 rc
= lpfc_sli3_bsg_diag_loopback_mode(phba
, job
);
2188 else if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
2189 LPFC_SLI_INTF_IF_TYPE_2
)
2190 rc
= lpfc_sli4_bsg_diag_loopback_mode(phba
, job
);
2198 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
2199 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
2201 * This function is responsible for responding to check and dispatch bsg diag
2202 * command from the user to proper driver action routines.
2205 lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job
*job
)
2207 struct Scsi_Host
*shost
;
2208 struct lpfc_vport
*vport
;
2209 struct lpfc_hba
*phba
;
2210 struct diag_mode_set
*loopback_mode_end_cmd
;
2217 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2224 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2226 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2227 LPFC_SLI_INTF_IF_TYPE_2
)
2230 /* clear loopback diagnostic mode */
2231 spin_lock_irq(&phba
->hbalock
);
2232 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
2233 spin_unlock_irq(&phba
->hbalock
);
2234 loopback_mode_end_cmd
= (struct diag_mode_set
*)
2235 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2236 timeout
= loopback_mode_end_cmd
->timeout
* 100;
2238 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2240 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2241 "3139 Failed to bring link to diagnostic "
2242 "state, rc:x%x\n", rc
);
2243 goto loopback_mode_end_exit
;
2246 /* wait for link down before proceeding */
2248 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
2249 if (i
++ > timeout
) {
2250 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2251 "3140 Timeout waiting for link to "
2252 "diagnostic mode_end, timeout:%d ms\n",
2254 /* there is nothing much we can do here */
2260 /* reset port resource registrations */
2261 rc
= lpfc_selective_reset(phba
);
2262 phba
->pport
->fc_myDID
= 0;
2264 loopback_mode_end_exit
:
2265 /* make return code available to userspace */
2266 job
->reply
->result
= rc
;
2267 /* complete the job back to userspace if no error */
2274 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
2275 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
2277 * This function is to perform SLI4 diag link test request from the user
2281 lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job
*job
)
2283 struct Scsi_Host
*shost
;
2284 struct lpfc_vport
*vport
;
2285 struct lpfc_hba
*phba
;
2286 LPFC_MBOXQ_t
*pmboxq
;
2287 struct sli4_link_diag
*link_diag_test_cmd
;
2288 uint32_t req_len
, alloc_len
;
2289 struct lpfc_mbx_run_link_diag_test
*run_link_diag_test
;
2290 union lpfc_sli4_cfg_shdr
*shdr
;
2291 uint32_t shdr_status
, shdr_add_status
;
2292 struct diag_status
*diag_status_reply
;
2293 int mbxstatus
, rc
= 0;
2300 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2311 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2315 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2316 LPFC_SLI_INTF_IF_TYPE_2
) {
2321 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
2322 sizeof(struct sli4_link_diag
)) {
2323 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2324 "3013 Received LINK DIAG TEST request "
2325 " size:%d below the minimum size:%d\n",
2327 (int)(sizeof(struct fc_bsg_request
) +
2328 sizeof(struct sli4_link_diag
)));
2333 rc
= lpfc_bsg_diag_mode_enter(phba
);
2337 link_diag_test_cmd
= (struct sli4_link_diag
*)
2338 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2340 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
2345 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2348 goto link_diag_test_exit
;
2351 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
2352 sizeof(struct lpfc_sli4_cfg_mhdr
));
2353 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2354 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
2355 req_len
, LPFC_SLI4_MBX_EMBED
);
2356 if (alloc_len
!= req_len
) {
2358 goto link_diag_test_exit
;
2360 run_link_diag_test
= &pmboxq
->u
.mqe
.un
.link_diag_test
;
2361 bf_set(lpfc_mbx_run_diag_test_link_num
, &run_link_diag_test
->u
.req
,
2362 phba
->sli4_hba
.lnk_info
.lnk_no
);
2363 bf_set(lpfc_mbx_run_diag_test_link_type
, &run_link_diag_test
->u
.req
,
2364 phba
->sli4_hba
.lnk_info
.lnk_tp
);
2365 bf_set(lpfc_mbx_run_diag_test_test_id
, &run_link_diag_test
->u
.req
,
2366 link_diag_test_cmd
->test_id
);
2367 bf_set(lpfc_mbx_run_diag_test_loops
, &run_link_diag_test
->u
.req
,
2368 link_diag_test_cmd
->loops
);
2369 bf_set(lpfc_mbx_run_diag_test_test_ver
, &run_link_diag_test
->u
.req
,
2370 link_diag_test_cmd
->test_version
);
2371 bf_set(lpfc_mbx_run_diag_test_err_act
, &run_link_diag_test
->u
.req
,
2372 link_diag_test_cmd
->error_action
);
2374 mbxstatus
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2376 shdr
= (union lpfc_sli4_cfg_shdr
*)
2377 &pmboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2378 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
2379 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
2380 if (shdr_status
|| shdr_add_status
|| mbxstatus
) {
2381 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2382 "3010 Run link diag test mailbox failed with "
2383 "mbx_status x%x status x%x, add_status x%x\n",
2384 mbxstatus
, shdr_status
, shdr_add_status
);
2387 diag_status_reply
= (struct diag_status
*)
2388 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
2390 if (job
->reply_len
<
2391 sizeof(struct fc_bsg_request
) + sizeof(struct diag_status
)) {
2392 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2393 "3012 Received Run link diag test reply "
2394 "below minimum size (%d): reply_len:%d\n",
2395 (int)(sizeof(struct fc_bsg_request
) +
2396 sizeof(struct diag_status
)),
2402 diag_status_reply
->mbox_status
= mbxstatus
;
2403 diag_status_reply
->shdr_status
= shdr_status
;
2404 diag_status_reply
->shdr_add_status
= shdr_add_status
;
2406 link_diag_test_exit
:
2407 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2410 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2412 lpfc_bsg_diag_mode_exit(phba
);
2415 /* make error code available to userspace */
2416 job
->reply
->result
= rc
;
2417 /* complete the job back to userspace if no error */
2424 * lpfcdiag_loop_self_reg - obtains a remote port login id
2425 * @phba: Pointer to HBA context object
2426 * @rpi: Pointer to a remote port login id
2428 * This function obtains a remote port login id so the diag loopback test
2429 * can send and receive its own unsolicited CT command.
2431 static int lpfcdiag_loop_self_reg(struct lpfc_hba
*phba
, uint16_t *rpi
)
2434 struct lpfc_dmabuf
*dmabuff
;
2437 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2441 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2442 status
= lpfc_reg_rpi(phba
, 0, phba
->pport
->fc_myDID
,
2443 (uint8_t *)&phba
->pport
->fc_sparam
,
2446 *rpi
= lpfc_sli4_alloc_rpi(phba
);
2447 status
= lpfc_reg_rpi(phba
, phba
->pport
->vpi
,
2448 phba
->pport
->fc_myDID
,
2449 (uint8_t *)&phba
->pport
->fc_sparam
,
2454 mempool_free(mbox
, phba
->mbox_mem_pool
);
2455 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2456 lpfc_sli4_free_rpi(phba
, *rpi
);
2460 dmabuff
= (struct lpfc_dmabuf
*) mbox
->context1
;
2461 mbox
->context1
= NULL
;
2462 mbox
->context2
= NULL
;
2463 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2465 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2466 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2468 if (status
!= MBX_TIMEOUT
)
2469 mempool_free(mbox
, phba
->mbox_mem_pool
);
2470 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2471 lpfc_sli4_free_rpi(phba
, *rpi
);
2475 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2476 *rpi
= mbox
->u
.mb
.un
.varWords
[0];
2478 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2480 mempool_free(mbox
, phba
->mbox_mem_pool
);
2485 * lpfcdiag_loop_self_unreg - unregs from the rpi
2486 * @phba: Pointer to HBA context object
2487 * @rpi: Remote port login id
2489 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2491 static int lpfcdiag_loop_self_unreg(struct lpfc_hba
*phba
, uint16_t rpi
)
2496 /* Allocate mboxq structure */
2497 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2501 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2502 lpfc_unreg_login(phba
, 0, rpi
, mbox
);
2504 lpfc_unreg_login(phba
, phba
->pport
->vpi
,
2505 phba
->sli4_hba
.rpi_ids
[rpi
], mbox
);
2507 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2509 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2510 if (status
!= MBX_TIMEOUT
)
2511 mempool_free(mbox
, phba
->mbox_mem_pool
);
2514 mempool_free(mbox
, phba
->mbox_mem_pool
);
2515 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2516 lpfc_sli4_free_rpi(phba
, rpi
);
2521 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2522 * @phba: Pointer to HBA context object
2523 * @rpi: Remote port login id
2524 * @txxri: Pointer to transmit exchange id
2525 * @rxxri: Pointer to response exchabge id
2527 * This function obtains the transmit and receive ids required to send
2528 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2529 * flags are used to the unsolicted response handler is able to process
2530 * the ct command sent on the same port.
2532 static int lpfcdiag_loop_get_xri(struct lpfc_hba
*phba
, uint16_t rpi
,
2533 uint16_t *txxri
, uint16_t * rxxri
)
2535 struct lpfc_bsg_event
*evt
;
2536 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2538 struct lpfc_dmabuf
*dmabuf
;
2539 struct ulp_bde64
*bpl
= NULL
;
2540 struct lpfc_sli_ct_request
*ctreq
= NULL
;
2543 int iocb_stat
= IOCB_SUCCESS
;
2544 unsigned long flags
;
2548 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2549 SLI_CT_ELX_LOOPBACK
);
2553 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2554 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2555 lpfc_bsg_event_ref(evt
);
2556 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2558 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2559 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2561 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2563 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, 0, &dmabuf
->phys
);
2565 INIT_LIST_HEAD(&dmabuf
->list
);
2566 bpl
= (struct ulp_bde64
*) dmabuf
->virt
;
2567 memset(bpl
, 0, sizeof(*bpl
));
2568 ctreq
= (struct lpfc_sli_ct_request
*)(bpl
+ 1);
2570 le32_to_cpu(putPaddrHigh(dmabuf
->phys
+
2573 le32_to_cpu(putPaddrLow(dmabuf
->phys
+
2575 bpl
->tus
.f
.bdeFlags
= 0;
2576 bpl
->tus
.f
.bdeSize
= ELX_LOOPBACK_HEADER_SZ
;
2577 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2581 if (cmdiocbq
== NULL
|| rspiocbq
== NULL
||
2582 dmabuf
== NULL
|| bpl
== NULL
|| ctreq
== NULL
||
2583 dmabuf
->virt
== NULL
) {
2585 goto err_get_xri_exit
;
2588 cmd
= &cmdiocbq
->iocb
;
2589 rsp
= &rspiocbq
->iocb
;
2591 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2593 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2594 ctreq
->RevisionId
.bits
.InId
= 0;
2595 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2596 ctreq
->FsSubType
= 0;
2597 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_XRI_SETUP
;
2598 ctreq
->CommandResponse
.bits
.Size
= 0;
2601 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(dmabuf
->phys
);
2602 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(dmabuf
->phys
);
2603 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2604 cmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(*bpl
);
2606 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= LA
;
2607 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2608 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2609 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2611 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CR
;
2612 cmd
->ulpBdeCount
= 1;
2614 cmd
->ulpClass
= CLASS3
;
2615 cmd
->ulpContext
= rpi
;
2617 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2618 cmdiocbq
->vport
= phba
->pport
;
2619 cmdiocbq
->iocb_cmpl
= NULL
;
2621 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2623 (phba
->fc_ratov
* 2)
2624 + LPFC_DRVR_TIMEOUT
);
2625 if ((iocb_stat
!= IOCB_SUCCESS
) || (rsp
->ulpStatus
!= IOSTAT_SUCCESS
)) {
2627 goto err_get_xri_exit
;
2629 *txxri
= rsp
->ulpContext
;
2632 evt
->wait_time_stamp
= jiffies
;
2633 time_left
= wait_event_interruptible_timeout(
2634 evt
->wq
, !list_empty(&evt
->events_to_see
),
2635 msecs_to_jiffies(1000 *
2636 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
)));
2637 if (list_empty(&evt
->events_to_see
))
2638 ret_val
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
2640 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2641 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2642 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2643 *rxxri
= (list_entry(evt
->events_to_get
.prev
,
2644 typeof(struct event_data
),
2650 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2651 lpfc_bsg_event_unref(evt
); /* release ref */
2652 lpfc_bsg_event_unref(evt
); /* delete */
2653 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2657 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2661 if (cmdiocbq
&& (iocb_stat
!= IOCB_TIMEDOUT
))
2662 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2664 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2669 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2670 * @phba: Pointer to HBA context object
2672 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and.
2673 * returns the pointer to the buffer.
2675 static struct lpfc_dmabuf
*
2676 lpfc_bsg_dma_page_alloc(struct lpfc_hba
*phba
)
2678 struct lpfc_dmabuf
*dmabuf
;
2679 struct pci_dev
*pcidev
= phba
->pcidev
;
2681 /* allocate dma buffer struct */
2682 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2686 INIT_LIST_HEAD(&dmabuf
->list
);
2688 /* now, allocate dma buffer */
2689 dmabuf
->virt
= dma_zalloc_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2690 &(dmabuf
->phys
), GFP_KERNEL
);
2692 if (!dmabuf
->virt
) {
2701 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2702 * @phba: Pointer to HBA context object.
2703 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2705 * This routine just simply frees a dma buffer and its associated buffer
2706 * descriptor referred by @dmabuf.
2709 lpfc_bsg_dma_page_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*dmabuf
)
2711 struct pci_dev
*pcidev
= phba
->pcidev
;
2717 dma_free_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2718 dmabuf
->virt
, dmabuf
->phys
);
2724 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2725 * @phba: Pointer to HBA context object.
2726 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2728 * This routine just simply frees all dma buffers and their associated buffer
2729 * descriptors referred by @dmabuf_list.
2732 lpfc_bsg_dma_page_list_free(struct lpfc_hba
*phba
,
2733 struct list_head
*dmabuf_list
)
2735 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
2737 if (list_empty(dmabuf_list
))
2740 list_for_each_entry_safe(dmabuf
, next_dmabuf
, dmabuf_list
, list
) {
2741 list_del_init(&dmabuf
->list
);
2742 lpfc_bsg_dma_page_free(phba
, dmabuf
);
2748 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2749 * @phba: Pointer to HBA context object
2750 * @bpl: Pointer to 64 bit bde structure
2751 * @size: Number of bytes to process
2752 * @nocopydata: Flag to copy user data into the allocated buffer
2754 * This function allocates page size buffers and populates an lpfc_dmabufext.
2755 * If allowed the user data pointed to with indataptr is copied into the kernel
2756 * memory. The chained list of page size buffers is returned.
2758 static struct lpfc_dmabufext
*
2759 diag_cmd_data_alloc(struct lpfc_hba
*phba
,
2760 struct ulp_bde64
*bpl
, uint32_t size
,
2763 struct lpfc_dmabufext
*mlist
= NULL
;
2764 struct lpfc_dmabufext
*dmp
;
2765 int cnt
, offset
= 0, i
= 0;
2766 struct pci_dev
*pcidev
;
2768 pcidev
= phba
->pcidev
;
2771 /* We get chunks of 4K */
2772 if (size
> BUF_SZ_4K
)
2777 /* allocate struct lpfc_dmabufext buffer header */
2778 dmp
= kmalloc(sizeof(struct lpfc_dmabufext
), GFP_KERNEL
);
2782 INIT_LIST_HEAD(&dmp
->dma
.list
);
2784 /* Queue it to a linked list */
2786 list_add_tail(&dmp
->dma
.list
, &mlist
->dma
.list
);
2790 /* allocate buffer */
2791 dmp
->dma
.virt
= dma_alloc_coherent(&pcidev
->dev
,
2802 bpl
->tus
.f
.bdeFlags
= 0;
2803 pci_dma_sync_single_for_device(phba
->pcidev
,
2804 dmp
->dma
.phys
, LPFC_BPL_SIZE
, PCI_DMA_TODEVICE
);
2807 memset((uint8_t *)dmp
->dma
.virt
, 0, cnt
);
2808 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2811 /* build buffer ptr list for IOCB */
2812 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dmp
->dma
.phys
));
2813 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dmp
->dma
.phys
));
2814 bpl
->tus
.f
.bdeSize
= (ushort
) cnt
;
2815 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2828 diag_cmd_data_free(phba
, mlist
);
2833 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2834 * @phba: Pointer to HBA context object
2835 * @rxxri: Receive exchange id
2836 * @len: Number of data bytes
2838 * This function allocates and posts a data buffer of sufficient size to receive
2839 * an unsolicted CT command.
2841 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba
*phba
, uint16_t rxxri
,
2844 struct lpfc_sli
*psli
= &phba
->sli
;
2845 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2846 struct lpfc_iocbq
*cmdiocbq
;
2848 struct list_head head
, *curr
, *next
;
2849 struct lpfc_dmabuf
*rxbmp
;
2850 struct lpfc_dmabuf
*dmp
;
2851 struct lpfc_dmabuf
*mp
[2] = {NULL
, NULL
};
2852 struct ulp_bde64
*rxbpl
= NULL
;
2854 struct lpfc_dmabufext
*rxbuffer
= NULL
;
2859 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2860 rxbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2861 if (rxbmp
!= NULL
) {
2862 rxbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &rxbmp
->phys
);
2864 INIT_LIST_HEAD(&rxbmp
->list
);
2865 rxbpl
= (struct ulp_bde64
*) rxbmp
->virt
;
2866 rxbuffer
= diag_cmd_data_alloc(phba
, rxbpl
, len
, 0);
2870 if (!cmdiocbq
|| !rxbmp
|| !rxbpl
|| !rxbuffer
) {
2872 goto err_post_rxbufs_exit
;
2875 /* Queue buffers for the receive exchange */
2876 num_bde
= (uint32_t)rxbuffer
->flag
;
2877 dmp
= &rxbuffer
->dma
;
2879 cmd
= &cmdiocbq
->iocb
;
2882 INIT_LIST_HEAD(&head
);
2883 list_add_tail(&head
, &dmp
->list
);
2884 list_for_each_safe(curr
, next
, &head
) {
2885 mp
[i
] = list_entry(curr
, struct lpfc_dmabuf
, list
);
2888 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2889 mp
[i
]->buffer_tag
= lpfc_sli_get_buffer_tag(phba
);
2890 cmd
->un
.quexri64cx
.buff
.bde
.addrHigh
=
2891 putPaddrHigh(mp
[i
]->phys
);
2892 cmd
->un
.quexri64cx
.buff
.bde
.addrLow
=
2893 putPaddrLow(mp
[i
]->phys
);
2894 cmd
->un
.quexri64cx
.buff
.bde
.tus
.f
.bdeSize
=
2895 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2896 cmd
->un
.quexri64cx
.buff
.buffer_tag
= mp
[i
]->buffer_tag
;
2897 cmd
->ulpCommand
= CMD_QUE_XRI64_CX
;
2900 cmd
->ulpBdeCount
= 1;
2901 cmd
->unsli3
.que_xri64cx_ext_words
.ebde_count
= 0;
2904 cmd
->un
.cont64
[i
].addrHigh
= putPaddrHigh(mp
[i
]->phys
);
2905 cmd
->un
.cont64
[i
].addrLow
= putPaddrLow(mp
[i
]->phys
);
2906 cmd
->un
.cont64
[i
].tus
.f
.bdeSize
=
2907 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2908 cmd
->ulpBdeCount
= ++i
;
2910 if ((--num_bde
> 0) && (i
< 2))
2913 cmd
->ulpCommand
= CMD_QUE_XRI_BUF64_CX
;
2917 cmd
->ulpClass
= CLASS3
;
2918 cmd
->ulpContext
= rxxri
;
2920 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
2922 if (iocb_stat
== IOCB_ERROR
) {
2923 diag_cmd_data_free(phba
,
2924 (struct lpfc_dmabufext
*)mp
[0]);
2926 diag_cmd_data_free(phba
,
2927 (struct lpfc_dmabufext
*)mp
[1]);
2928 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2930 goto err_post_rxbufs_exit
;
2933 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[0]);
2935 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[1]);
2939 /* The iocb was freed by lpfc_sli_issue_iocb */
2940 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2942 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2944 goto err_post_rxbufs_exit
;
2947 cmd
= &cmdiocbq
->iocb
;
2952 err_post_rxbufs_exit
:
2956 lpfc_mbuf_free(phba
, rxbmp
->virt
, rxbmp
->phys
);
2961 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2966 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
2967 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2969 * This function receives a user data buffer to be transmitted and received on
2970 * the same port, the link must be up and in loopback mode prior
2972 * 1. A kernel buffer is allocated to copy the user data into.
2973 * 2. The port registers with "itself".
2974 * 3. The transmit and receive exchange ids are obtained.
2975 * 4. The receive exchange id is posted.
2976 * 5. A new els loopback event is created.
2977 * 6. The command and response iocbs are allocated.
2978 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2980 * This function is meant to be called n times while the port is in loopback
2981 * so it is the apps responsibility to issue a reset to take the port out
2985 lpfc_bsg_diag_loopback_run(struct fc_bsg_job
*job
)
2987 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2988 struct lpfc_hba
*phba
= vport
->phba
;
2989 struct lpfc_bsg_event
*evt
;
2990 struct event_data
*evdat
;
2991 struct lpfc_sli
*psli
= &phba
->sli
;
2994 size_t segment_len
= 0, segment_offset
= 0, current_offset
= 0;
2996 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
= NULL
;
2997 IOCB_t
*cmd
, *rsp
= NULL
;
2998 struct lpfc_sli_ct_request
*ctreq
;
2999 struct lpfc_dmabuf
*txbmp
;
3000 struct ulp_bde64
*txbpl
= NULL
;
3001 struct lpfc_dmabufext
*txbuffer
= NULL
;
3002 struct list_head head
;
3003 struct lpfc_dmabuf
*curr
;
3004 uint16_t txxri
= 0, rxxri
;
3006 uint8_t *ptr
= NULL
, *rx_databuf
= NULL
;
3009 int iocb_stat
= IOCB_SUCCESS
;
3010 unsigned long flags
;
3011 void *dataout
= NULL
;
3014 /* in case no data is returned return just the return code */
3015 job
->reply
->reply_payload_rcv_len
= 0;
3017 if (job
->request_len
<
3018 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_test
)) {
3019 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3020 "2739 Received DIAG TEST request below minimum "
3023 goto loopback_test_exit
;
3026 if (job
->request_payload
.payload_len
!=
3027 job
->reply_payload
.payload_len
) {
3029 goto loopback_test_exit
;
3032 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
3033 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
3034 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
3036 goto loopback_test_exit
;
3039 if (!lpfc_is_link_up(phba
) || !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
3041 goto loopback_test_exit
;
3044 size
= job
->request_payload
.payload_len
;
3045 full_size
= size
+ ELX_LOOPBACK_HEADER_SZ
; /* plus the header */
3047 if ((size
== 0) || (size
> 80 * BUF_SZ_4K
)) {
3049 goto loopback_test_exit
;
3052 if (full_size
>= BUF_SZ_4K
) {
3054 * Allocate memory for ioctl data. If buffer is bigger than 64k,
3055 * then we allocate 64k and re-use that buffer over and over to
3056 * xfer the whole block. This is because Linux kernel has a
3057 * problem allocating more than 120k of kernel space memory. Saw
3058 * problem with GET_FCPTARGETMAPPING...
3060 if (size
<= (64 * 1024))
3061 total_mem
= full_size
;
3063 total_mem
= 64 * 1024;
3065 /* Allocate memory for ioctl data */
3066 total_mem
= BUF_SZ_4K
;
3068 dataout
= kmalloc(total_mem
, GFP_KERNEL
);
3069 if (dataout
== NULL
) {
3071 goto loopback_test_exit
;
3075 ptr
+= ELX_LOOPBACK_HEADER_SZ
;
3076 sg_copy_to_buffer(job
->request_payload
.sg_list
,
3077 job
->request_payload
.sg_cnt
,
3079 rc
= lpfcdiag_loop_self_reg(phba
, &rpi
);
3081 goto loopback_test_exit
;
3083 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3084 rc
= lpfcdiag_loop_get_xri(phba
, rpi
, &txxri
, &rxxri
);
3086 lpfcdiag_loop_self_unreg(phba
, rpi
);
3087 goto loopback_test_exit
;
3090 rc
= lpfcdiag_loop_post_rxbufs(phba
, rxxri
, full_size
);
3092 lpfcdiag_loop_self_unreg(phba
, rpi
);
3093 goto loopback_test_exit
;
3096 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
3097 SLI_CT_ELX_LOOPBACK
);
3099 lpfcdiag_loop_self_unreg(phba
, rpi
);
3101 goto loopback_test_exit
;
3104 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3105 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
3106 lpfc_bsg_event_ref(evt
);
3107 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3109 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
3110 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3111 rspiocbq
= lpfc_sli_get_iocbq(phba
);
3112 txbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3115 txbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &txbmp
->phys
);
3117 INIT_LIST_HEAD(&txbmp
->list
);
3118 txbpl
= (struct ulp_bde64
*) txbmp
->virt
;
3119 txbuffer
= diag_cmd_data_alloc(phba
,
3120 txbpl
, full_size
, 0);
3124 if (!cmdiocbq
|| !txbmp
|| !txbpl
|| !txbuffer
|| !txbmp
->virt
) {
3126 goto err_loopback_test_exit
;
3128 if ((phba
->sli_rev
< LPFC_SLI_REV4
) && !rspiocbq
) {
3130 goto err_loopback_test_exit
;
3133 cmd
= &cmdiocbq
->iocb
;
3134 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3135 rsp
= &rspiocbq
->iocb
;
3137 INIT_LIST_HEAD(&head
);
3138 list_add_tail(&head
, &txbuffer
->dma
.list
);
3139 list_for_each_entry(curr
, &head
, list
) {
3140 segment_len
= ((struct lpfc_dmabufext
*)curr
)->size
;
3141 if (current_offset
== 0) {
3143 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
3144 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
3145 ctreq
->RevisionId
.bits
.InId
= 0;
3146 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
3147 ctreq
->FsSubType
= 0;
3148 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_DATA
;
3149 ctreq
->CommandResponse
.bits
.Size
= size
;
3150 segment_offset
= ELX_LOOPBACK_HEADER_SZ
;
3154 BUG_ON(segment_offset
>= segment_len
);
3155 memcpy(curr
->virt
+ segment_offset
,
3156 ptr
+ current_offset
,
3157 segment_len
- segment_offset
);
3159 current_offset
+= segment_len
- segment_offset
;
3160 BUG_ON(current_offset
> size
);
3164 /* Build the XMIT_SEQUENCE iocb */
3165 num_bde
= (uint32_t)txbuffer
->flag
;
3167 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(txbmp
->phys
);
3168 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(txbmp
->phys
);
3169 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
3170 cmd
->un
.xseq64
.bdl
.bdeSize
= (num_bde
* sizeof(struct ulp_bde64
));
3172 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
3173 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
3174 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
3175 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
3177 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
3178 cmd
->ulpBdeCount
= 1;
3180 cmd
->ulpClass
= CLASS3
;
3182 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3183 cmd
->ulpContext
= txxri
;
3185 cmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
3186 cmd
->un
.ulpWord
[3] = phba
->sli4_hba
.rpi_ids
[rpi
];
3187 cmdiocbq
->context3
= txbmp
;
3188 cmdiocbq
->sli4_xritag
= NO_XRI
;
3189 cmd
->unsli3
.rcvsli3
.ox_id
= 0xffff;
3191 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
3192 cmdiocbq
->iocb_flag
|= LPFC_IO_LOOPBACK
;
3193 cmdiocbq
->vport
= phba
->pport
;
3194 cmdiocbq
->iocb_cmpl
= NULL
;
3195 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
3196 rspiocbq
, (phba
->fc_ratov
* 2) +
3199 if ((iocb_stat
!= IOCB_SUCCESS
) ||
3200 ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3201 (rsp
->ulpStatus
!= IOSTAT_SUCCESS
))) {
3202 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3203 "3126 Failed loopback test issue iocb: "
3204 "iocb_stat:x%x\n", iocb_stat
);
3206 goto err_loopback_test_exit
;
3210 time_left
= wait_event_interruptible_timeout(
3211 evt
->wq
, !list_empty(&evt
->events_to_see
),
3212 msecs_to_jiffies(1000 *
3213 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
)));
3215 if (list_empty(&evt
->events_to_see
)) {
3216 rc
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
3217 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3218 "3125 Not receiving unsolicited event, "
3221 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3222 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
3223 evdat
= list_entry(evt
->events_to_get
.prev
,
3224 typeof(*evdat
), node
);
3225 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3226 rx_databuf
= evdat
->data
;
3227 if (evdat
->len
!= full_size
) {
3228 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3229 "1603 Loopback test did not receive expected "
3230 "data length. actual length 0x%x expected "
3232 evdat
->len
, full_size
);
3234 } else if (rx_databuf
== NULL
)
3238 /* skip over elx loopback header */
3239 rx_databuf
+= ELX_LOOPBACK_HEADER_SZ
;
3240 job
->reply
->reply_payload_rcv_len
=
3241 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3242 job
->reply_payload
.sg_cnt
,
3244 job
->reply
->reply_payload_rcv_len
= size
;
3248 err_loopback_test_exit
:
3249 lpfcdiag_loop_self_unreg(phba
, rpi
);
3251 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3252 lpfc_bsg_event_unref(evt
); /* release ref */
3253 lpfc_bsg_event_unref(evt
); /* delete */
3254 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3256 if ((cmdiocbq
!= NULL
) && (iocb_stat
!= IOCB_TIMEDOUT
))
3257 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
3259 if (rspiocbq
!= NULL
)
3260 lpfc_sli_release_iocbq(phba
, rspiocbq
);
3262 if (txbmp
!= NULL
) {
3263 if (txbpl
!= NULL
) {
3264 if (txbuffer
!= NULL
)
3265 diag_cmd_data_free(phba
, txbuffer
);
3266 lpfc_mbuf_free(phba
, txbmp
->virt
, txbmp
->phys
);
3273 /* make error code available to userspace */
3274 job
->reply
->result
= rc
;
3275 job
->dd_data
= NULL
;
3276 /* complete the job back to userspace if no error */
3277 if (rc
== IOCB_SUCCESS
)
3283 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
3284 * @job: GET_DFC_REV fc_bsg_job
3287 lpfc_bsg_get_dfc_rev(struct fc_bsg_job
*job
)
3289 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
3290 struct lpfc_hba
*phba
= vport
->phba
;
3291 struct get_mgmt_rev_reply
*event_reply
;
3294 if (job
->request_len
<
3295 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev
)) {
3296 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3297 "2740 Received GET_DFC_REV request below "
3303 event_reply
= (struct get_mgmt_rev_reply
*)
3304 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
3306 if (job
->reply_len
<
3307 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev_reply
)) {
3308 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3309 "2741 Received GET_DFC_REV reply below "
3315 event_reply
->info
.a_Major
= MANAGEMENT_MAJOR_REV
;
3316 event_reply
->info
.a_Minor
= MANAGEMENT_MINOR_REV
;
3318 job
->reply
->result
= rc
;
3325 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
3326 * @phba: Pointer to HBA context object.
3327 * @pmboxq: Pointer to mailbox command.
3329 * This is completion handler function for mailbox commands issued from
3330 * lpfc_bsg_issue_mbox function. This function is called by the
3331 * mailbox event handler function with no lock held. This function
3332 * will wake up thread waiting on the wait queue pointed by context1
3336 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3338 struct bsg_job_data
*dd_data
;
3339 struct fc_bsg_job
*job
;
3341 unsigned long flags
;
3342 uint8_t *pmb
, *pmb_buf
;
3344 dd_data
= pmboxq
->context1
;
3347 * The outgoing buffer is readily referred from the dma buffer,
3348 * just need to get header part from mailboxq structure.
3350 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3351 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3352 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3354 /* Determine if job has been aborted */
3356 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3357 job
= dd_data
->set_job
;
3359 /* Prevent timeout handling from trying to abort job */
3360 job
->dd_data
= NULL
;
3362 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3364 /* Copy the mailbox data to the job if it is still active */
3367 size
= job
->reply_payload
.payload_len
;
3368 job
->reply
->reply_payload_rcv_len
=
3369 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3370 job
->reply_payload
.sg_cnt
,
3374 dd_data
->set_job
= NULL
;
3375 mempool_free(dd_data
->context_un
.mbox
.pmboxq
, phba
->mbox_mem_pool
);
3376 lpfc_bsg_dma_page_free(phba
, dd_data
->context_un
.mbox
.dmabuffers
);
3379 /* Complete the job if the job is still active */
3382 job
->reply
->result
= 0;
3389 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3390 * @phba: Pointer to HBA context object.
3391 * @mb: Pointer to a mailbox object.
3392 * @vport: Pointer to a vport object.
3394 * Some commands require the port to be offline, some may not be called from
3397 static int lpfc_bsg_check_cmd_access(struct lpfc_hba
*phba
,
3398 MAILBOX_t
*mb
, struct lpfc_vport
*vport
)
3400 /* return negative error values for bsg job */
3401 switch (mb
->mbxCommand
) {
3405 case MBX_CONFIG_LINK
:
3406 case MBX_CONFIG_RING
:
3407 case MBX_RESET_RING
:
3408 case MBX_UNREG_LOGIN
:
3410 case MBX_DUMP_CONTEXT
:
3414 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
3415 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3416 "2743 Command 0x%x is illegal in on-line "
3422 case MBX_WRITE_VPARMS
:
3425 case MBX_READ_CONFIG
:
3426 case MBX_READ_RCONFIG
:
3427 case MBX_READ_STATUS
:
3430 case MBX_READ_LNK_STAT
:
3431 case MBX_DUMP_MEMORY
:
3433 case MBX_UPDATE_CFG
:
3434 case MBX_KILL_BOARD
:
3435 case MBX_READ_TOPOLOGY
:
3437 case MBX_LOAD_EXP_ROM
:
3439 case MBX_DEL_LD_ENTRY
:
3442 case MBX_SLI4_CONFIG
:
3443 case MBX_READ_EVENT_LOG
:
3444 case MBX_READ_EVENT_LOG_STATUS
:
3445 case MBX_WRITE_EVENT_LOG
:
3446 case MBX_PORT_CAPABILITIES
:
3447 case MBX_PORT_IOV_CONTROL
:
3448 case MBX_RUN_BIU_DIAG64
:
3450 case MBX_SET_VARIABLE
:
3451 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3452 "1226 mbox: set_variable 0x%x, 0x%x\n",
3454 mb
->un
.varWords
[1]);
3455 if ((mb
->un
.varWords
[0] == SETVAR_MLOMNT
)
3456 && (mb
->un
.varWords
[1] == 1)) {
3457 phba
->wait_4_mlo_maint_flg
= 1;
3458 } else if (mb
->un
.varWords
[0] == SETVAR_MLORST
) {
3459 spin_lock_irq(&phba
->hbalock
);
3460 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
3461 spin_unlock_irq(&phba
->hbalock
);
3462 phba
->fc_topology
= LPFC_TOPOLOGY_PT_PT
;
3465 case MBX_READ_SPARM64
:
3467 case MBX_REG_LOGIN64
:
3468 case MBX_CONFIG_PORT
:
3469 case MBX_RUN_BIU_DIAG
:
3471 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3472 "2742 Unknown Command 0x%x\n",
3481 * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
3482 * @phba: Pointer to HBA context object.
3484 * This is routine clean up and reset BSG handling of multi-buffer mbox
3488 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba
*phba
)
3490 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
)
3493 /* free all memory, including dma buffers */
3494 lpfc_bsg_dma_page_list_free(phba
,
3495 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3496 lpfc_bsg_dma_page_free(phba
, phba
->mbox_ext_buf_ctx
.mbx_dmabuf
);
3497 /* multi-buffer write mailbox command pass-through complete */
3498 memset((char *)&phba
->mbox_ext_buf_ctx
, 0,
3499 sizeof(struct lpfc_mbox_ext_buf_ctx
));
3500 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3506 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3507 * @phba: Pointer to HBA context object.
3508 * @pmboxq: Pointer to mailbox command.
3510 * This is routine handles BSG job for mailbox commands completions with
3511 * multiple external buffers.
3513 static struct fc_bsg_job
*
3514 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3516 struct bsg_job_data
*dd_data
;
3517 struct fc_bsg_job
*job
;
3518 uint8_t *pmb
, *pmb_buf
;
3519 unsigned long flags
;
3522 struct lpfc_dmabuf
*dmabuf
;
3523 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3526 dd_data
= pmboxq
->context1
;
3528 /* Determine if job has been aborted */
3529 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3530 job
= dd_data
->set_job
;
3532 /* Prevent timeout handling from trying to abort job */
3533 job
->dd_data
= NULL
;
3535 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3538 * The outgoing buffer is readily referred from the dma buffer,
3539 * just need to get header part from mailboxq structure.
3542 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3543 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3544 /* Copy the byte swapped response mailbox back to the user */
3545 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3546 /* if there is any non-embedded extended data copy that too */
3547 dmabuf
= phba
->mbox_ext_buf_ctx
.mbx_dmabuf
;
3548 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3549 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3550 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3551 pmbx
= (uint8_t *)dmabuf
->virt
;
3552 /* byte swap the extended data following the mailbox command */
3553 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3554 &pmbx
[sizeof(MAILBOX_t
)],
3555 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[0].buf_len
);
3558 /* Complete the job if the job is still active */
3561 size
= job
->reply_payload
.payload_len
;
3562 job
->reply
->reply_payload_rcv_len
=
3563 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3564 job
->reply_payload
.sg_cnt
,
3567 /* result for successful */
3568 job
->reply
->result
= 0;
3570 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3571 "2937 SLI_CONFIG ext-buffer maibox command "
3572 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3573 phba
->mbox_ext_buf_ctx
.nembType
,
3574 phba
->mbox_ext_buf_ctx
.mboxType
, size
);
3575 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
,
3576 phba
->mbox_ext_buf_ctx
.nembType
,
3577 phba
->mbox_ext_buf_ctx
.mboxType
,
3578 dma_ebuf
, sta_pos_addr
,
3579 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
, 0);
3581 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3582 "2938 SLI_CONFIG ext-buffer maibox "
3583 "command (x%x/x%x) failure, rc:x%x\n",
3584 phba
->mbox_ext_buf_ctx
.nembType
,
3585 phba
->mbox_ext_buf_ctx
.mboxType
, rc
);
3590 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_DONE
;
3596 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3597 * @phba: Pointer to HBA context object.
3598 * @pmboxq: Pointer to mailbox command.
3600 * This is completion handler function for mailbox read commands with multiple
3604 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3606 struct fc_bsg_job
*job
;
3608 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3610 /* handle the BSG job with mailbox command */
3612 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3614 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3615 "2939 SLI_CONFIG ext-buffer rd maibox command "
3616 "complete, ctxState:x%x, mbxStatus:x%x\n",
3617 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3619 if (pmboxq
->u
.mb
.mbxStatus
|| phba
->mbox_ext_buf_ctx
.numBuf
== 1)
3620 lpfc_bsg_mbox_ext_session_reset(phba
);
3622 /* free base driver mailbox structure memory */
3623 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3625 /* if the job is still active, call job done */
3633 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3634 * @phba: Pointer to HBA context object.
3635 * @pmboxq: Pointer to mailbox command.
3637 * This is completion handler function for mailbox write commands with multiple
3641 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3643 struct fc_bsg_job
*job
;
3645 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3647 /* handle the BSG job with the mailbox command */
3649 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3651 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3652 "2940 SLI_CONFIG ext-buffer wr maibox command "
3653 "complete, ctxState:x%x, mbxStatus:x%x\n",
3654 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3656 /* free all memory, including dma buffers */
3657 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3658 lpfc_bsg_mbox_ext_session_reset(phba
);
3660 /* if the job is still active, call job done */
3668 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba
*phba
, enum nemb_type nemb_tp
,
3669 uint32_t index
, struct lpfc_dmabuf
*mbx_dmabuf
,
3670 struct lpfc_dmabuf
*ext_dmabuf
)
3672 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3674 /* pointer to the start of mailbox command */
3675 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)mbx_dmabuf
->virt
;
3677 if (nemb_tp
== nemb_mse
) {
3679 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3681 putPaddrHigh(mbx_dmabuf
->phys
+
3683 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3685 putPaddrLow(mbx_dmabuf
->phys
+
3687 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3688 "2943 SLI_CONFIG(mse)[%d], "
3689 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3691 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3693 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3695 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3698 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3700 putPaddrHigh(ext_dmabuf
->phys
);
3701 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3703 putPaddrLow(ext_dmabuf
->phys
);
3704 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3705 "2944 SLI_CONFIG(mse)[%d], "
3706 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3708 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3710 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3712 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3717 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3719 putPaddrHigh(mbx_dmabuf
->phys
+
3721 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3723 putPaddrLow(mbx_dmabuf
->phys
+
3725 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3726 "3007 SLI_CONFIG(hbd)[%d], "
3727 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3729 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3731 sli_config_emb1_subsys
.hbd
[index
]),
3732 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3734 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3738 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3740 putPaddrHigh(ext_dmabuf
->phys
);
3741 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3743 putPaddrLow(ext_dmabuf
->phys
);
3744 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3745 "3008 SLI_CONFIG(hbd)[%d], "
3746 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3748 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3750 sli_config_emb1_subsys
.hbd
[index
]),
3751 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3753 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3761 * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
3762 * @phba: Pointer to HBA context object.
3763 * @mb: Pointer to a BSG mailbox object.
3764 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3765 * @dmabuff: Pointer to a DMA buffer descriptor.
3767 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3768 * non-embedded external bufffers.
3771 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3772 enum nemb_type nemb_tp
,
3773 struct lpfc_dmabuf
*dmabuf
)
3775 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3776 struct dfc_mbox_req
*mbox_req
;
3777 struct lpfc_dmabuf
*curr_dmabuf
, *next_dmabuf
;
3778 uint32_t ext_buf_cnt
, ext_buf_index
;
3779 struct lpfc_dmabuf
*ext_dmabuf
= NULL
;
3780 struct bsg_job_data
*dd_data
= NULL
;
3781 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3787 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3789 /* pointer to the start of mailbox command */
3790 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3792 if (nemb_tp
== nemb_mse
) {
3793 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3794 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3795 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3796 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3797 "2945 Handled SLI_CONFIG(mse) rd, "
3798 "ext_buf_cnt(%d) out of range(%d)\n",
3800 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3804 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3805 "2941 Handled SLI_CONFIG(mse) rd, "
3806 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3808 /* sanity check on interface type for support */
3809 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3810 LPFC_SLI_INTF_IF_TYPE_2
) {
3814 /* nemb_tp == nemb_hbd */
3815 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3816 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3817 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3818 "2946 Handled SLI_CONFIG(hbd) rd, "
3819 "ext_buf_cnt(%d) out of range(%d)\n",
3821 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3825 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3826 "2942 Handled SLI_CONFIG(hbd) rd, "
3827 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3830 /* before dma descriptor setup */
3831 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3832 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3834 /* reject non-embedded mailbox command with none external buffer */
3835 if (ext_buf_cnt
== 0) {
3838 } else if (ext_buf_cnt
> 1) {
3839 /* additional external read buffers */
3840 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3841 ext_dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
3846 list_add_tail(&ext_dmabuf
->list
,
3847 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3851 /* bsg tracking structure */
3852 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3858 /* mailbox command structure for base driver */
3859 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3864 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3866 /* for the first external buffer */
3867 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3869 /* for the rest of external buffer descriptors if any */
3870 if (ext_buf_cnt
> 1) {
3872 list_for_each_entry_safe(curr_dmabuf
, next_dmabuf
,
3873 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
, list
) {
3874 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
,
3875 ext_buf_index
, dmabuf
,
3881 /* after dma descriptor setup */
3882 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3883 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3885 /* construct base driver mbox command */
3886 pmb
= &pmboxq
->u
.mb
;
3887 pmbx
= (uint8_t *)dmabuf
->virt
;
3888 memcpy(pmb
, pmbx
, sizeof(*pmb
));
3889 pmb
->mbxOwner
= OWN_HOST
;
3890 pmboxq
->vport
= phba
->pport
;
3892 /* multi-buffer handling context */
3893 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3894 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_rd
;
3895 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3896 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3897 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3898 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3900 /* callback for multi-buffer read mailbox command */
3901 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_read_mbox_ext_cmpl
;
3903 /* context fields to callback function */
3904 pmboxq
->context1
= dd_data
;
3905 dd_data
->type
= TYPE_MBOX
;
3906 dd_data
->set_job
= job
;
3907 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3908 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
3909 job
->dd_data
= dd_data
;
3912 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3915 * Non-embedded mailbox subcommand data gets byte swapped here because
3916 * the lower level driver code only does the first 64 mailbox words.
3918 if ((!bsg_bf_get(lpfc_mbox_hdr_emb
,
3919 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) &&
3920 (nemb_tp
== nemb_mse
))
3921 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3922 &pmbx
[sizeof(MAILBOX_t
)],
3923 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3926 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3927 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3928 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3929 "2947 Issued SLI_CONFIG ext-buffer "
3930 "maibox command, rc:x%x\n", rc
);
3931 return SLI_CONFIG_HANDLED
;
3933 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3934 "2948 Failed to issue SLI_CONFIG ext-buffer "
3935 "maibox command, rc:x%x\n", rc
);
3940 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3941 lpfc_bsg_dma_page_list_free(phba
,
3942 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3944 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
3949 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
3950 * @phba: Pointer to HBA context object.
3951 * @mb: Pointer to a BSG mailbox object.
3952 * @dmabuff: Pointer to a DMA buffer descriptor.
3954 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
3955 * non-embedded external bufffers.
3958 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3959 enum nemb_type nemb_tp
,
3960 struct lpfc_dmabuf
*dmabuf
)
3962 struct dfc_mbox_req
*mbox_req
;
3963 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3964 uint32_t ext_buf_cnt
;
3965 struct bsg_job_data
*dd_data
= NULL
;
3966 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3969 int rc
= SLI_CONFIG_NOT_HANDLED
, i
;
3972 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3974 /* pointer to the start of mailbox command */
3975 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3977 if (nemb_tp
== nemb_mse
) {
3978 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3979 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3980 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3981 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3982 "2953 Failed SLI_CONFIG(mse) wr, "
3983 "ext_buf_cnt(%d) out of range(%d)\n",
3985 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3988 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3989 "2949 Handled SLI_CONFIG(mse) wr, "
3990 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3992 /* sanity check on interface type for support */
3993 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3994 LPFC_SLI_INTF_IF_TYPE_2
)
3996 /* nemb_tp == nemb_hbd */
3997 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3998 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3999 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4000 "2954 Failed SLI_CONFIG(hbd) wr, "
4001 "ext_buf_cnt(%d) out of range(%d)\n",
4003 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
4006 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4007 "2950 Handled SLI_CONFIG(hbd) wr, "
4008 "ext_buf_cnt:%d\n", ext_buf_cnt
);
4011 /* before dma buffer descriptor setup */
4012 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
4013 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
4015 if (ext_buf_cnt
== 0)
4018 /* for the first external buffer */
4019 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
4021 /* after dma descriptor setup */
4022 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
4023 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
4025 /* log for looking forward */
4026 for (i
= 1; i
< ext_buf_cnt
; i
++) {
4027 if (nemb_tp
== nemb_mse
)
4028 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4029 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
4030 i
, sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
4033 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4034 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
4035 i
, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
4036 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
4040 /* multi-buffer handling context */
4041 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
4042 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_wr
;
4043 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
4044 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
4045 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
4046 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
4048 if (ext_buf_cnt
== 1) {
4049 /* bsg tracking structure */
4050 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4056 /* mailbox command structure for base driver */
4057 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4062 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4063 pmb
= &pmboxq
->u
.mb
;
4064 mbx
= (uint8_t *)dmabuf
->virt
;
4065 memcpy(pmb
, mbx
, sizeof(*pmb
));
4066 pmb
->mbxOwner
= OWN_HOST
;
4067 pmboxq
->vport
= phba
->pport
;
4069 /* callback for multi-buffer read mailbox command */
4070 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
4072 /* context fields to callback function */
4073 pmboxq
->context1
= dd_data
;
4074 dd_data
->type
= TYPE_MBOX
;
4075 dd_data
->set_job
= job
;
4076 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4077 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)mbx
;
4078 job
->dd_data
= dd_data
;
4082 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4083 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4084 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4085 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4086 "2955 Issued SLI_CONFIG ext-buffer "
4087 "maibox command, rc:x%x\n", rc
);
4088 return SLI_CONFIG_HANDLED
;
4090 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4091 "2956 Failed to issue SLI_CONFIG ext-buffer "
4092 "maibox command, rc:x%x\n", rc
);
4097 /* wait for additoinal external buffers */
4099 job
->reply
->result
= 0;
4101 return SLI_CONFIG_HANDLED
;
4105 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4112 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
4113 * @phba: Pointer to HBA context object.
4114 * @mb: Pointer to a BSG mailbox object.
4115 * @dmabuff: Pointer to a DMA buffer descriptor.
4117 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
4118 * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
4119 * with embedded sussystem 0x1 and opcodes with external HBDs.
4122 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4123 struct lpfc_dmabuf
*dmabuf
)
4125 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4128 int rc
= SLI_CONFIG_NOT_HANDLED
;
4130 /* state change on new multi-buffer pass-through mailbox command */
4131 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_HOST
;
4133 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
4135 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
4136 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
4137 subsys
= bsg_bf_get(lpfc_emb0_subcmnd_subsys
,
4138 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
4139 opcode
= bsg_bf_get(lpfc_emb0_subcmnd_opcode
,
4140 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
4141 if (subsys
== SLI_CONFIG_SUBSYS_FCOE
) {
4143 case FCOE_OPCODE_READ_FCF
:
4144 case FCOE_OPCODE_GET_DPORT_RESULTS
:
4145 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4146 "2957 Handled SLI_CONFIG "
4147 "subsys_fcoe, opcode:x%x\n",
4149 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4152 case FCOE_OPCODE_ADD_FCF
:
4153 case FCOE_OPCODE_SET_DPORT_MODE
:
4154 case LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
:
4155 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4156 "2958 Handled SLI_CONFIG "
4157 "subsys_fcoe, opcode:x%x\n",
4159 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
4163 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4164 "2959 Reject SLI_CONFIG "
4165 "subsys_fcoe, opcode:x%x\n",
4170 } else if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
4172 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES
:
4173 case COMN_OPCODE_GET_CNTL_ATTRIBUTES
:
4174 case COMN_OPCODE_GET_PROFILE_CONFIG
:
4175 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4176 "3106 Handled SLI_CONFIG "
4177 "subsys_comn, opcode:x%x\n",
4179 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4183 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4184 "3107 Reject SLI_CONFIG "
4185 "subsys_comn, opcode:x%x\n",
4191 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4192 "2977 Reject SLI_CONFIG "
4193 "subsys:x%d, opcode:x%x\n",
4198 subsys
= bsg_bf_get(lpfc_emb1_subcmnd_subsys
,
4199 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4200 opcode
= bsg_bf_get(lpfc_emb1_subcmnd_opcode
,
4201 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4202 if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
4204 case COMN_OPCODE_READ_OBJECT
:
4205 case COMN_OPCODE_READ_OBJECT_LIST
:
4206 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4207 "2960 Handled SLI_CONFIG "
4208 "subsys_comn, opcode:x%x\n",
4210 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4213 case COMN_OPCODE_WRITE_OBJECT
:
4214 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4215 "2961 Handled SLI_CONFIG "
4216 "subsys_comn, opcode:x%x\n",
4218 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
4222 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4223 "2962 Not handled SLI_CONFIG "
4224 "subsys_comn, opcode:x%x\n",
4226 rc
= SLI_CONFIG_NOT_HANDLED
;
4230 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4231 "2978 Not handled SLI_CONFIG "
4232 "subsys:x%d, opcode:x%x\n",
4234 rc
= SLI_CONFIG_NOT_HANDLED
;
4238 /* state reset on not handled new multi-buffer mailbox command */
4239 if (rc
!= SLI_CONFIG_HANDLED
)
4240 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
4246 * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
4247 * @phba: Pointer to HBA context object.
4249 * This routine is for requesting to abort a pass-through mailbox command with
4250 * multiple external buffers due to error condition.
4253 lpfc_bsg_mbox_ext_abort(struct lpfc_hba
*phba
)
4255 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
4256 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
4258 lpfc_bsg_mbox_ext_session_reset(phba
);
4263 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
4264 * @phba: Pointer to HBA context object.
4265 * @dmabuf: Pointer to a DMA buffer descriptor.
4267 * This routine extracts the next mailbox read external buffer back to
4268 * user space through BSG.
4271 lpfc_bsg_read_ebuf_get(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
4273 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4274 struct lpfc_dmabuf
*dmabuf
;
4279 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4280 phba
->mbox_ext_buf_ctx
.seqNum
++;
4282 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4283 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4285 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4286 size
= bsg_bf_get(lpfc_mbox_sli_config_mse_len
,
4287 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[index
]);
4288 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4289 "2963 SLI_CONFIG (mse) ext-buffer rd get "
4290 "buffer[%d], size:%d\n", index
, size
);
4292 size
= bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
4293 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd
[index
]);
4294 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4295 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
4296 "buffer[%d], size:%d\n", index
, size
);
4298 if (list_empty(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
))
4300 dmabuf
= list_first_entry(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
,
4301 struct lpfc_dmabuf
, list
);
4302 list_del_init(&dmabuf
->list
);
4304 /* after dma buffer descriptor setup */
4305 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4306 mbox_rd
, dma_ebuf
, sta_pos_addr
,
4309 pbuf
= (uint8_t *)dmabuf
->virt
;
4310 job
->reply
->reply_payload_rcv_len
=
4311 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4312 job
->reply_payload
.sg_cnt
,
4315 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4317 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4318 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4319 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
4320 "command session done\n");
4321 lpfc_bsg_mbox_ext_session_reset(phba
);
4324 job
->reply
->result
= 0;
4327 return SLI_CONFIG_HANDLED
;
4331 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
4332 * @phba: Pointer to HBA context object.
4333 * @dmabuf: Pointer to a DMA buffer descriptor.
4335 * This routine sets up the next mailbox read external buffer obtained
4336 * from user space through BSG.
4339 lpfc_bsg_write_ebuf_set(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4340 struct lpfc_dmabuf
*dmabuf
)
4342 struct bsg_job_data
*dd_data
= NULL
;
4343 LPFC_MBOXQ_t
*pmboxq
= NULL
;
4345 enum nemb_type nemb_tp
;
4351 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4352 phba
->mbox_ext_buf_ctx
.seqNum
++;
4353 nemb_tp
= phba
->mbox_ext_buf_ctx
.nembType
;
4355 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4361 pbuf
= (uint8_t *)dmabuf
->virt
;
4362 size
= job
->request_payload
.payload_len
;
4363 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4364 job
->request_payload
.sg_cnt
,
4367 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4368 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4369 "2966 SLI_CONFIG (mse) ext-buffer wr set "
4370 "buffer[%d], size:%d\n",
4371 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4374 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4375 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
4376 "buffer[%d], size:%d\n",
4377 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4381 /* set up external buffer descriptor and add to external buffer list */
4382 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, index
,
4383 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
,
4385 list_add_tail(&dmabuf
->list
, &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4387 /* after write dma buffer */
4388 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4389 mbox_wr
, dma_ebuf
, sta_pos_addr
,
4392 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4393 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4394 "2968 SLI_CONFIG ext-buffer wr all %d "
4395 "ebuffers received\n",
4396 phba
->mbox_ext_buf_ctx
.numBuf
);
4397 /* mailbox command structure for base driver */
4398 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4403 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4404 pbuf
= (uint8_t *)phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4405 pmb
= &pmboxq
->u
.mb
;
4406 memcpy(pmb
, pbuf
, sizeof(*pmb
));
4407 pmb
->mbxOwner
= OWN_HOST
;
4408 pmboxq
->vport
= phba
->pport
;
4410 /* callback for multi-buffer write mailbox command */
4411 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
4413 /* context fields to callback function */
4414 pmboxq
->context1
= dd_data
;
4415 dd_data
->type
= TYPE_MBOX
;
4416 dd_data
->set_job
= job
;
4417 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4418 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pbuf
;
4419 job
->dd_data
= dd_data
;
4422 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4424 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4425 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4426 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4427 "2969 Issued SLI_CONFIG ext-buffer "
4428 "maibox command, rc:x%x\n", rc
);
4429 return SLI_CONFIG_HANDLED
;
4431 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4432 "2970 Failed to issue SLI_CONFIG ext-buffer "
4433 "maibox command, rc:x%x\n", rc
);
4438 /* wait for additoinal external buffers */
4439 job
->reply
->result
= 0;
4441 return SLI_CONFIG_HANDLED
;
4444 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4451 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4452 * @phba: Pointer to HBA context object.
4453 * @mb: Pointer to a BSG mailbox object.
4454 * @dmabuff: Pointer to a DMA buffer descriptor.
4456 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4457 * command with multiple non-embedded external buffers.
4460 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4461 struct lpfc_dmabuf
*dmabuf
)
4465 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4466 "2971 SLI_CONFIG buffer (type:x%x)\n",
4467 phba
->mbox_ext_buf_ctx
.mboxType
);
4469 if (phba
->mbox_ext_buf_ctx
.mboxType
== mbox_rd
) {
4470 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_DONE
) {
4471 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4472 "2972 SLI_CONFIG rd buffer state "
4474 phba
->mbox_ext_buf_ctx
.state
);
4475 lpfc_bsg_mbox_ext_abort(phba
);
4478 rc
= lpfc_bsg_read_ebuf_get(phba
, job
);
4479 if (rc
== SLI_CONFIG_HANDLED
)
4480 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4481 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4482 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_HOST
) {
4483 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4484 "2973 SLI_CONFIG wr buffer state "
4486 phba
->mbox_ext_buf_ctx
.state
);
4487 lpfc_bsg_mbox_ext_abort(phba
);
4490 rc
= lpfc_bsg_write_ebuf_set(phba
, job
, dmabuf
);
4496 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4497 * @phba: Pointer to HBA context object.
4498 * @mb: Pointer to a BSG mailbox object.
4499 * @dmabuff: Pointer to a DMA buffer descriptor.
4501 * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
4502 * (0x9B) mailbox commands and external buffers.
4505 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4506 struct lpfc_dmabuf
*dmabuf
)
4508 struct dfc_mbox_req
*mbox_req
;
4509 int rc
= SLI_CONFIG_NOT_HANDLED
;
4512 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4514 /* mbox command with/without single external buffer */
4515 if (mbox_req
->extMboxTag
== 0 && mbox_req
->extSeqNum
== 0)
4518 /* mbox command and first external buffer */
4519 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
) {
4520 if (mbox_req
->extSeqNum
== 1) {
4521 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4522 "2974 SLI_CONFIG mailbox: tag:%d, "
4523 "seq:%d\n", mbox_req
->extMboxTag
,
4524 mbox_req
->extSeqNum
);
4525 rc
= lpfc_bsg_handle_sli_cfg_mbox(phba
, job
, dmabuf
);
4528 goto sli_cfg_ext_error
;
4532 * handle additional external buffers
4535 /* check broken pipe conditions */
4536 if (mbox_req
->extMboxTag
!= phba
->mbox_ext_buf_ctx
.mbxTag
)
4537 goto sli_cfg_ext_error
;
4538 if (mbox_req
->extSeqNum
> phba
->mbox_ext_buf_ctx
.numBuf
)
4539 goto sli_cfg_ext_error
;
4540 if (mbox_req
->extSeqNum
!= phba
->mbox_ext_buf_ctx
.seqNum
+ 1)
4541 goto sli_cfg_ext_error
;
4543 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4544 "2975 SLI_CONFIG mailbox external buffer: "
4545 "extSta:x%x, tag:%d, seq:%d\n",
4546 phba
->mbox_ext_buf_ctx
.state
, mbox_req
->extMboxTag
,
4547 mbox_req
->extSeqNum
);
4548 rc
= lpfc_bsg_handle_sli_cfg_ebuf(phba
, job
, dmabuf
);
4552 /* all other cases, broken pipe */
4553 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4554 "2976 SLI_CONFIG mailbox broken pipe: "
4555 "ctxSta:x%x, ctxNumBuf:%d "
4556 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4557 phba
->mbox_ext_buf_ctx
.state
,
4558 phba
->mbox_ext_buf_ctx
.numBuf
,
4559 phba
->mbox_ext_buf_ctx
.mbxTag
,
4560 phba
->mbox_ext_buf_ctx
.seqNum
,
4561 mbox_req
->extMboxTag
, mbox_req
->extSeqNum
);
4563 lpfc_bsg_mbox_ext_session_reset(phba
);
4569 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4570 * @phba: Pointer to HBA context object.
4571 * @mb: Pointer to a mailbox object.
4572 * @vport: Pointer to a vport object.
4574 * Allocate a tracking object, mailbox command memory, get a mailbox
4575 * from the mailbox pool, copy the caller mailbox command.
4577 * If offline and the sli is active we need to poll for the command (port is
4578 * being reset) and com-plete the job, otherwise issue the mailbox command and
4579 * let our completion handler finish the command.
4582 lpfc_bsg_issue_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4583 struct lpfc_vport
*vport
)
4585 LPFC_MBOXQ_t
*pmboxq
= NULL
; /* internal mailbox queue */
4586 MAILBOX_t
*pmb
; /* shortcut to the pmboxq mailbox */
4587 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4588 uint8_t *pmbx
= NULL
;
4589 struct bsg_job_data
*dd_data
= NULL
; /* bsg data tracking structure */
4590 struct lpfc_dmabuf
*dmabuf
= NULL
;
4591 struct dfc_mbox_req
*mbox_req
;
4592 struct READ_EVENT_LOG_VAR
*rdEventLog
;
4593 uint32_t transmit_length
, receive_length
, mode
;
4594 struct lpfc_mbx_sli4_config
*sli4_config
;
4595 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
4596 struct ulp_bde64
*bde
;
4597 uint8_t *ext
= NULL
;
4602 /* in case no data is transferred */
4603 job
->reply
->reply_payload_rcv_len
= 0;
4605 /* sanity check to protect driver */
4606 if (job
->reply_payload
.payload_len
> BSG_MBOX_SIZE
||
4607 job
->request_payload
.payload_len
> BSG_MBOX_SIZE
) {
4613 * Don't allow mailbox commands to be sent when blocked or when in
4614 * the middle of discovery
4616 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4622 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4624 /* check if requested extended data lengths are valid */
4625 if ((mbox_req
->inExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t)) ||
4626 (mbox_req
->outExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t))) {
4631 dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
4632 if (!dmabuf
|| !dmabuf
->virt
) {
4637 /* Get the mailbox command or external buffer from BSG */
4638 pmbx
= (uint8_t *)dmabuf
->virt
;
4639 size
= job
->request_payload
.payload_len
;
4640 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4641 job
->request_payload
.sg_cnt
, pmbx
, size
);
4643 /* Handle possible SLI_CONFIG with non-embedded payloads */
4644 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4645 rc
= lpfc_bsg_handle_sli_cfg_ext(phba
, job
, dmabuf
);
4646 if (rc
== SLI_CONFIG_HANDLED
)
4650 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4653 rc
= lpfc_bsg_check_cmd_access(phba
, (MAILBOX_t
*)pmbx
, vport
);
4655 goto job_done
; /* must be negative */
4657 /* allocate our bsg tracking structure */
4658 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4660 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4661 "2727 Failed allocation of dd_data\n");
4666 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4671 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4673 pmb
= &pmboxq
->u
.mb
;
4674 memcpy(pmb
, pmbx
, sizeof(*pmb
));
4675 pmb
->mbxOwner
= OWN_HOST
;
4676 pmboxq
->vport
= vport
;
4678 /* If HBA encountered an error attention, allow only DUMP
4679 * or RESTART mailbox commands until the HBA is restarted.
4681 if (phba
->pport
->stopped
&&
4682 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4683 pmb
->mbxCommand
!= MBX_RESTART
&&
4684 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4685 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4686 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4687 "2797 mbox: Issued mailbox cmd "
4688 "0x%x while in stopped state.\n",
4691 /* extended mailbox commands will need an extended buffer */
4692 if (mbox_req
->inExtWLen
|| mbox_req
->outExtWLen
) {
4694 ext
= from
+ sizeof(MAILBOX_t
);
4695 pmboxq
->context2
= ext
;
4696 pmboxq
->in_ext_byte_len
=
4697 mbox_req
->inExtWLen
* sizeof(uint32_t);
4698 pmboxq
->out_ext_byte_len
=
4699 mbox_req
->outExtWLen
* sizeof(uint32_t);
4700 pmboxq
->mbox_offset_word
= mbox_req
->mbOffset
;
4703 /* biu diag will need a kernel buffer to transfer the data
4704 * allocate our own buffer and setup the mailbox command to
4707 if (pmb
->mbxCommand
== MBX_RUN_BIU_DIAG64
) {
4708 transmit_length
= pmb
->un
.varWords
[1];
4709 receive_length
= pmb
->un
.varWords
[4];
4710 /* transmit length cannot be greater than receive length or
4711 * mailbox extension size
4713 if ((transmit_length
> receive_length
) ||
4714 (transmit_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4718 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrHigh
=
4719 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4720 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrLow
=
4721 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4723 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrHigh
=
4724 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4725 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4726 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrLow
=
4727 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4728 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4729 } else if (pmb
->mbxCommand
== MBX_READ_EVENT_LOG
) {
4730 rdEventLog
= &pmb
->un
.varRdEventLog
;
4731 receive_length
= rdEventLog
->rcv_bde64
.tus
.f
.bdeSize
;
4732 mode
= bf_get(lpfc_event_log
, rdEventLog
);
4734 /* receive length cannot be greater than mailbox
4737 if (receive_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4742 /* mode zero uses a bde like biu diags command */
4744 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4745 + sizeof(MAILBOX_t
));
4746 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4747 + sizeof(MAILBOX_t
));
4749 } else if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4750 /* Let type 4 (well known data) through because the data is
4751 * returned in varwords[4-8]
4752 * otherwise check the recieve length and fetch the buffer addr
4754 if ((pmb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
4755 (pmb
->un
.varDmp
.type
!= DMP_WELL_KNOWN
)) {
4756 /* rebuild the command for sli4 using our own buffers
4757 * like we do for biu diags
4759 receive_length
= pmb
->un
.varWords
[2];
4760 /* receive length cannot be greater than mailbox
4763 if (receive_length
== 0) {
4767 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4768 + sizeof(MAILBOX_t
));
4769 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4770 + sizeof(MAILBOX_t
));
4771 } else if ((pmb
->mbxCommand
== MBX_UPDATE_CFG
) &&
4772 pmb
->un
.varUpdateCfg
.co
) {
4773 bde
= (struct ulp_bde64
*)&pmb
->un
.varWords
[4];
4775 /* bde size cannot be greater than mailbox ext size */
4776 if (bde
->tus
.f
.bdeSize
>
4777 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4781 bde
->addrHigh
= putPaddrHigh(dmabuf
->phys
4782 + sizeof(MAILBOX_t
));
4783 bde
->addrLow
= putPaddrLow(dmabuf
->phys
4784 + sizeof(MAILBOX_t
));
4785 } else if (pmb
->mbxCommand
== MBX_SLI4_CONFIG
) {
4786 /* Handling non-embedded SLI_CONFIG mailbox command */
4787 sli4_config
= &pmboxq
->u
.mqe
.un
.sli4_config
;
4788 if (!bf_get(lpfc_mbox_hdr_emb
,
4789 &sli4_config
->header
.cfg_mhdr
)) {
4790 /* rebuild the command for sli4 using our
4791 * own buffers like we do for biu diags
4793 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
4794 &pmb
->un
.varWords
[0];
4795 receive_length
= nembed_sge
->sge
[0].length
;
4797 /* receive length cannot be greater than
4798 * mailbox extension size
4800 if ((receive_length
== 0) ||
4802 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4807 nembed_sge
->sge
[0].pa_hi
=
4808 putPaddrHigh(dmabuf
->phys
4809 + sizeof(MAILBOX_t
));
4810 nembed_sge
->sge
[0].pa_lo
=
4811 putPaddrLow(dmabuf
->phys
4812 + sizeof(MAILBOX_t
));
4817 dd_data
->context_un
.mbox
.dmabuffers
= dmabuf
;
4819 /* setup wake call as IOCB callback */
4820 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_mbox_cmpl
;
4822 /* setup context field to pass wait_queue pointer to wake function */
4823 pmboxq
->context1
= dd_data
;
4824 dd_data
->type
= TYPE_MBOX
;
4825 dd_data
->set_job
= job
;
4826 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4827 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
4828 dd_data
->context_un
.mbox
.ext
= ext
;
4829 dd_data
->context_un
.mbox
.mbOffset
= mbox_req
->mbOffset
;
4830 dd_data
->context_un
.mbox
.inExtWLen
= mbox_req
->inExtWLen
;
4831 dd_data
->context_un
.mbox
.outExtWLen
= mbox_req
->outExtWLen
;
4832 job
->dd_data
= dd_data
;
4834 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4835 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4836 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4837 if (rc
!= MBX_SUCCESS
) {
4838 rc
= (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4842 /* job finished, copy the data */
4843 memcpy(pmbx
, pmb
, sizeof(*pmb
));
4844 job
->reply
->reply_payload_rcv_len
=
4845 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4846 job
->reply_payload
.sg_cnt
,
4848 /* not waiting mbox already done */
4853 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4854 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
))
4855 return 1; /* job started */
4858 /* common exit for error or job completed inline */
4860 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4861 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4869 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
4870 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
4873 lpfc_bsg_mbox_cmd(struct fc_bsg_job
*job
)
4875 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4876 struct lpfc_hba
*phba
= vport
->phba
;
4877 struct dfc_mbox_req
*mbox_req
;
4880 /* mix-and-match backward compatibility */
4881 job
->reply
->reply_payload_rcv_len
= 0;
4882 if (job
->request_len
<
4883 sizeof(struct fc_bsg_request
) + sizeof(struct dfc_mbox_req
)) {
4884 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4885 "2737 Mix-and-match backward compatibility "
4886 "between MBOX_REQ old size:%d and "
4887 "new request size:%d\n",
4888 (int)(job
->request_len
-
4889 sizeof(struct fc_bsg_request
)),
4890 (int)sizeof(struct dfc_mbox_req
));
4891 mbox_req
= (struct dfc_mbox_req
*)
4892 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4893 mbox_req
->extMboxTag
= 0;
4894 mbox_req
->extSeqNum
= 0;
4897 rc
= lpfc_bsg_issue_mbox(phba
, job
, vport
);
4901 job
->reply
->result
= 0;
4902 job
->dd_data
= NULL
;
4905 /* job submitted, will complete later*/
4906 rc
= 0; /* return zero, no error */
4908 /* some error occurred */
4909 job
->reply
->result
= rc
;
4910 job
->dd_data
= NULL
;
4917 * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
4918 * @phba: Pointer to HBA context object.
4919 * @cmdiocbq: Pointer to command iocb.
4920 * @rspiocbq: Pointer to response iocb.
4922 * This function is the completion handler for iocbs issued using
4923 * lpfc_menlo_cmd function. This function is called by the
4924 * ring event handler function without any lock held. This function
4925 * can be called from both worker thread context and interrupt
4926 * context. This function also can be called from another thread which
4927 * cleans up the SLI layer objects.
4928 * This function copies the contents of the response iocb to the
4929 * response iocb memory object provided by the caller of
4930 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4931 * sleeps for the iocb completion.
4934 lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba
*phba
,
4935 struct lpfc_iocbq
*cmdiocbq
,
4936 struct lpfc_iocbq
*rspiocbq
)
4938 struct bsg_job_data
*dd_data
;
4939 struct fc_bsg_job
*job
;
4941 struct lpfc_dmabuf
*bmp
, *cmp
, *rmp
;
4942 struct lpfc_bsg_menlo
*menlo
;
4943 unsigned long flags
;
4944 struct menlo_response
*menlo_resp
;
4945 unsigned int rsp_size
;
4948 dd_data
= cmdiocbq
->context1
;
4949 cmp
= cmdiocbq
->context2
;
4950 bmp
= cmdiocbq
->context3
;
4951 menlo
= &dd_data
->context_un
.menlo
;
4953 rsp
= &rspiocbq
->iocb
;
4955 /* Determine if job has been aborted */
4956 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
4957 job
= dd_data
->set_job
;
4959 /* Prevent timeout handling from trying to abort job */
4960 job
->dd_data
= NULL
;
4962 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4964 /* Copy the job data or set the failing status for the job */
4967 /* always return the xri, this would be used in the case
4968 * of a menlo download to allow the data to be sent as a
4969 * continuation of the exchange.
4972 menlo_resp
= (struct menlo_response
*)
4973 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4974 menlo_resp
->xri
= rsp
->ulpContext
;
4975 if (rsp
->ulpStatus
) {
4976 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
4977 switch (rsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) {
4978 case IOERR_SEQUENCE_TIMEOUT
:
4981 case IOERR_INVALID_RPI
:
4992 rsp_size
= rsp
->un
.genreq64
.bdl
.bdeSize
;
4993 job
->reply
->reply_payload_rcv_len
=
4994 lpfc_bsg_copy_data(rmp
, &job
->reply_payload
,
5000 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
5001 lpfc_free_bsg_buffers(phba
, cmp
);
5002 lpfc_free_bsg_buffers(phba
, rmp
);
5003 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
5007 /* Complete the job if active */
5010 job
->reply
->result
= rc
;
5018 * lpfc_menlo_cmd - send an ioctl for menlo hardware
5019 * @job: fc_bsg_job to handle
5021 * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
5022 * all the command completions will return the xri for the command.
5023 * For menlo data requests a gen request 64 CX is used to continue the exchange
5024 * supplied in the menlo request header xri field.
5027 lpfc_menlo_cmd(struct fc_bsg_job
*job
)
5029 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
5030 struct lpfc_hba
*phba
= vport
->phba
;
5031 struct lpfc_iocbq
*cmdiocbq
;
5034 struct menlo_command
*menlo_cmd
;
5035 struct lpfc_dmabuf
*bmp
= NULL
, *cmp
= NULL
, *rmp
= NULL
;
5038 struct bsg_job_data
*dd_data
;
5039 struct ulp_bde64
*bpl
= NULL
;
5041 /* in case no data is returned return just the return code */
5042 job
->reply
->reply_payload_rcv_len
= 0;
5044 if (job
->request_len
<
5045 sizeof(struct fc_bsg_request
) +
5046 sizeof(struct menlo_command
)) {
5047 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5048 "2784 Received MENLO_CMD request below "
5054 if (job
->reply_len
<
5055 sizeof(struct fc_bsg_request
) + sizeof(struct menlo_response
)) {
5056 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5057 "2785 Received MENLO_CMD reply below "
5063 if (!(phba
->menlo_flag
& HBA_MENLO_SUPPORT
)) {
5064 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5065 "2786 Adapter does not support menlo "
5071 menlo_cmd
= (struct menlo_command
*)
5072 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
5074 /* allocate our bsg tracking structure */
5075 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
5077 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5078 "2787 Failed allocation of dd_data\n");
5083 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5089 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
5095 INIT_LIST_HEAD(&bmp
->list
);
5097 bpl
= (struct ulp_bde64
*)bmp
->virt
;
5098 request_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
);
5099 cmp
= lpfc_alloc_bsg_buffers(phba
, job
->request_payload
.payload_len
,
5100 1, bpl
, &request_nseg
);
5105 lpfc_bsg_copy_data(cmp
, &job
->request_payload
,
5106 job
->request_payload
.payload_len
, 1);
5108 bpl
+= request_nseg
;
5109 reply_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
) - request_nseg
;
5110 rmp
= lpfc_alloc_bsg_buffers(phba
, job
->reply_payload
.payload_len
, 0,
5117 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
5123 cmd
= &cmdiocbq
->iocb
;
5124 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
5125 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
5126 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
5127 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
5128 cmd
->un
.genreq64
.bdl
.bdeSize
=
5129 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
5130 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
5131 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
5132 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CMD
;
5133 cmd
->un
.genreq64
.w5
.hcsw
.Type
= MENLO_TRANSPORT_TYPE
; /* 0xfe */
5134 cmd
->ulpBdeCount
= 1;
5135 cmd
->ulpClass
= CLASS3
;
5136 cmd
->ulpOwner
= OWN_CHIP
;
5137 cmd
->ulpLe
= 1; /* Limited Edition */
5138 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
5139 cmdiocbq
->vport
= phba
->pport
;
5140 /* We want the firmware to timeout before we do */
5141 cmd
->ulpTimeout
= MENLO_TIMEOUT
- 5;
5142 cmdiocbq
->iocb_cmpl
= lpfc_bsg_menlo_cmd_cmp
;
5143 cmdiocbq
->context1
= dd_data
;
5144 cmdiocbq
->context2
= cmp
;
5145 cmdiocbq
->context3
= bmp
;
5146 if (menlo_cmd
->cmd
== LPFC_BSG_VENDOR_MENLO_CMD
) {
5147 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
5148 cmd
->ulpPU
= MENLO_PU
; /* 3 */
5149 cmd
->un
.ulpWord
[4] = MENLO_DID
; /* 0x0000FC0E */
5150 cmd
->ulpContext
= MENLO_CONTEXT
; /* 0 */
5152 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CX
;
5154 cmd
->un
.ulpWord
[4] = 0;
5155 cmd
->ulpContext
= menlo_cmd
->xri
;
5158 dd_data
->type
= TYPE_MENLO
;
5159 dd_data
->set_job
= job
;
5160 dd_data
->context_un
.menlo
.cmdiocbq
= cmdiocbq
;
5161 dd_data
->context_un
.menlo
.rmp
= rmp
;
5162 job
->dd_data
= dd_data
;
5164 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
5166 if (rc
== IOCB_SUCCESS
)
5167 return 0; /* done for now */
5169 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
5172 lpfc_free_bsg_buffers(phba
, rmp
);
5174 lpfc_free_bsg_buffers(phba
, cmp
);
5177 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
5182 /* make error code available to userspace */
5183 job
->reply
->result
= rc
;
5184 job
->dd_data
= NULL
;
5189 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
5190 * @job: fc_bsg_job to handle
5193 lpfc_bsg_hst_vendor(struct fc_bsg_job
*job
)
5195 int command
= job
->request
->rqst_data
.h_vendor
.vendor_cmd
[0];
5199 case LPFC_BSG_VENDOR_SET_CT_EVENT
:
5200 rc
= lpfc_bsg_hba_set_event(job
);
5202 case LPFC_BSG_VENDOR_GET_CT_EVENT
:
5203 rc
= lpfc_bsg_hba_get_event(job
);
5205 case LPFC_BSG_VENDOR_SEND_MGMT_RESP
:
5206 rc
= lpfc_bsg_send_mgmt_rsp(job
);
5208 case LPFC_BSG_VENDOR_DIAG_MODE
:
5209 rc
= lpfc_bsg_diag_loopback_mode(job
);
5211 case LPFC_BSG_VENDOR_DIAG_MODE_END
:
5212 rc
= lpfc_sli4_bsg_diag_mode_end(job
);
5214 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK
:
5215 rc
= lpfc_bsg_diag_loopback_run(job
);
5217 case LPFC_BSG_VENDOR_LINK_DIAG_TEST
:
5218 rc
= lpfc_sli4_bsg_link_diag_test(job
);
5220 case LPFC_BSG_VENDOR_GET_MGMT_REV
:
5221 rc
= lpfc_bsg_get_dfc_rev(job
);
5223 case LPFC_BSG_VENDOR_MBOX
:
5224 rc
= lpfc_bsg_mbox_cmd(job
);
5226 case LPFC_BSG_VENDOR_MENLO_CMD
:
5227 case LPFC_BSG_VENDOR_MENLO_DATA
:
5228 rc
= lpfc_menlo_cmd(job
);
5232 job
->reply
->reply_payload_rcv_len
= 0;
5233 /* make error code available to userspace */
5234 job
->reply
->result
= rc
;
5242 * lpfc_bsg_request - handle a bsg request from the FC transport
5243 * @job: fc_bsg_job to handle
5246 lpfc_bsg_request(struct fc_bsg_job
*job
)
5251 msgcode
= job
->request
->msgcode
;
5253 case FC_BSG_HST_VENDOR
:
5254 rc
= lpfc_bsg_hst_vendor(job
);
5256 case FC_BSG_RPT_ELS
:
5257 rc
= lpfc_bsg_rport_els(job
);
5260 rc
= lpfc_bsg_send_mgmt_cmd(job
);
5264 job
->reply
->reply_payload_rcv_len
= 0;
5265 /* make error code available to userspace */
5266 job
->reply
->result
= rc
;
5274 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
5275 * @job: fc_bsg_job that has timed out
5277 * This function just aborts the job's IOCB. The aborted IOCB will return to
5278 * the waiting function which will handle passing the error back to userspace
5281 lpfc_bsg_timeout(struct fc_bsg_job
*job
)
5283 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
5284 struct lpfc_hba
*phba
= vport
->phba
;
5285 struct lpfc_iocbq
*cmdiocb
;
5286 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5287 struct bsg_job_data
*dd_data
;
5288 unsigned long flags
;
5290 LIST_HEAD(completions
);
5291 struct lpfc_iocbq
*check_iocb
, *next_iocb
;
5293 /* if job's driver data is NULL, the command completed or is in the
5294 * the process of completing. In this case, return status to request
5295 * so the timeout is retried. This avoids double completion issues
5296 * and the request will be pulled off the timer queue when the
5297 * command's completion handler executes. Otherwise, prevent the
5298 * command's completion handler from executing the job done callback
5299 * and continue processing to abort the outstanding the command.
5302 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
5303 dd_data
= (struct bsg_job_data
*)job
->dd_data
;
5305 dd_data
->set_job
= NULL
;
5306 job
->dd_data
= NULL
;
5308 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5312 switch (dd_data
->type
) {
5314 /* Check to see if IOCB was issued to the port or not. If not,
5315 * remove it from the txq queue and call cancel iocbs.
5316 * Otherwise, call abort iotag
5318 cmdiocb
= dd_data
->context_un
.iocb
.cmdiocbq
;
5319 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5321 spin_lock_irqsave(&phba
->hbalock
, flags
);
5322 /* make sure the I/O abort window is still open */
5323 if (!(cmdiocb
->iocb_flag
& LPFC_IO_CMD_OUTSTANDING
)) {
5324 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5327 list_for_each_entry_safe(check_iocb
, next_iocb
, &pring
->txq
,
5329 if (check_iocb
== cmdiocb
) {
5330 list_move_tail(&check_iocb
->list
, &completions
);
5334 if (list_empty(&completions
))
5335 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5336 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5337 if (!list_empty(&completions
)) {
5338 lpfc_sli_cancel_iocbs(phba
, &completions
,
5339 IOSTAT_LOCAL_REJECT
,
5345 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5349 /* Update the ext buf ctx state if needed */
5351 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
5352 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
5353 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5356 /* Check to see if IOCB was issued to the port or not. If not,
5357 * remove it from the txq queue and call cancel iocbs.
5358 * Otherwise, call abort iotag.
5360 cmdiocb
= dd_data
->context_un
.menlo
.cmdiocbq
;
5361 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5363 spin_lock_irqsave(&phba
->hbalock
, flags
);
5364 list_for_each_entry_safe(check_iocb
, next_iocb
, &pring
->txq
,
5366 if (check_iocb
== cmdiocb
) {
5367 list_move_tail(&check_iocb
->list
, &completions
);
5371 if (list_empty(&completions
))
5372 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5373 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5374 if (!list_empty(&completions
)) {
5375 lpfc_sli_cancel_iocbs(phba
, &completions
,
5376 IOSTAT_LOCAL_REJECT
,
5381 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5385 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
5386 * otherwise an error message will be displayed on the console
5387 * so always return success (zero)