1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2009-2015 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
23 #include <linux/interrupt.h>
24 #include <linux/mempool.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
28 #include <linux/list.h>
29 #include <linux/bsg-lib.h>
30 #include <linux/vmalloc.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_transport_fc.h>
35 #include <scsi/scsi_bsg_fc.h>
36 #include <scsi/fc/fc_fs.h>
41 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
45 #include "lpfc_scsi.h"
47 #include "lpfc_logmsg.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_debugfs.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_version.h"
53 struct lpfc_bsg_event
{
54 struct list_head node
;
58 /* Event type and waiter identifiers */
63 /* next two flags are here for the auto-delete logic */
64 unsigned long wait_time_stamp
;
67 /* seen and not seen events */
68 struct list_head events_to_get
;
69 struct list_head events_to_see
;
71 /* driver data associated with the job */
75 struct lpfc_bsg_iocb
{
76 struct lpfc_iocbq
*cmdiocbq
;
77 struct lpfc_dmabuf
*rmp
;
78 struct lpfc_nodelist
*ndlp
;
81 struct lpfc_bsg_mbox
{
84 struct lpfc_dmabuf
*dmabuffers
; /* for BIU diags */
85 uint8_t *ext
; /* extended mailbox data */
86 uint32_t mbOffset
; /* from app */
87 uint32_t inExtWLen
; /* from app */
88 uint32_t outExtWLen
; /* from app */
91 #define MENLO_DID 0x0000FC0E
93 struct lpfc_bsg_menlo
{
94 struct lpfc_iocbq
*cmdiocbq
;
95 struct lpfc_dmabuf
*rmp
;
102 struct bsg_job_data
{
104 struct bsg_job
*set_job
; /* job waiting for this iocb to finish */
106 struct lpfc_bsg_event
*evt
;
107 struct lpfc_bsg_iocb iocb
;
108 struct lpfc_bsg_mbox mbox
;
109 struct lpfc_bsg_menlo menlo
;
114 struct list_head node
;
121 #define BUF_SZ_4K 4096
122 #define SLI_CT_ELX_LOOPBACK 0x10
124 enum ELX_LOOPBACK_CMD
{
125 ELX_LOOPBACK_XRI_SETUP
,
129 #define ELX_LOOPBACK_HEADER_SZ \
130 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
132 struct lpfc_dmabufext
{
133 struct lpfc_dmabuf dma
;
139 lpfc_free_bsg_buffers(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*mlist
)
141 struct lpfc_dmabuf
*mlast
, *next_mlast
;
144 list_for_each_entry_safe(mlast
, next_mlast
, &mlist
->list
,
146 lpfc_mbuf_free(phba
, mlast
->virt
, mlast
->phys
);
147 list_del(&mlast
->list
);
150 lpfc_mbuf_free(phba
, mlist
->virt
, mlist
->phys
);
156 static struct lpfc_dmabuf
*
157 lpfc_alloc_bsg_buffers(struct lpfc_hba
*phba
, unsigned int size
,
158 int outbound_buffers
, struct ulp_bde64
*bpl
,
161 struct lpfc_dmabuf
*mlist
= NULL
;
162 struct lpfc_dmabuf
*mp
;
163 unsigned int bytes_left
= size
;
165 /* Verify we can support the size specified */
166 if (!size
|| (size
> (*bpl_entries
* LPFC_BPL_SIZE
)))
169 /* Determine the number of dma buffers to allocate */
170 *bpl_entries
= (size
% LPFC_BPL_SIZE
? size
/LPFC_BPL_SIZE
+ 1 :
173 /* Allocate dma buffer and place in BPL passed */
175 /* Allocate dma buffer */
176 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
179 lpfc_free_bsg_buffers(phba
, mlist
);
183 INIT_LIST_HEAD(&mp
->list
);
184 mp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &(mp
->phys
));
189 lpfc_free_bsg_buffers(phba
, mlist
);
193 /* Queue it to a linked list */
197 list_add_tail(&mp
->list
, &mlist
->list
);
199 /* Add buffer to buffer pointer list */
200 if (outbound_buffers
)
201 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
203 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
204 bpl
->addrLow
= le32_to_cpu(putPaddrLow(mp
->phys
));
205 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(mp
->phys
));
206 bpl
->tus
.f
.bdeSize
= (uint16_t)
207 (bytes_left
>= LPFC_BPL_SIZE
? LPFC_BPL_SIZE
:
209 bytes_left
-= bpl
->tus
.f
.bdeSize
;
210 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
217 lpfc_bsg_copy_data(struct lpfc_dmabuf
*dma_buffers
,
218 struct bsg_buffer
*bsg_buffers
,
219 unsigned int bytes_to_transfer
, int to_buffers
)
222 struct lpfc_dmabuf
*mp
;
223 unsigned int transfer_bytes
, bytes_copied
= 0;
224 unsigned int sg_offset
, dma_offset
;
225 unsigned char *dma_address
, *sg_address
;
226 LIST_HEAD(temp_list
);
227 struct sg_mapping_iter miter
;
229 unsigned int sg_flags
= SG_MITER_ATOMIC
;
232 list_splice_init(&dma_buffers
->list
, &temp_list
);
233 list_add(&dma_buffers
->list
, &temp_list
);
236 sg_flags
|= SG_MITER_FROM_SG
;
238 sg_flags
|= SG_MITER_TO_SG
;
239 sg_miter_start(&miter
, bsg_buffers
->sg_list
, bsg_buffers
->sg_cnt
,
241 local_irq_save(flags
);
242 sg_valid
= sg_miter_next(&miter
);
243 list_for_each_entry(mp
, &temp_list
, list
) {
245 while (bytes_to_transfer
&& sg_valid
&&
246 (dma_offset
< LPFC_BPL_SIZE
)) {
247 dma_address
= mp
->virt
+ dma_offset
;
249 /* Continue previous partial transfer of sg */
250 sg_address
= miter
.addr
+ sg_offset
;
251 transfer_bytes
= miter
.length
- sg_offset
;
253 sg_address
= miter
.addr
;
254 transfer_bytes
= miter
.length
;
256 if (bytes_to_transfer
< transfer_bytes
)
257 transfer_bytes
= bytes_to_transfer
;
258 if (transfer_bytes
> (LPFC_BPL_SIZE
- dma_offset
))
259 transfer_bytes
= LPFC_BPL_SIZE
- dma_offset
;
261 memcpy(dma_address
, sg_address
, transfer_bytes
);
263 memcpy(sg_address
, dma_address
, transfer_bytes
);
264 dma_offset
+= transfer_bytes
;
265 sg_offset
+= transfer_bytes
;
266 bytes_to_transfer
-= transfer_bytes
;
267 bytes_copied
+= transfer_bytes
;
268 if (sg_offset
>= miter
.length
) {
270 sg_valid
= sg_miter_next(&miter
);
274 sg_miter_stop(&miter
);
275 local_irq_restore(flags
);
276 list_del_init(&dma_buffers
->list
);
277 list_splice(&temp_list
, &dma_buffers
->list
);
282 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
283 * @phba: Pointer to HBA context object.
284 * @cmdiocbq: Pointer to command iocb.
285 * @rspiocbq: Pointer to response iocb.
287 * This function is the completion handler for iocbs issued using
288 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
289 * ring event handler function without any lock held. This function
290 * can be called from both worker thread context and interrupt
291 * context. This function also can be called from another thread which
292 * cleans up the SLI layer objects.
293 * This function copies the contents of the response iocb to the
294 * response iocb memory object provided by the caller of
295 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
296 * sleeps for the iocb completion.
299 lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba
*phba
,
300 struct lpfc_iocbq
*cmdiocbq
,
301 struct lpfc_iocbq
*rspiocbq
)
303 struct bsg_job_data
*dd_data
;
305 struct fc_bsg_reply
*bsg_reply
;
307 struct lpfc_dmabuf
*bmp
, *cmp
, *rmp
;
308 struct lpfc_nodelist
*ndlp
;
309 struct lpfc_bsg_iocb
*iocb
;
311 unsigned int rsp_size
;
314 dd_data
= cmdiocbq
->context1
;
316 /* Determine if job has been aborted */
317 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
318 job
= dd_data
->set_job
;
320 bsg_reply
= job
->reply
;
321 /* Prevent timeout handling from trying to abort job */
324 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
326 /* Close the timeout handler abort window */
327 spin_lock_irqsave(&phba
->hbalock
, flags
);
328 cmdiocbq
->iocb_flag
&= ~LPFC_IO_CMD_OUTSTANDING
;
329 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
331 iocb
= &dd_data
->context_un
.iocb
;
334 cmp
= cmdiocbq
->context2
;
335 bmp
= cmdiocbq
->context3
;
336 rsp
= &rspiocbq
->iocb
;
338 /* Copy the completed data or set the error status */
341 if (rsp
->ulpStatus
) {
342 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
343 switch (rsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) {
344 case IOERR_SEQUENCE_TIMEOUT
:
347 case IOERR_INVALID_RPI
:
358 rsp_size
= rsp
->un
.genreq64
.bdl
.bdeSize
;
359 bsg_reply
->reply_payload_rcv_len
=
360 lpfc_bsg_copy_data(rmp
, &job
->reply_payload
,
365 lpfc_free_bsg_buffers(phba
, cmp
);
366 lpfc_free_bsg_buffers(phba
, rmp
);
367 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
369 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
373 /* Complete the job if the job is still active */
376 bsg_reply
->result
= rc
;
377 bsg_job_done(job
, bsg_reply
->result
,
378 bsg_reply
->reply_payload_rcv_len
);
384 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
385 * @job: fc_bsg_job to handle
388 lpfc_bsg_send_mgmt_cmd(struct bsg_job
*job
)
390 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
391 struct lpfc_hba
*phba
= vport
->phba
;
392 struct lpfc_rport_data
*rdata
= fc_bsg_to_rport(job
)->dd_data
;
393 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
394 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
395 struct ulp_bde64
*bpl
= NULL
;
397 struct lpfc_iocbq
*cmdiocbq
= NULL
;
399 struct lpfc_dmabuf
*bmp
= NULL
, *cmp
= NULL
, *rmp
= NULL
;
402 struct bsg_job_data
*dd_data
;
408 /* in case no data is transferred */
409 bsg_reply
->reply_payload_rcv_len
= 0;
411 /* allocate our bsg tracking structure */
412 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
414 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
415 "2733 Failed allocation of dd_data\n");
420 if (!lpfc_nlp_get(ndlp
)) {
425 if (ndlp
->nlp_flag
& NLP_ELS_SND_MASK
) {
430 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
436 cmd
= &cmdiocbq
->iocb
;
438 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
443 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
449 INIT_LIST_HEAD(&bmp
->list
);
451 bpl
= (struct ulp_bde64
*) bmp
->virt
;
452 request_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
);
453 cmp
= lpfc_alloc_bsg_buffers(phba
, job
->request_payload
.payload_len
,
454 1, bpl
, &request_nseg
);
459 lpfc_bsg_copy_data(cmp
, &job
->request_payload
,
460 job
->request_payload
.payload_len
, 1);
463 reply_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
) - request_nseg
;
464 rmp
= lpfc_alloc_bsg_buffers(phba
, job
->reply_payload
.payload_len
, 0,
471 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
472 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
473 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
474 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
475 cmd
->un
.genreq64
.bdl
.bdeSize
=
476 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
477 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
478 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
479 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
480 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
481 cmd
->un
.genreq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
482 cmd
->ulpBdeCount
= 1;
484 cmd
->ulpClass
= CLASS3
;
485 cmd
->ulpContext
= ndlp
->nlp_rpi
;
486 if (phba
->sli_rev
== LPFC_SLI_REV4
)
487 cmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
488 cmd
->ulpOwner
= OWN_CHIP
;
489 cmdiocbq
->vport
= phba
->pport
;
490 cmdiocbq
->context3
= bmp
;
491 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
492 timeout
= phba
->fc_ratov
* 2;
493 cmd
->ulpTimeout
= timeout
;
495 cmdiocbq
->iocb_cmpl
= lpfc_bsg_send_mgmt_cmd_cmp
;
496 cmdiocbq
->context1
= dd_data
;
497 cmdiocbq
->context2
= cmp
;
498 cmdiocbq
->context3
= bmp
;
499 cmdiocbq
->context_un
.ndlp
= ndlp
;
500 dd_data
->type
= TYPE_IOCB
;
501 dd_data
->set_job
= job
;
502 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
503 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
504 dd_data
->context_un
.iocb
.rmp
= rmp
;
505 job
->dd_data
= dd_data
;
507 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
508 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
512 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
513 writel(creg_val
, phba
->HCregaddr
);
514 readl(phba
->HCregaddr
); /* flush */
517 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
519 if (iocb_stat
== IOCB_SUCCESS
) {
520 spin_lock_irqsave(&phba
->hbalock
, flags
);
521 /* make sure the I/O had not been completed yet */
522 if (cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
523 /* open up abort window to timeout handler */
524 cmdiocbq
->iocb_flag
|= LPFC_IO_CMD_OUTSTANDING
;
526 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
527 return 0; /* done for now */
528 } else if (iocb_stat
== IOCB_BUSY
) {
534 /* iocb failed so cleanup */
538 lpfc_free_bsg_buffers(phba
, rmp
);
540 lpfc_free_bsg_buffers(phba
, cmp
);
543 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
546 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
552 /* make error code available to userspace */
553 bsg_reply
->result
= rc
;
559 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
560 * @phba: Pointer to HBA context object.
561 * @cmdiocbq: Pointer to command iocb.
562 * @rspiocbq: Pointer to response iocb.
564 * This function is the completion handler for iocbs issued using
565 * lpfc_bsg_rport_els_cmp function. This function is called by the
566 * ring event handler function without any lock held. This function
567 * can be called from both worker thread context and interrupt
568 * context. This function also can be called from other thread which
569 * cleans up the SLI layer objects.
570 * This function copies the contents of the response iocb to the
571 * response iocb memory object provided by the caller of
572 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
573 * sleeps for the iocb completion.
576 lpfc_bsg_rport_els_cmp(struct lpfc_hba
*phba
,
577 struct lpfc_iocbq
*cmdiocbq
,
578 struct lpfc_iocbq
*rspiocbq
)
580 struct bsg_job_data
*dd_data
;
582 struct fc_bsg_reply
*bsg_reply
;
584 struct lpfc_nodelist
*ndlp
;
585 struct lpfc_dmabuf
*pcmd
= NULL
, *prsp
= NULL
;
586 struct fc_bsg_ctels_reply
*els_reply
;
589 unsigned int rsp_size
;
592 dd_data
= cmdiocbq
->context1
;
593 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
594 cmdiocbq
->context1
= ndlp
;
596 /* Determine if job has been aborted */
597 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
598 job
= dd_data
->set_job
;
600 bsg_reply
= job
->reply
;
601 /* Prevent timeout handling from trying to abort job */
604 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
606 /* Close the timeout handler abort window */
607 spin_lock_irqsave(&phba
->hbalock
, flags
);
608 cmdiocbq
->iocb_flag
&= ~LPFC_IO_CMD_OUTSTANDING
;
609 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
611 rsp
= &rspiocbq
->iocb
;
612 pcmd
= (struct lpfc_dmabuf
*)cmdiocbq
->context2
;
613 prsp
= (struct lpfc_dmabuf
*)pcmd
->list
.next
;
615 /* Copy the completed job data or determine the job status if job is
620 if (rsp
->ulpStatus
== IOSTAT_SUCCESS
) {
621 rsp_size
= rsp
->un
.elsreq64
.bdl
.bdeSize
;
622 bsg_reply
->reply_payload_rcv_len
=
623 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
624 job
->reply_payload
.sg_cnt
,
627 } else if (rsp
->ulpStatus
== IOSTAT_LS_RJT
) {
628 bsg_reply
->reply_payload_rcv_len
=
629 sizeof(struct fc_bsg_ctels_reply
);
630 /* LS_RJT data returned in word 4 */
631 rjt_data
= (uint8_t *)&rsp
->un
.ulpWord
[4];
632 els_reply
= &bsg_reply
->reply_data
.ctels_reply
;
633 els_reply
->status
= FC_CTELS_STATUS_REJECT
;
634 els_reply
->rjt_data
.action
= rjt_data
[3];
635 els_reply
->rjt_data
.reason_code
= rjt_data
[2];
636 els_reply
->rjt_data
.reason_explanation
= rjt_data
[1];
637 els_reply
->rjt_data
.vendor_unique
= rjt_data
[0];
644 lpfc_els_free_iocb(phba
, cmdiocbq
);
647 /* Complete the job if the job is still active */
650 bsg_reply
->result
= rc
;
651 bsg_job_done(job
, bsg_reply
->result
,
652 bsg_reply
->reply_payload_rcv_len
);
658 * lpfc_bsg_rport_els - send an ELS command from a bsg request
659 * @job: fc_bsg_job to handle
662 lpfc_bsg_rport_els(struct bsg_job
*job
)
664 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
665 struct lpfc_hba
*phba
= vport
->phba
;
666 struct lpfc_rport_data
*rdata
= fc_bsg_to_rport(job
)->dd_data
;
667 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
668 struct fc_bsg_request
*bsg_request
= job
->request
;
669 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
672 struct lpfc_iocbq
*cmdiocbq
;
674 struct bsg_job_data
*dd_data
;
679 /* in case no data is transferred */
680 bsg_reply
->reply_payload_rcv_len
= 0;
682 /* verify the els command is not greater than the
683 * maximum ELS transfer size.
686 if (job
->request_payload
.payload_len
> FCELSSIZE
) {
691 /* allocate our bsg tracking structure */
692 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
694 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
695 "2735 Failed allocation of dd_data\n");
700 elscmd
= bsg_request
->rqst_data
.r_els
.els_code
;
701 cmdsize
= job
->request_payload
.payload_len
;
703 if (!lpfc_nlp_get(ndlp
)) {
708 /* We will use the allocated dma buffers by prep els iocb for command
709 * and response to ensure if the job times out and the request is freed,
710 * we won't be dma into memory that is no longer allocated to for the
714 cmdiocbq
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
,
715 ndlp
->nlp_DID
, elscmd
);
723 /* Transfer the request payload to allocated command dma buffer */
725 sg_copy_to_buffer(job
->request_payload
.sg_list
,
726 job
->request_payload
.sg_cnt
,
727 ((struct lpfc_dmabuf
*)cmdiocbq
->context2
)->virt
,
730 if (phba
->sli_rev
== LPFC_SLI_REV4
)
731 cmdiocbq
->iocb
.ulpContext
= phba
->sli4_hba
.rpi_ids
[rpi
];
733 cmdiocbq
->iocb
.ulpContext
= rpi
;
734 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
735 cmdiocbq
->context1
= dd_data
;
736 cmdiocbq
->context_un
.ndlp
= ndlp
;
737 cmdiocbq
->iocb_cmpl
= lpfc_bsg_rport_els_cmp
;
738 dd_data
->type
= TYPE_IOCB
;
739 dd_data
->set_job
= job
;
740 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
741 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
742 dd_data
->context_un
.iocb
.rmp
= NULL
;
743 job
->dd_data
= dd_data
;
745 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
746 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
750 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
751 writel(creg_val
, phba
->HCregaddr
);
752 readl(phba
->HCregaddr
); /* flush */
755 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
757 if (rc
== IOCB_SUCCESS
) {
758 spin_lock_irqsave(&phba
->hbalock
, flags
);
759 /* make sure the I/O had not been completed/released */
760 if (cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
761 /* open up abort window to timeout handler */
762 cmdiocbq
->iocb_flag
|= LPFC_IO_CMD_OUTSTANDING
;
764 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
765 return 0; /* done for now */
766 } else if (rc
== IOCB_BUSY
) {
772 /* iocb failed so cleanup */
776 cmdiocbq
->context1
= ndlp
;
777 lpfc_els_free_iocb(phba
, cmdiocbq
);
786 /* make error code available to userspace */
787 bsg_reply
->result
= rc
;
793 * lpfc_bsg_event_free - frees an allocated event structure
794 * @kref: Pointer to a kref.
796 * Called from kref_put. Back cast the kref into an event structure address.
797 * Free any events to get, delete associated nodes, free any events to see,
798 * free any data then free the event itself.
801 lpfc_bsg_event_free(struct kref
*kref
)
803 struct lpfc_bsg_event
*evt
= container_of(kref
, struct lpfc_bsg_event
,
805 struct event_data
*ed
;
807 list_del(&evt
->node
);
809 while (!list_empty(&evt
->events_to_get
)) {
810 ed
= list_entry(evt
->events_to_get
.next
, typeof(*ed
), node
);
816 while (!list_empty(&evt
->events_to_see
)) {
817 ed
= list_entry(evt
->events_to_see
.next
, typeof(*ed
), node
);
828 * lpfc_bsg_event_ref - increments the kref for an event
829 * @evt: Pointer to an event structure.
832 lpfc_bsg_event_ref(struct lpfc_bsg_event
*evt
)
834 kref_get(&evt
->kref
);
838 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
839 * @evt: Pointer to an event structure.
842 lpfc_bsg_event_unref(struct lpfc_bsg_event
*evt
)
844 kref_put(&evt
->kref
, lpfc_bsg_event_free
);
848 * lpfc_bsg_event_new - allocate and initialize a event structure
849 * @ev_mask: Mask of events.
850 * @ev_reg_id: Event reg id.
851 * @ev_req_id: Event request id.
853 static struct lpfc_bsg_event
*
854 lpfc_bsg_event_new(uint32_t ev_mask
, int ev_reg_id
, uint32_t ev_req_id
)
856 struct lpfc_bsg_event
*evt
= kzalloc(sizeof(*evt
), GFP_KERNEL
);
861 INIT_LIST_HEAD(&evt
->events_to_get
);
862 INIT_LIST_HEAD(&evt
->events_to_see
);
863 evt
->type_mask
= ev_mask
;
864 evt
->req_id
= ev_req_id
;
865 evt
->reg_id
= ev_reg_id
;
866 evt
->wait_time_stamp
= jiffies
;
868 init_waitqueue_head(&evt
->wq
);
869 kref_init(&evt
->kref
);
874 * diag_cmd_data_free - Frees an lpfc dma buffer extension
875 * @phba: Pointer to HBA context object.
876 * @mlist: Pointer to an lpfc dma buffer extension.
879 diag_cmd_data_free(struct lpfc_hba
*phba
, struct lpfc_dmabufext
*mlist
)
881 struct lpfc_dmabufext
*mlast
;
882 struct pci_dev
*pcidev
;
883 struct list_head head
, *curr
, *next
;
885 if ((!mlist
) || (!lpfc_is_link_up(phba
) &&
886 (phba
->link_flag
& LS_LOOPBACK_MODE
))) {
890 pcidev
= phba
->pcidev
;
891 list_add_tail(&head
, &mlist
->dma
.list
);
893 list_for_each_safe(curr
, next
, &head
) {
894 mlast
= list_entry(curr
, struct lpfc_dmabufext
, dma
.list
);
896 dma_free_coherent(&pcidev
->dev
,
906 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
911 * This function is called when an unsolicited CT command is received. It
912 * forwards the event to any processes registered to receive CT events.
915 lpfc_bsg_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
916 struct lpfc_iocbq
*piocbq
)
918 uint32_t evt_req_id
= 0;
920 struct lpfc_dmabuf
*dmabuf
= NULL
;
921 struct lpfc_bsg_event
*evt
;
922 struct event_data
*evt_dat
= NULL
;
923 struct lpfc_iocbq
*iocbq
;
925 struct list_head head
;
926 struct ulp_bde64
*bde
;
929 struct lpfc_dmabuf
*bdeBuf1
= piocbq
->context2
;
930 struct lpfc_dmabuf
*bdeBuf2
= piocbq
->context3
;
931 struct lpfc_hbq_entry
*hbqe
;
932 struct lpfc_sli_ct_request
*ct_req
;
933 struct bsg_job
*job
= NULL
;
934 struct fc_bsg_reply
*bsg_reply
;
935 struct bsg_job_data
*dd_data
= NULL
;
939 INIT_LIST_HEAD(&head
);
940 list_add_tail(&head
, &piocbq
->list
);
942 if (piocbq
->iocb
.ulpBdeCount
== 0 ||
943 piocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
== 0)
944 goto error_ct_unsol_exit
;
946 if (phba
->link_state
== LPFC_HBA_ERROR
||
947 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)))
948 goto error_ct_unsol_exit
;
950 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
953 dma_addr
= getPaddr(piocbq
->iocb
.un
.cont64
[0].addrHigh
,
954 piocbq
->iocb
.un
.cont64
[0].addrLow
);
955 dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
, dma_addr
);
958 goto error_ct_unsol_exit
;
959 ct_req
= (struct lpfc_sli_ct_request
*)dmabuf
->virt
;
960 evt_req_id
= ct_req
->FsType
;
961 cmd
= ct_req
->CommandResponse
.bits
.CmdRsp
;
962 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
963 lpfc_sli_ringpostbuf_put(phba
, pring
, dmabuf
);
965 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
966 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
967 if (!(evt
->type_mask
& FC_REG_CT_EVENT
) ||
968 evt
->req_id
!= evt_req_id
)
971 lpfc_bsg_event_ref(evt
);
972 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
973 evt_dat
= kzalloc(sizeof(*evt_dat
), GFP_KERNEL
);
974 if (evt_dat
== NULL
) {
975 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
976 lpfc_bsg_event_unref(evt
);
977 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
978 "2614 Memory allocation failed for "
983 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
984 /* take accumulated byte count from the last iocbq */
985 iocbq
= list_entry(head
.prev
, typeof(*iocbq
), list
);
986 evt_dat
->len
= iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
;
988 list_for_each_entry(iocbq
, &head
, list
) {
989 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++)
991 iocbq
->iocb
.un
.cont64
[i
].tus
.f
.bdeSize
;
995 evt_dat
->data
= kzalloc(evt_dat
->len
, GFP_KERNEL
);
996 if (evt_dat
->data
== NULL
) {
997 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
998 "2615 Memory allocation failed for "
999 "CT event data, size %d\n",
1002 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1003 lpfc_bsg_event_unref(evt
);
1004 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1005 goto error_ct_unsol_exit
;
1008 list_for_each_entry(iocbq
, &head
, list
) {
1010 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
1011 bdeBuf1
= iocbq
->context2
;
1012 bdeBuf2
= iocbq
->context3
;
1014 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++) {
1015 if (phba
->sli3_options
&
1016 LPFC_SLI3_HBQ_ENABLED
) {
1018 hbqe
= (struct lpfc_hbq_entry
*)
1019 &iocbq
->iocb
.un
.ulpWord
[0];
1020 size
= hbqe
->bde
.tus
.f
.bdeSize
;
1022 } else if (i
== 1) {
1023 hbqe
= (struct lpfc_hbq_entry
*)
1024 &iocbq
->iocb
.unsli3
.
1026 size
= hbqe
->bde
.tus
.f
.bdeSize
;
1029 if ((offset
+ size
) > evt_dat
->len
)
1030 size
= evt_dat
->len
- offset
;
1032 size
= iocbq
->iocb
.un
.cont64
[i
].
1034 bde
= &iocbq
->iocb
.un
.cont64
[i
];
1035 dma_addr
= getPaddr(bde
->addrHigh
,
1037 dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
1041 lpfc_printf_log(phba
, KERN_ERR
,
1042 LOG_LIBDFC
, "2616 No dmabuf "
1043 "found for iocbq x%px\n",
1045 kfree(evt_dat
->data
);
1047 spin_lock_irqsave(&phba
->ct_ev_lock
,
1049 lpfc_bsg_event_unref(evt
);
1050 spin_unlock_irqrestore(
1051 &phba
->ct_ev_lock
, flags
);
1052 goto error_ct_unsol_exit
;
1054 memcpy((char *)(evt_dat
->data
) + offset
,
1055 dmabuf
->virt
, size
);
1057 if (evt_req_id
!= SLI_CT_ELX_LOOPBACK
&&
1058 !(phba
->sli3_options
&
1059 LPFC_SLI3_HBQ_ENABLED
)) {
1060 lpfc_sli_ringpostbuf_put(phba
, pring
,
1064 case ELX_LOOPBACK_DATA
:
1067 diag_cmd_data_free(phba
,
1068 (struct lpfc_dmabufext
1071 case ELX_LOOPBACK_XRI_SETUP
:
1072 if ((phba
->sli_rev
==
1074 (phba
->sli3_options
&
1075 LPFC_SLI3_HBQ_ENABLED
1077 lpfc_in_buf_free(phba
,
1080 lpfc_post_buffer(phba
,
1086 if (!(phba
->sli3_options
&
1087 LPFC_SLI3_HBQ_ENABLED
))
1088 lpfc_post_buffer(phba
,
1097 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1098 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1099 evt_dat
->immed_dat
= phba
->ctx_idx
;
1100 phba
->ctx_idx
= (phba
->ctx_idx
+ 1) % LPFC_CT_CTX_MAX
;
1101 /* Provide warning for over-run of the ct_ctx array */
1102 if (phba
->ct_ctx
[evt_dat
->immed_dat
].valid
==
1104 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1105 "2717 CT context array entry "
1106 "[%d] over-run: oxid:x%x, "
1107 "sid:x%x\n", phba
->ctx_idx
,
1109 evt_dat
->immed_dat
].oxid
,
1111 evt_dat
->immed_dat
].SID
);
1112 phba
->ct_ctx
[evt_dat
->immed_dat
].rxid
=
1113 piocbq
->iocb
.ulpContext
;
1114 phba
->ct_ctx
[evt_dat
->immed_dat
].oxid
=
1115 piocbq
->iocb
.unsli3
.rcvsli3
.ox_id
;
1116 phba
->ct_ctx
[evt_dat
->immed_dat
].SID
=
1117 piocbq
->iocb
.un
.rcvels
.remoteID
;
1118 phba
->ct_ctx
[evt_dat
->immed_dat
].valid
= UNSOL_VALID
;
1120 evt_dat
->immed_dat
= piocbq
->iocb
.ulpContext
;
1122 evt_dat
->type
= FC_REG_CT_EVENT
;
1123 list_add(&evt_dat
->node
, &evt
->events_to_see
);
1124 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
) {
1125 wake_up_interruptible(&evt
->wq
);
1126 lpfc_bsg_event_unref(evt
);
1130 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
1132 dd_data
= (struct bsg_job_data
*)evt
->dd_data
;
1133 job
= dd_data
->set_job
;
1134 dd_data
->set_job
= NULL
;
1135 lpfc_bsg_event_unref(evt
);
1137 bsg_reply
= job
->reply
;
1138 bsg_reply
->reply_payload_rcv_len
= size
;
1139 /* make error code available to userspace */
1140 bsg_reply
->result
= 0;
1141 job
->dd_data
= NULL
;
1142 /* complete the job back to userspace */
1143 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1144 bsg_job_done(job
, bsg_reply
->result
,
1145 bsg_reply
->reply_payload_rcv_len
);
1146 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1149 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1151 error_ct_unsol_exit
:
1152 if (!list_empty(&head
))
1154 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
1155 (evt_req_id
== SLI_CT_ELX_LOOPBACK
))
1161 * lpfc_bsg_ct_unsol_abort - handler ct abort to management plane
1162 * @phba: Pointer to HBA context object.
1163 * @dmabuf: pointer to a dmabuf that describes the FC sequence
1165 * This function handles abort to the CT command toward management plane
1168 * If the pending context of a CT command to management plane present, clears
1169 * such context and returns 1 for handled; otherwise, it returns 0 indicating
1170 * no context exists.
1173 lpfc_bsg_ct_unsol_abort(struct lpfc_hba
*phba
, struct hbq_dmabuf
*dmabuf
)
1175 struct fc_frame_header fc_hdr
;
1176 struct fc_frame_header
*fc_hdr_ptr
= &fc_hdr
;
1177 int ctx_idx
, handled
= 0;
1178 uint16_t oxid
, rxid
;
1181 memcpy(fc_hdr_ptr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
1182 sid
= sli4_sid_from_fc_hdr(fc_hdr_ptr
);
1183 oxid
= be16_to_cpu(fc_hdr_ptr
->fh_ox_id
);
1184 rxid
= be16_to_cpu(fc_hdr_ptr
->fh_rx_id
);
1186 for (ctx_idx
= 0; ctx_idx
< LPFC_CT_CTX_MAX
; ctx_idx
++) {
1187 if (phba
->ct_ctx
[ctx_idx
].valid
!= UNSOL_VALID
)
1189 if (phba
->ct_ctx
[ctx_idx
].rxid
!= rxid
)
1191 if (phba
->ct_ctx
[ctx_idx
].oxid
!= oxid
)
1193 if (phba
->ct_ctx
[ctx_idx
].SID
!= sid
)
1195 phba
->ct_ctx
[ctx_idx
].valid
= UNSOL_INVALID
;
1202 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1203 * @job: SET_EVENT fc_bsg_job
1206 lpfc_bsg_hba_set_event(struct bsg_job
*job
)
1208 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
1209 struct lpfc_hba
*phba
= vport
->phba
;
1210 struct fc_bsg_request
*bsg_request
= job
->request
;
1211 struct set_ct_event
*event_req
;
1212 struct lpfc_bsg_event
*evt
;
1214 struct bsg_job_data
*dd_data
= NULL
;
1216 unsigned long flags
;
1218 if (job
->request_len
<
1219 sizeof(struct fc_bsg_request
) + sizeof(struct set_ct_event
)) {
1220 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1221 "2612 Received SET_CT_EVENT below minimum "
1227 event_req
= (struct set_ct_event
*)
1228 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
1229 ev_mask
= ((uint32_t)(unsigned long)event_req
->type_mask
&
1231 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1232 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1233 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1234 lpfc_bsg_event_ref(evt
);
1235 evt
->wait_time_stamp
= jiffies
;
1236 dd_data
= (struct bsg_job_data
*)evt
->dd_data
;
1240 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1242 if (&evt
->node
== &phba
->ct_ev_waiters
) {
1243 /* no event waiting struct yet - first call */
1244 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1245 if (dd_data
== NULL
) {
1246 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1247 "2734 Failed allocation of dd_data\n");
1251 evt
= lpfc_bsg_event_new(ev_mask
, event_req
->ev_reg_id
,
1252 event_req
->ev_req_id
);
1254 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1255 "2617 Failed allocation of event "
1260 dd_data
->type
= TYPE_EVT
;
1261 dd_data
->set_job
= NULL
;
1262 dd_data
->context_un
.evt
= evt
;
1263 evt
->dd_data
= (void *)dd_data
;
1264 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1265 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1266 lpfc_bsg_event_ref(evt
);
1267 evt
->wait_time_stamp
= jiffies
;
1268 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1271 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1273 dd_data
->set_job
= job
; /* for unsolicited command */
1274 job
->dd_data
= dd_data
; /* for fc transport timeout callback*/
1275 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1276 return 0; /* call job done later */
1280 job
->dd_data
= NULL
;
1285 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1286 * @job: GET_EVENT fc_bsg_job
1289 lpfc_bsg_hba_get_event(struct bsg_job
*job
)
1291 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
1292 struct lpfc_hba
*phba
= vport
->phba
;
1293 struct fc_bsg_request
*bsg_request
= job
->request
;
1294 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
1295 struct get_ct_event
*event_req
;
1296 struct get_ct_event_reply
*event_reply
;
1297 struct lpfc_bsg_event
*evt
, *evt_next
;
1298 struct event_data
*evt_dat
= NULL
;
1299 unsigned long flags
;
1302 if (job
->request_len
<
1303 sizeof(struct fc_bsg_request
) + sizeof(struct get_ct_event
)) {
1304 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1305 "2613 Received GET_CT_EVENT request below "
1311 event_req
= (struct get_ct_event
*)
1312 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
1314 event_reply
= (struct get_ct_event_reply
*)
1315 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
1316 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1317 list_for_each_entry_safe(evt
, evt_next
, &phba
->ct_ev_waiters
, node
) {
1318 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1319 if (list_empty(&evt
->events_to_get
))
1321 lpfc_bsg_event_ref(evt
);
1322 evt
->wait_time_stamp
= jiffies
;
1323 evt_dat
= list_entry(evt
->events_to_get
.prev
,
1324 struct event_data
, node
);
1325 list_del(&evt_dat
->node
);
1329 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1331 /* The app may continue to ask for event data until it gets
1332 * an error indicating that there isn't anymore
1334 if (evt_dat
== NULL
) {
1335 bsg_reply
->reply_payload_rcv_len
= 0;
1340 if (evt_dat
->len
> job
->request_payload
.payload_len
) {
1341 evt_dat
->len
= job
->request_payload
.payload_len
;
1342 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1343 "2618 Truncated event data at %d "
1345 job
->request_payload
.payload_len
);
1348 event_reply
->type
= evt_dat
->type
;
1349 event_reply
->immed_data
= evt_dat
->immed_dat
;
1350 if (evt_dat
->len
> 0)
1351 bsg_reply
->reply_payload_rcv_len
=
1352 sg_copy_from_buffer(job
->request_payload
.sg_list
,
1353 job
->request_payload
.sg_cnt
,
1354 evt_dat
->data
, evt_dat
->len
);
1356 bsg_reply
->reply_payload_rcv_len
= 0;
1359 kfree(evt_dat
->data
);
1363 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1364 lpfc_bsg_event_unref(evt
);
1365 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1366 job
->dd_data
= NULL
;
1367 bsg_reply
->result
= 0;
1368 bsg_job_done(job
, bsg_reply
->result
,
1369 bsg_reply
->reply_payload_rcv_len
);
1373 job
->dd_data
= NULL
;
1374 bsg_reply
->result
= rc
;
1379 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1380 * @phba: Pointer to HBA context object.
1381 * @cmdiocbq: Pointer to command iocb.
1382 * @rspiocbq: Pointer to response iocb.
1384 * This function is the completion handler for iocbs issued using
1385 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1386 * ring event handler function without any lock held. This function
1387 * can be called from both worker thread context and interrupt
1388 * context. This function also can be called from other thread which
1389 * cleans up the SLI layer objects.
1390 * This function copy the contents of the response iocb to the
1391 * response iocb memory object provided by the caller of
1392 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1393 * sleeps for the iocb completion.
1396 lpfc_issue_ct_rsp_cmp(struct lpfc_hba
*phba
,
1397 struct lpfc_iocbq
*cmdiocbq
,
1398 struct lpfc_iocbq
*rspiocbq
)
1400 struct bsg_job_data
*dd_data
;
1401 struct bsg_job
*job
;
1402 struct fc_bsg_reply
*bsg_reply
;
1404 struct lpfc_dmabuf
*bmp
, *cmp
;
1405 struct lpfc_nodelist
*ndlp
;
1406 unsigned long flags
;
1409 dd_data
= cmdiocbq
->context1
;
1411 /* Determine if job has been aborted */
1412 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1413 job
= dd_data
->set_job
;
1415 /* Prevent timeout handling from trying to abort job */
1416 job
->dd_data
= NULL
;
1418 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1420 /* Close the timeout handler abort window */
1421 spin_lock_irqsave(&phba
->hbalock
, flags
);
1422 cmdiocbq
->iocb_flag
&= ~LPFC_IO_CMD_OUTSTANDING
;
1423 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1425 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
1426 cmp
= cmdiocbq
->context2
;
1427 bmp
= cmdiocbq
->context3
;
1428 rsp
= &rspiocbq
->iocb
;
1430 /* Copy the completed job data or set the error status */
1433 bsg_reply
= job
->reply
;
1434 if (rsp
->ulpStatus
) {
1435 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1436 switch (rsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) {
1437 case IOERR_SEQUENCE_TIMEOUT
:
1440 case IOERR_INVALID_RPI
:
1451 bsg_reply
->reply_payload_rcv_len
= 0;
1455 lpfc_free_bsg_buffers(phba
, cmp
);
1456 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1458 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1462 /* Complete the job if the job is still active */
1465 bsg_reply
->result
= rc
;
1466 bsg_job_done(job
, bsg_reply
->result
,
1467 bsg_reply
->reply_payload_rcv_len
);
1473 * lpfc_issue_ct_rsp - issue a ct response
1474 * @phba: Pointer to HBA context object.
1475 * @job: Pointer to the job object.
1476 * @tag: tag index value into the ports context exchange array.
1477 * @bmp: Pointer to a dma buffer descriptor.
1478 * @num_entry: Number of enties in the bde.
1481 lpfc_issue_ct_rsp(struct lpfc_hba
*phba
, struct bsg_job
*job
, uint32_t tag
,
1482 struct lpfc_dmabuf
*cmp
, struct lpfc_dmabuf
*bmp
,
1486 struct lpfc_iocbq
*ctiocb
= NULL
;
1488 struct lpfc_nodelist
*ndlp
= NULL
;
1489 struct bsg_job_data
*dd_data
;
1490 unsigned long flags
;
1493 /* allocate our bsg tracking structure */
1494 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1496 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1497 "2736 Failed allocation of dd_data\n");
1502 /* Allocate buffer for command iocb */
1503 ctiocb
= lpfc_sli_get_iocbq(phba
);
1509 icmd
= &ctiocb
->iocb
;
1510 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
1511 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
1512 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
1513 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1514 icmd
->un
.xseq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
1515 icmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
1516 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1517 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_SOL_CTL
;
1518 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1520 /* Fill in rest of iocb */
1521 icmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
1522 icmd
->ulpBdeCount
= 1;
1524 icmd
->ulpClass
= CLASS3
;
1525 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1526 /* Do not issue unsol response if oxid not marked as valid */
1527 if (phba
->ct_ctx
[tag
].valid
!= UNSOL_VALID
) {
1529 goto issue_ct_rsp_exit
;
1531 icmd
->ulpContext
= phba
->ct_ctx
[tag
].rxid
;
1532 icmd
->unsli3
.rcvsli3
.ox_id
= phba
->ct_ctx
[tag
].oxid
;
1533 ndlp
= lpfc_findnode_did(phba
->pport
, phba
->ct_ctx
[tag
].SID
);
1535 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1536 "2721 ndlp null for oxid %x SID %x\n",
1538 phba
->ct_ctx
[tag
].SID
);
1540 goto issue_ct_rsp_exit
;
1543 /* Check if the ndlp is active */
1544 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1546 goto issue_ct_rsp_exit
;
1549 /* get a refernece count so the ndlp doesn't go away while
1552 if (!lpfc_nlp_get(ndlp
)) {
1554 goto issue_ct_rsp_exit
;
1557 icmd
->un
.ulpWord
[3] =
1558 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
1560 /* The exchange is done, mark the entry as invalid */
1561 phba
->ct_ctx
[tag
].valid
= UNSOL_INVALID
;
1563 icmd
->ulpContext
= (ushort
) tag
;
1565 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
1567 /* Xmit CT response on exchange <xid> */
1568 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1569 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1570 icmd
->ulpContext
, icmd
->ulpIoTag
, tag
, phba
->link_state
);
1572 ctiocb
->iocb_flag
|= LPFC_IO_LIBDFC
;
1573 ctiocb
->vport
= phba
->pport
;
1574 ctiocb
->context1
= dd_data
;
1575 ctiocb
->context2
= cmp
;
1576 ctiocb
->context3
= bmp
;
1577 ctiocb
->context_un
.ndlp
= ndlp
;
1578 ctiocb
->iocb_cmpl
= lpfc_issue_ct_rsp_cmp
;
1580 dd_data
->type
= TYPE_IOCB
;
1581 dd_data
->set_job
= job
;
1582 dd_data
->context_un
.iocb
.cmdiocbq
= ctiocb
;
1583 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
1584 dd_data
->context_un
.iocb
.rmp
= NULL
;
1585 job
->dd_data
= dd_data
;
1587 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1588 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1590 goto issue_ct_rsp_exit
;
1592 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1593 writel(creg_val
, phba
->HCregaddr
);
1594 readl(phba
->HCregaddr
); /* flush */
1597 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
1599 if (rc
== IOCB_SUCCESS
) {
1600 spin_lock_irqsave(&phba
->hbalock
, flags
);
1601 /* make sure the I/O had not been completed/released */
1602 if (ctiocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
1603 /* open up abort window to timeout handler */
1604 ctiocb
->iocb_flag
|= LPFC_IO_CMD_OUTSTANDING
;
1606 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1607 return 0; /* done for now */
1610 /* iocb failed so cleanup */
1611 job
->dd_data
= NULL
;
1614 lpfc_sli_release_iocbq(phba
, ctiocb
);
1622 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1623 * @job: SEND_MGMT_RESP fc_bsg_job
1626 lpfc_bsg_send_mgmt_rsp(struct bsg_job
*job
)
1628 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
1629 struct lpfc_hba
*phba
= vport
->phba
;
1630 struct fc_bsg_request
*bsg_request
= job
->request
;
1631 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
1632 struct send_mgmt_resp
*mgmt_resp
= (struct send_mgmt_resp
*)
1633 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
1634 struct ulp_bde64
*bpl
;
1635 struct lpfc_dmabuf
*bmp
= NULL
, *cmp
= NULL
;
1637 uint32_t tag
= mgmt_resp
->tag
;
1638 unsigned long reqbfrcnt
=
1639 (unsigned long)job
->request_payload
.payload_len
;
1642 /* in case no data is transferred */
1643 bsg_reply
->reply_payload_rcv_len
= 0;
1645 if (!reqbfrcnt
|| (reqbfrcnt
> (80 * BUF_SZ_4K
))) {
1647 goto send_mgmt_rsp_exit
;
1650 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1653 goto send_mgmt_rsp_exit
;
1656 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
1659 goto send_mgmt_rsp_free_bmp
;
1662 INIT_LIST_HEAD(&bmp
->list
);
1663 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1664 bpl_entries
= (LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
));
1665 cmp
= lpfc_alloc_bsg_buffers(phba
, job
->request_payload
.payload_len
,
1666 1, bpl
, &bpl_entries
);
1669 goto send_mgmt_rsp_free_bmp
;
1671 lpfc_bsg_copy_data(cmp
, &job
->request_payload
,
1672 job
->request_payload
.payload_len
, 1);
1674 rc
= lpfc_issue_ct_rsp(phba
, job
, tag
, cmp
, bmp
, bpl_entries
);
1676 if (rc
== IOCB_SUCCESS
)
1677 return 0; /* done for now */
1681 lpfc_free_bsg_buffers(phba
, cmp
);
1683 send_mgmt_rsp_free_bmp
:
1685 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1688 /* make error code available to userspace */
1689 bsg_reply
->result
= rc
;
1690 job
->dd_data
= NULL
;
1695 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1696 * @phba: Pointer to HBA context object.
1698 * This function is responsible for preparing driver for diag loopback
1702 lpfc_bsg_diag_mode_enter(struct lpfc_hba
*phba
)
1704 struct lpfc_vport
**vports
;
1705 struct Scsi_Host
*shost
;
1706 struct lpfc_sli
*psli
;
1707 struct lpfc_queue
*qp
= NULL
;
1708 struct lpfc_sli_ring
*pring
;
1716 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1717 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
1718 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
1721 vports
= lpfc_create_vport_work_array(phba
);
1723 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1724 shost
= lpfc_shost_from_vport(vports
[i
]);
1725 scsi_block_requests(shost
);
1727 lpfc_destroy_vport_work_array(phba
, vports
);
1729 shost
= lpfc_shost_from_vport(phba
->pport
);
1730 scsi_block_requests(shost
);
1733 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
1734 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
1735 lpfc_emptyq_wait(phba
, &pring
->txcmplq
, &phba
->hbalock
);
1738 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
1740 if (!pring
|| (pring
->ringno
!= LPFC_FCP_RING
))
1742 if (!lpfc_emptyq_wait(phba
, &pring
->txcmplq
,
1750 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1751 * @phba: Pointer to HBA context object.
1753 * This function is responsible for driver exit processing of setting up
1754 * diag loopback mode on device.
1757 lpfc_bsg_diag_mode_exit(struct lpfc_hba
*phba
)
1759 struct Scsi_Host
*shost
;
1760 struct lpfc_vport
**vports
;
1763 vports
= lpfc_create_vport_work_array(phba
);
1765 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1766 shost
= lpfc_shost_from_vport(vports
[i
]);
1767 scsi_unblock_requests(shost
);
1769 lpfc_destroy_vport_work_array(phba
, vports
);
1771 shost
= lpfc_shost_from_vport(phba
->pport
);
1772 scsi_unblock_requests(shost
);
1778 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1779 * @phba: Pointer to HBA context object.
1780 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1782 * This function is responsible for placing an sli3 port into diagnostic
1783 * loopback mode in order to perform a diagnostic loopback test.
1784 * All new scsi requests are blocked, a small delay is used to allow the
1785 * scsi requests to complete then the link is brought down. If the link is
1786 * is placed in loopback mode then scsi requests are again allowed
1787 * so the scsi mid-layer doesn't give up on the port.
1788 * All of this is done in-line.
1791 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct bsg_job
*job
)
1793 struct fc_bsg_request
*bsg_request
= job
->request
;
1794 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
1795 struct diag_mode_set
*loopback_mode
;
1796 uint32_t link_flags
;
1798 LPFC_MBOXQ_t
*pmboxq
= NULL
;
1799 int mbxstatus
= MBX_SUCCESS
;
1803 /* no data to return just the return code */
1804 bsg_reply
->reply_payload_rcv_len
= 0;
1806 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1807 sizeof(struct diag_mode_set
)) {
1808 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1809 "2738 Received DIAG MODE request size:%d "
1810 "below the minimum size:%d\n",
1812 (int)(sizeof(struct fc_bsg_request
) +
1813 sizeof(struct diag_mode_set
)));
1818 rc
= lpfc_bsg_diag_mode_enter(phba
);
1822 /* bring the link to diagnostic mode */
1823 loopback_mode
= (struct diag_mode_set
*)
1824 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
1825 link_flags
= loopback_mode
->type
;
1826 timeout
= loopback_mode
->timeout
* 100;
1828 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1831 goto loopback_mode_exit
;
1833 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1834 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1835 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1837 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1839 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0)) {
1840 /* wait for link down before proceeding */
1842 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1843 if (i
++ > timeout
) {
1845 goto loopback_mode_exit
;
1850 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1851 if (link_flags
== INTERNAL_LOOP_BACK
)
1852 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
1854 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
=
1855 FLAGS_TOPOLOGY_MODE_LOOP
;
1857 pmboxq
->u
.mb
.mbxCommand
= MBX_INIT_LINK
;
1858 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1860 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1863 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1866 spin_lock_irq(&phba
->hbalock
);
1867 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1868 spin_unlock_irq(&phba
->hbalock
);
1869 /* wait for the link attention interrupt */
1873 while (phba
->link_state
!= LPFC_HBA_READY
) {
1874 if (i
++ > timeout
) {
1887 lpfc_bsg_diag_mode_exit(phba
);
1890 * Let SLI layer release mboxq if mbox command completed after timeout.
1892 if (pmboxq
&& mbxstatus
!= MBX_TIMEOUT
)
1893 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1896 /* make error code available to userspace */
1897 bsg_reply
->result
= rc
;
1898 /* complete the job back to userspace if no error */
1900 bsg_job_done(job
, bsg_reply
->result
,
1901 bsg_reply
->reply_payload_rcv_len
);
1906 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1907 * @phba: Pointer to HBA context object.
1908 * @diag: Flag for set link to diag or nomral operation state.
1910 * This function is responsible for issuing a sli4 mailbox command for setting
1911 * link to either diag state or normal operation state.
1914 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba
*phba
, uint32_t diag
)
1916 LPFC_MBOXQ_t
*pmboxq
;
1917 struct lpfc_mbx_set_link_diag_state
*link_diag_state
;
1918 uint32_t req_len
, alloc_len
;
1919 int mbxstatus
= MBX_SUCCESS
, rc
;
1921 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1925 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
1926 sizeof(struct lpfc_sli4_cfg_mhdr
));
1927 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1928 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
1929 req_len
, LPFC_SLI4_MBX_EMBED
);
1930 if (alloc_len
!= req_len
) {
1932 goto link_diag_state_set_out
;
1934 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1935 "3128 Set link to diagnostic state:x%x (x%x/x%x)\n",
1936 diag
, phba
->sli4_hba
.lnk_info
.lnk_tp
,
1937 phba
->sli4_hba
.lnk_info
.lnk_no
);
1939 link_diag_state
= &pmboxq
->u
.mqe
.un
.link_diag_state
;
1940 bf_set(lpfc_mbx_set_diag_state_diag_bit_valid
, &link_diag_state
->u
.req
,
1941 LPFC_DIAG_STATE_DIAG_BIT_VALID_CHANGE
);
1942 bf_set(lpfc_mbx_set_diag_state_link_num
, &link_diag_state
->u
.req
,
1943 phba
->sli4_hba
.lnk_info
.lnk_no
);
1944 bf_set(lpfc_mbx_set_diag_state_link_type
, &link_diag_state
->u
.req
,
1945 phba
->sli4_hba
.lnk_info
.lnk_tp
);
1947 bf_set(lpfc_mbx_set_diag_state_diag
,
1948 &link_diag_state
->u
.req
, 1);
1950 bf_set(lpfc_mbx_set_diag_state_diag
,
1951 &link_diag_state
->u
.req
, 0);
1953 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1955 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0))
1960 link_diag_state_set_out
:
1961 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1962 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1968 * lpfc_sli4_bsg_set_loopback_mode - set sli4 internal loopback diagnostic
1969 * @phba: Pointer to HBA context object.
1970 * @mode: loopback mode to set
1971 * @link_no: link number for loopback mode to set
1973 * This function is responsible for issuing a sli4 mailbox command for setting
1974 * up loopback diagnostic for a link.
1977 lpfc_sli4_bsg_set_loopback_mode(struct lpfc_hba
*phba
, int mode
,
1980 LPFC_MBOXQ_t
*pmboxq
;
1981 uint32_t req_len
, alloc_len
;
1982 struct lpfc_mbx_set_link_diag_loopback
*link_diag_loopback
;
1983 int mbxstatus
= MBX_SUCCESS
, rc
= 0;
1985 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1988 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_loopback
) -
1989 sizeof(struct lpfc_sli4_cfg_mhdr
));
1990 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1991 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK
,
1992 req_len
, LPFC_SLI4_MBX_EMBED
);
1993 if (alloc_len
!= req_len
) {
1994 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1997 link_diag_loopback
= &pmboxq
->u
.mqe
.un
.link_diag_loopback
;
1998 bf_set(lpfc_mbx_set_diag_state_link_num
,
1999 &link_diag_loopback
->u
.req
, link_no
);
2001 if (phba
->sli4_hba
.conf_trunk
& (1 << link_no
)) {
2002 bf_set(lpfc_mbx_set_diag_state_link_type
,
2003 &link_diag_loopback
->u
.req
, LPFC_LNK_FC_TRUNKED
);
2005 bf_set(lpfc_mbx_set_diag_state_link_type
,
2006 &link_diag_loopback
->u
.req
,
2007 phba
->sli4_hba
.lnk_info
.lnk_tp
);
2010 bf_set(lpfc_mbx_set_diag_lpbk_type
, &link_diag_loopback
->u
.req
,
2013 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
2014 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
)) {
2015 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2016 "3127 Failed setup loopback mode mailbox "
2017 "command, rc:x%x, status:x%x\n", mbxstatus
,
2018 pmboxq
->u
.mb
.mbxStatus
);
2021 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
2022 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2027 * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic
2028 * @phba: Pointer to HBA context object.
2030 * This function set up SLI4 FC port registrations for diagnostic run, which
2031 * includes all the rpis, vfi, and also vpi.
2034 lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba
*phba
)
2038 if (phba
->pport
->fc_flag
& FC_VFI_REGISTERED
) {
2039 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2040 "3136 Port still had vfi registered: "
2041 "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
2042 phba
->pport
->fc_myDID
, phba
->fcf
.fcfi
,
2043 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
],
2044 phba
->vpi_ids
[phba
->pport
->vpi
]);
2047 rc
= lpfc_issue_reg_vfi(phba
->pport
);
2052 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
2053 * @phba: Pointer to HBA context object.
2054 * @job: LPFC_BSG_VENDOR_DIAG_MODE
2056 * This function is responsible for placing an sli4 port into diagnostic
2057 * loopback mode in order to perform a diagnostic loopback test.
2060 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct bsg_job
*job
)
2062 struct fc_bsg_request
*bsg_request
= job
->request
;
2063 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
2064 struct diag_mode_set
*loopback_mode
;
2065 uint32_t link_flags
, timeout
, link_no
;
2068 /* no data to return just the return code */
2069 bsg_reply
->reply_payload_rcv_len
= 0;
2071 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
2072 sizeof(struct diag_mode_set
)) {
2073 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2074 "3011 Received DIAG MODE request size:%d "
2075 "below the minimum size:%d\n",
2077 (int)(sizeof(struct fc_bsg_request
) +
2078 sizeof(struct diag_mode_set
)));
2083 loopback_mode
= (struct diag_mode_set
*)
2084 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
2085 link_flags
= loopback_mode
->type
;
2086 timeout
= loopback_mode
->timeout
* 100;
2088 if (loopback_mode
->physical_link
== -1)
2089 link_no
= phba
->sli4_hba
.lnk_info
.lnk_no
;
2091 link_no
= loopback_mode
->physical_link
;
2093 if (link_flags
== DISABLE_LOOP_BACK
) {
2094 rc
= lpfc_sli4_bsg_set_loopback_mode(phba
,
2095 LPFC_DIAG_LOOPBACK_TYPE_DISABLE
,
2098 /* Unset the need disable bit */
2099 phba
->sli4_hba
.conf_trunk
&= ~((1 << link_no
) << 4);
2103 /* Check if we need to disable the loopback state */
2104 if (phba
->sli4_hba
.conf_trunk
& ((1 << link_no
) << 4)) {
2110 rc
= lpfc_bsg_diag_mode_enter(phba
);
2114 /* indicate we are in loobpack diagnostic mode */
2115 spin_lock_irq(&phba
->hbalock
);
2116 phba
->link_flag
|= LS_LOOPBACK_MODE
;
2117 spin_unlock_irq(&phba
->hbalock
);
2119 /* reset port to start frome scratch */
2120 rc
= lpfc_selective_reset(phba
);
2124 /* bring the link to diagnostic mode */
2125 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2126 "3129 Bring link to diagnostic state.\n");
2128 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
2130 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2131 "3130 Failed to bring link to diagnostic "
2132 "state, rc:x%x\n", rc
);
2133 goto loopback_mode_exit
;
2136 /* wait for link down before proceeding */
2138 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
2139 if (i
++ > timeout
) {
2141 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2142 "3131 Timeout waiting for link to "
2143 "diagnostic mode, timeout:%d ms\n",
2145 goto loopback_mode_exit
;
2150 /* set up loopback mode */
2151 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2152 "3132 Set up loopback mode:x%x\n", link_flags
);
2154 switch (link_flags
) {
2155 case INTERNAL_LOOP_BACK
:
2156 if (phba
->sli4_hba
.conf_trunk
& (1 << link_no
)) {
2157 rc
= lpfc_sli4_bsg_set_loopback_mode(phba
,
2158 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL
,
2161 /* Trunk is configured, but link is not in this trunk */
2162 if (phba
->sli4_hba
.conf_trunk
) {
2164 goto loopback_mode_exit
;
2167 rc
= lpfc_sli4_bsg_set_loopback_mode(phba
,
2168 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL
,
2173 /* Set the need disable bit */
2174 phba
->sli4_hba
.conf_trunk
|= (1 << link_no
) << 4;
2178 case EXTERNAL_LOOP_BACK
:
2179 if (phba
->sli4_hba
.conf_trunk
& (1 << link_no
)) {
2180 rc
= lpfc_sli4_bsg_set_loopback_mode(phba
,
2181 LPFC_DIAG_LOOPBACK_TYPE_EXTERNAL_TRUNKED
,
2184 /* Trunk is configured, but link is not in this trunk */
2185 if (phba
->sli4_hba
.conf_trunk
) {
2187 goto loopback_mode_exit
;
2190 rc
= lpfc_sli4_bsg_set_loopback_mode(phba
,
2191 LPFC_DIAG_LOOPBACK_TYPE_SERDES
,
2196 /* Set the need disable bit */
2197 phba
->sli4_hba
.conf_trunk
|= (1 << link_no
) << 4;
2203 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2204 "3141 Loopback mode:x%x not supported\n",
2206 goto loopback_mode_exit
;
2210 /* wait for the link attention interrupt */
2213 while (phba
->link_state
< LPFC_LINK_UP
) {
2214 if (i
++ > timeout
) {
2216 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2217 "3137 Timeout waiting for link up "
2218 "in loopback mode, timeout:%d ms\n",
2226 /* port resource registration setup for loopback diagnostic */
2228 /* set up a none zero myDID for loopback test */
2229 phba
->pport
->fc_myDID
= 1;
2230 rc
= lpfc_sli4_diag_fcport_reg_setup(phba
);
2232 goto loopback_mode_exit
;
2235 /* wait for the port ready */
2238 while (phba
->link_state
!= LPFC_HBA_READY
) {
2239 if (i
++ > timeout
) {
2241 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2242 "3133 Timeout waiting for port "
2243 "loopback mode ready, timeout:%d ms\n",
2252 /* clear loopback diagnostic mode */
2254 spin_lock_irq(&phba
->hbalock
);
2255 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
2256 spin_unlock_irq(&phba
->hbalock
);
2258 lpfc_bsg_diag_mode_exit(phba
);
2261 /* make error code available to userspace */
2262 bsg_reply
->result
= rc
;
2263 /* complete the job back to userspace if no error */
2265 bsg_job_done(job
, bsg_reply
->result
,
2266 bsg_reply
->reply_payload_rcv_len
);
2271 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
2272 * @job: LPFC_BSG_VENDOR_DIAG_MODE
2274 * This function is responsible for responding to check and dispatch bsg diag
2275 * command from the user to proper driver action routines.
2278 lpfc_bsg_diag_loopback_mode(struct bsg_job
*job
)
2280 struct Scsi_Host
*shost
;
2281 struct lpfc_vport
*vport
;
2282 struct lpfc_hba
*phba
;
2285 shost
= fc_bsg_to_shost(job
);
2288 vport
= shost_priv(shost
);
2295 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2296 rc
= lpfc_sli3_bsg_diag_loopback_mode(phba
, job
);
2297 else if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) >=
2298 LPFC_SLI_INTF_IF_TYPE_2
)
2299 rc
= lpfc_sli4_bsg_diag_loopback_mode(phba
, job
);
2307 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
2308 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
2310 * This function is responsible for responding to check and dispatch bsg diag
2311 * command from the user to proper driver action routines.
2314 lpfc_sli4_bsg_diag_mode_end(struct bsg_job
*job
)
2316 struct fc_bsg_request
*bsg_request
= job
->request
;
2317 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
2318 struct Scsi_Host
*shost
;
2319 struct lpfc_vport
*vport
;
2320 struct lpfc_hba
*phba
;
2321 struct diag_mode_set
*loopback_mode_end_cmd
;
2325 shost
= fc_bsg_to_shost(job
);
2328 vport
= shost_priv(shost
);
2335 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2337 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
2338 LPFC_SLI_INTF_IF_TYPE_2
)
2341 /* clear loopback diagnostic mode */
2342 spin_lock_irq(&phba
->hbalock
);
2343 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
2344 spin_unlock_irq(&phba
->hbalock
);
2345 loopback_mode_end_cmd
= (struct diag_mode_set
*)
2346 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
2347 timeout
= loopback_mode_end_cmd
->timeout
* 100;
2349 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2351 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2352 "3139 Failed to bring link to diagnostic "
2353 "state, rc:x%x\n", rc
);
2354 goto loopback_mode_end_exit
;
2357 /* wait for link down before proceeding */
2359 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
2360 if (i
++ > timeout
) {
2361 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2362 "3140 Timeout waiting for link to "
2363 "diagnostic mode_end, timeout:%d ms\n",
2365 /* there is nothing much we can do here */
2371 /* reset port resource registrations */
2372 rc
= lpfc_selective_reset(phba
);
2373 phba
->pport
->fc_myDID
= 0;
2375 loopback_mode_end_exit
:
2376 /* make return code available to userspace */
2377 bsg_reply
->result
= rc
;
2378 /* complete the job back to userspace if no error */
2380 bsg_job_done(job
, bsg_reply
->result
,
2381 bsg_reply
->reply_payload_rcv_len
);
2386 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
2387 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
2389 * This function is to perform SLI4 diag link test request from the user
2393 lpfc_sli4_bsg_link_diag_test(struct bsg_job
*job
)
2395 struct fc_bsg_request
*bsg_request
= job
->request
;
2396 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
2397 struct Scsi_Host
*shost
;
2398 struct lpfc_vport
*vport
;
2399 struct lpfc_hba
*phba
;
2400 LPFC_MBOXQ_t
*pmboxq
;
2401 struct sli4_link_diag
*link_diag_test_cmd
;
2402 uint32_t req_len
, alloc_len
;
2403 struct lpfc_mbx_run_link_diag_test
*run_link_diag_test
;
2404 union lpfc_sli4_cfg_shdr
*shdr
;
2405 uint32_t shdr_status
, shdr_add_status
;
2406 struct diag_status
*diag_status_reply
;
2407 int mbxstatus
, rc
= 0;
2409 shost
= fc_bsg_to_shost(job
);
2414 vport
= shost_priv(shost
);
2425 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2429 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
2430 LPFC_SLI_INTF_IF_TYPE_2
) {
2435 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
2436 sizeof(struct sli4_link_diag
)) {
2437 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2438 "3013 Received LINK DIAG TEST request "
2439 " size:%d below the minimum size:%d\n",
2441 (int)(sizeof(struct fc_bsg_request
) +
2442 sizeof(struct sli4_link_diag
)));
2447 rc
= lpfc_bsg_diag_mode_enter(phba
);
2451 link_diag_test_cmd
= (struct sli4_link_diag
*)
2452 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
2454 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
2459 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2461 goto link_diag_test_exit
;
2463 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
2464 sizeof(struct lpfc_sli4_cfg_mhdr
));
2465 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2466 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
2467 req_len
, LPFC_SLI4_MBX_EMBED
);
2468 if (alloc_len
!= req_len
)
2469 goto link_diag_test_exit
;
2471 run_link_diag_test
= &pmboxq
->u
.mqe
.un
.link_diag_test
;
2472 bf_set(lpfc_mbx_run_diag_test_link_num
, &run_link_diag_test
->u
.req
,
2473 phba
->sli4_hba
.lnk_info
.lnk_no
);
2474 bf_set(lpfc_mbx_run_diag_test_link_type
, &run_link_diag_test
->u
.req
,
2475 phba
->sli4_hba
.lnk_info
.lnk_tp
);
2476 bf_set(lpfc_mbx_run_diag_test_test_id
, &run_link_diag_test
->u
.req
,
2477 link_diag_test_cmd
->test_id
);
2478 bf_set(lpfc_mbx_run_diag_test_loops
, &run_link_diag_test
->u
.req
,
2479 link_diag_test_cmd
->loops
);
2480 bf_set(lpfc_mbx_run_diag_test_test_ver
, &run_link_diag_test
->u
.req
,
2481 link_diag_test_cmd
->test_version
);
2482 bf_set(lpfc_mbx_run_diag_test_err_act
, &run_link_diag_test
->u
.req
,
2483 link_diag_test_cmd
->error_action
);
2485 mbxstatus
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2487 shdr
= (union lpfc_sli4_cfg_shdr
*)
2488 &pmboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2489 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
2490 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
2491 if (shdr_status
|| shdr_add_status
|| mbxstatus
) {
2492 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2493 "3010 Run link diag test mailbox failed with "
2494 "mbx_status x%x status x%x, add_status x%x\n",
2495 mbxstatus
, shdr_status
, shdr_add_status
);
2498 diag_status_reply
= (struct diag_status
*)
2499 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
2501 if (job
->reply_len
<
2502 sizeof(struct fc_bsg_request
) + sizeof(struct diag_status
)) {
2503 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2504 "3012 Received Run link diag test reply "
2505 "below minimum size (%d): reply_len:%d\n",
2506 (int)(sizeof(struct fc_bsg_request
) +
2507 sizeof(struct diag_status
)),
2513 diag_status_reply
->mbox_status
= mbxstatus
;
2514 diag_status_reply
->shdr_status
= shdr_status
;
2515 diag_status_reply
->shdr_add_status
= shdr_add_status
;
2517 link_diag_test_exit
:
2518 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2521 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2523 lpfc_bsg_diag_mode_exit(phba
);
2526 /* make error code available to userspace */
2527 bsg_reply
->result
= rc
;
2528 /* complete the job back to userspace if no error */
2530 bsg_job_done(job
, bsg_reply
->result
,
2531 bsg_reply
->reply_payload_rcv_len
);
2536 * lpfcdiag_loop_self_reg - obtains a remote port login id
2537 * @phba: Pointer to HBA context object
2538 * @rpi: Pointer to a remote port login id
2540 * This function obtains a remote port login id so the diag loopback test
2541 * can send and receive its own unsolicited CT command.
2543 static int lpfcdiag_loop_self_reg(struct lpfc_hba
*phba
, uint16_t *rpi
)
2546 struct lpfc_dmabuf
*dmabuff
;
2549 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2553 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2554 status
= lpfc_reg_rpi(phba
, 0, phba
->pport
->fc_myDID
,
2555 (uint8_t *)&phba
->pport
->fc_sparam
,
2558 *rpi
= lpfc_sli4_alloc_rpi(phba
);
2559 if (*rpi
== LPFC_RPI_ALLOC_ERROR
) {
2560 mempool_free(mbox
, phba
->mbox_mem_pool
);
2563 status
= lpfc_reg_rpi(phba
, phba
->pport
->vpi
,
2564 phba
->pport
->fc_myDID
,
2565 (uint8_t *)&phba
->pport
->fc_sparam
,
2570 mempool_free(mbox
, phba
->mbox_mem_pool
);
2571 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2572 lpfc_sli4_free_rpi(phba
, *rpi
);
2576 dmabuff
= (struct lpfc_dmabuf
*)mbox
->ctx_buf
;
2577 mbox
->ctx_buf
= NULL
;
2578 mbox
->ctx_ndlp
= NULL
;
2579 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2581 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2582 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2584 if (status
!= MBX_TIMEOUT
)
2585 mempool_free(mbox
, phba
->mbox_mem_pool
);
2586 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2587 lpfc_sli4_free_rpi(phba
, *rpi
);
2591 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2592 *rpi
= mbox
->u
.mb
.un
.varWords
[0];
2594 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2596 mempool_free(mbox
, phba
->mbox_mem_pool
);
2601 * lpfcdiag_loop_self_unreg - unregs from the rpi
2602 * @phba: Pointer to HBA context object
2603 * @rpi: Remote port login id
2605 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2607 static int lpfcdiag_loop_self_unreg(struct lpfc_hba
*phba
, uint16_t rpi
)
2612 /* Allocate mboxq structure */
2613 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2617 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2618 lpfc_unreg_login(phba
, 0, rpi
, mbox
);
2620 lpfc_unreg_login(phba
, phba
->pport
->vpi
,
2621 phba
->sli4_hba
.rpi_ids
[rpi
], mbox
);
2623 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2625 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2626 if (status
!= MBX_TIMEOUT
)
2627 mempool_free(mbox
, phba
->mbox_mem_pool
);
2630 mempool_free(mbox
, phba
->mbox_mem_pool
);
2631 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2632 lpfc_sli4_free_rpi(phba
, rpi
);
2637 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2638 * @phba: Pointer to HBA context object
2639 * @rpi: Remote port login id
2640 * @txxri: Pointer to transmit exchange id
2641 * @rxxri: Pointer to response exchabge id
2643 * This function obtains the transmit and receive ids required to send
2644 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2645 * flags are used to the unsolicted response handler is able to process
2646 * the ct command sent on the same port.
2648 static int lpfcdiag_loop_get_xri(struct lpfc_hba
*phba
, uint16_t rpi
,
2649 uint16_t *txxri
, uint16_t * rxxri
)
2651 struct lpfc_bsg_event
*evt
;
2652 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2654 struct lpfc_dmabuf
*dmabuf
;
2655 struct ulp_bde64
*bpl
= NULL
;
2656 struct lpfc_sli_ct_request
*ctreq
= NULL
;
2659 int iocb_stat
= IOCB_SUCCESS
;
2660 unsigned long flags
;
2664 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2665 SLI_CT_ELX_LOOPBACK
);
2669 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2670 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2671 lpfc_bsg_event_ref(evt
);
2672 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2674 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2675 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2677 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2679 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, 0, &dmabuf
->phys
);
2681 INIT_LIST_HEAD(&dmabuf
->list
);
2682 bpl
= (struct ulp_bde64
*) dmabuf
->virt
;
2683 memset(bpl
, 0, sizeof(*bpl
));
2684 ctreq
= (struct lpfc_sli_ct_request
*)(bpl
+ 1);
2686 le32_to_cpu(putPaddrHigh(dmabuf
->phys
+
2689 le32_to_cpu(putPaddrLow(dmabuf
->phys
+
2691 bpl
->tus
.f
.bdeFlags
= 0;
2692 bpl
->tus
.f
.bdeSize
= ELX_LOOPBACK_HEADER_SZ
;
2693 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2697 if (cmdiocbq
== NULL
|| rspiocbq
== NULL
||
2698 dmabuf
== NULL
|| bpl
== NULL
|| ctreq
== NULL
||
2699 dmabuf
->virt
== NULL
) {
2701 goto err_get_xri_exit
;
2704 cmd
= &cmdiocbq
->iocb
;
2705 rsp
= &rspiocbq
->iocb
;
2707 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2709 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2710 ctreq
->RevisionId
.bits
.InId
= 0;
2711 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2712 ctreq
->FsSubType
= 0;
2713 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_XRI_SETUP
;
2714 ctreq
->CommandResponse
.bits
.Size
= 0;
2717 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(dmabuf
->phys
);
2718 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(dmabuf
->phys
);
2719 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2720 cmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(*bpl
);
2722 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= LA
;
2723 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2724 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2725 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2727 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CR
;
2728 cmd
->ulpBdeCount
= 1;
2730 cmd
->ulpClass
= CLASS3
;
2731 cmd
->ulpContext
= rpi
;
2733 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2734 cmdiocbq
->vport
= phba
->pport
;
2735 cmdiocbq
->iocb_cmpl
= NULL
;
2737 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2739 (phba
->fc_ratov
* 2)
2740 + LPFC_DRVR_TIMEOUT
);
2741 if ((iocb_stat
!= IOCB_SUCCESS
) || (rsp
->ulpStatus
!= IOSTAT_SUCCESS
)) {
2743 goto err_get_xri_exit
;
2745 *txxri
= rsp
->ulpContext
;
2748 evt
->wait_time_stamp
= jiffies
;
2749 time_left
= wait_event_interruptible_timeout(
2750 evt
->wq
, !list_empty(&evt
->events_to_see
),
2751 msecs_to_jiffies(1000 *
2752 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
)));
2753 if (list_empty(&evt
->events_to_see
))
2754 ret_val
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
2756 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2757 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2758 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2759 *rxxri
= (list_entry(evt
->events_to_get
.prev
,
2760 typeof(struct event_data
),
2766 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2767 lpfc_bsg_event_unref(evt
); /* release ref */
2768 lpfc_bsg_event_unref(evt
); /* delete */
2769 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2773 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2777 if (cmdiocbq
&& (iocb_stat
!= IOCB_TIMEDOUT
))
2778 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2780 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2785 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2786 * @phba: Pointer to HBA context object
2788 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and
2789 * returns the pointer to the buffer.
2791 static struct lpfc_dmabuf
*
2792 lpfc_bsg_dma_page_alloc(struct lpfc_hba
*phba
)
2794 struct lpfc_dmabuf
*dmabuf
;
2795 struct pci_dev
*pcidev
= phba
->pcidev
;
2797 /* allocate dma buffer struct */
2798 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2802 INIT_LIST_HEAD(&dmabuf
->list
);
2804 /* now, allocate dma buffer */
2805 dmabuf
->virt
= dma_alloc_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2806 &(dmabuf
->phys
), GFP_KERNEL
);
2808 if (!dmabuf
->virt
) {
2817 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2818 * @phba: Pointer to HBA context object.
2819 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2821 * This routine just simply frees a dma buffer and its associated buffer
2822 * descriptor referred by @dmabuf.
2825 lpfc_bsg_dma_page_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*dmabuf
)
2827 struct pci_dev
*pcidev
= phba
->pcidev
;
2833 dma_free_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2834 dmabuf
->virt
, dmabuf
->phys
);
2840 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2841 * @phba: Pointer to HBA context object.
2842 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2844 * This routine just simply frees all dma buffers and their associated buffer
2845 * descriptors referred by @dmabuf_list.
2848 lpfc_bsg_dma_page_list_free(struct lpfc_hba
*phba
,
2849 struct list_head
*dmabuf_list
)
2851 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
2853 if (list_empty(dmabuf_list
))
2856 list_for_each_entry_safe(dmabuf
, next_dmabuf
, dmabuf_list
, list
) {
2857 list_del_init(&dmabuf
->list
);
2858 lpfc_bsg_dma_page_free(phba
, dmabuf
);
2864 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2865 * @phba: Pointer to HBA context object
2866 * @bpl: Pointer to 64 bit bde structure
2867 * @size: Number of bytes to process
2868 * @nocopydata: Flag to copy user data into the allocated buffer
2870 * This function allocates page size buffers and populates an lpfc_dmabufext.
2871 * If allowed the user data pointed to with indataptr is copied into the kernel
2872 * memory. The chained list of page size buffers is returned.
2874 static struct lpfc_dmabufext
*
2875 diag_cmd_data_alloc(struct lpfc_hba
*phba
,
2876 struct ulp_bde64
*bpl
, uint32_t size
,
2879 struct lpfc_dmabufext
*mlist
= NULL
;
2880 struct lpfc_dmabufext
*dmp
;
2881 int cnt
, offset
= 0, i
= 0;
2882 struct pci_dev
*pcidev
;
2884 pcidev
= phba
->pcidev
;
2887 /* We get chunks of 4K */
2888 if (size
> BUF_SZ_4K
)
2893 /* allocate struct lpfc_dmabufext buffer header */
2894 dmp
= kmalloc(sizeof(struct lpfc_dmabufext
), GFP_KERNEL
);
2898 INIT_LIST_HEAD(&dmp
->dma
.list
);
2900 /* Queue it to a linked list */
2902 list_add_tail(&dmp
->dma
.list
, &mlist
->dma
.list
);
2906 /* allocate buffer */
2907 dmp
->dma
.virt
= dma_alloc_coherent(&pcidev
->dev
,
2918 bpl
->tus
.f
.bdeFlags
= 0;
2920 memset((uint8_t *)dmp
->dma
.virt
, 0, cnt
);
2921 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2924 /* build buffer ptr list for IOCB */
2925 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dmp
->dma
.phys
));
2926 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dmp
->dma
.phys
));
2927 bpl
->tus
.f
.bdeSize
= (ushort
) cnt
;
2928 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2941 diag_cmd_data_free(phba
, mlist
);
2946 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2947 * @phba: Pointer to HBA context object
2948 * @rxxri: Receive exchange id
2949 * @len: Number of data bytes
2951 * This function allocates and posts a data buffer of sufficient size to receive
2952 * an unsolicted CT command.
2954 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba
*phba
, uint16_t rxxri
,
2957 struct lpfc_sli_ring
*pring
;
2958 struct lpfc_iocbq
*cmdiocbq
;
2960 struct list_head head
, *curr
, *next
;
2961 struct lpfc_dmabuf
*rxbmp
;
2962 struct lpfc_dmabuf
*dmp
;
2963 struct lpfc_dmabuf
*mp
[2] = {NULL
, NULL
};
2964 struct ulp_bde64
*rxbpl
= NULL
;
2966 struct lpfc_dmabufext
*rxbuffer
= NULL
;
2971 pring
= lpfc_phba_elsring(phba
);
2973 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2974 rxbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2975 if (rxbmp
!= NULL
) {
2976 rxbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &rxbmp
->phys
);
2978 INIT_LIST_HEAD(&rxbmp
->list
);
2979 rxbpl
= (struct ulp_bde64
*) rxbmp
->virt
;
2980 rxbuffer
= diag_cmd_data_alloc(phba
, rxbpl
, len
, 0);
2984 if (!cmdiocbq
|| !rxbmp
|| !rxbpl
|| !rxbuffer
|| !pring
) {
2986 goto err_post_rxbufs_exit
;
2989 /* Queue buffers for the receive exchange */
2990 num_bde
= (uint32_t)rxbuffer
->flag
;
2991 dmp
= &rxbuffer
->dma
;
2993 cmd
= &cmdiocbq
->iocb
;
2996 INIT_LIST_HEAD(&head
);
2997 list_add_tail(&head
, &dmp
->list
);
2998 list_for_each_safe(curr
, next
, &head
) {
2999 mp
[i
] = list_entry(curr
, struct lpfc_dmabuf
, list
);
3002 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
3003 mp
[i
]->buffer_tag
= lpfc_sli_get_buffer_tag(phba
);
3004 cmd
->un
.quexri64cx
.buff
.bde
.addrHigh
=
3005 putPaddrHigh(mp
[i
]->phys
);
3006 cmd
->un
.quexri64cx
.buff
.bde
.addrLow
=
3007 putPaddrLow(mp
[i
]->phys
);
3008 cmd
->un
.quexri64cx
.buff
.bde
.tus
.f
.bdeSize
=
3009 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
3010 cmd
->un
.quexri64cx
.buff
.buffer_tag
= mp
[i
]->buffer_tag
;
3011 cmd
->ulpCommand
= CMD_QUE_XRI64_CX
;
3014 cmd
->ulpBdeCount
= 1;
3015 cmd
->unsli3
.que_xri64cx_ext_words
.ebde_count
= 0;
3018 cmd
->un
.cont64
[i
].addrHigh
= putPaddrHigh(mp
[i
]->phys
);
3019 cmd
->un
.cont64
[i
].addrLow
= putPaddrLow(mp
[i
]->phys
);
3020 cmd
->un
.cont64
[i
].tus
.f
.bdeSize
=
3021 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
3022 cmd
->ulpBdeCount
= ++i
;
3024 if ((--num_bde
> 0) && (i
< 2))
3027 cmd
->ulpCommand
= CMD_QUE_XRI_BUF64_CX
;
3031 cmd
->ulpClass
= CLASS3
;
3032 cmd
->ulpContext
= rxxri
;
3034 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
3036 if (iocb_stat
== IOCB_ERROR
) {
3037 diag_cmd_data_free(phba
,
3038 (struct lpfc_dmabufext
*)mp
[0]);
3040 diag_cmd_data_free(phba
,
3041 (struct lpfc_dmabufext
*)mp
[1]);
3042 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
3044 goto err_post_rxbufs_exit
;
3047 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[0]);
3049 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[1]);
3053 /* The iocb was freed by lpfc_sli_issue_iocb */
3054 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
3056 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
3058 goto err_post_rxbufs_exit
;
3061 cmd
= &cmdiocbq
->iocb
;
3066 err_post_rxbufs_exit
:
3070 lpfc_mbuf_free(phba
, rxbmp
->virt
, rxbmp
->phys
);
3075 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
3080 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
3081 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
3083 * This function receives a user data buffer to be transmitted and received on
3084 * the same port, the link must be up and in loopback mode prior
3086 * 1. A kernel buffer is allocated to copy the user data into.
3087 * 2. The port registers with "itself".
3088 * 3. The transmit and receive exchange ids are obtained.
3089 * 4. The receive exchange id is posted.
3090 * 5. A new els loopback event is created.
3091 * 6. The command and response iocbs are allocated.
3092 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
3094 * This function is meant to be called n times while the port is in loopback
3095 * so it is the apps responsibility to issue a reset to take the port out
3099 lpfc_bsg_diag_loopback_run(struct bsg_job
*job
)
3101 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
3102 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
3103 struct lpfc_hba
*phba
= vport
->phba
;
3104 struct lpfc_bsg_event
*evt
;
3105 struct event_data
*evdat
;
3106 struct lpfc_sli
*psli
= &phba
->sli
;
3109 size_t segment_len
= 0, segment_offset
= 0, current_offset
= 0;
3111 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
= NULL
;
3112 IOCB_t
*cmd
, *rsp
= NULL
;
3113 struct lpfc_sli_ct_request
*ctreq
;
3114 struct lpfc_dmabuf
*txbmp
;
3115 struct ulp_bde64
*txbpl
= NULL
;
3116 struct lpfc_dmabufext
*txbuffer
= NULL
;
3117 struct list_head head
;
3118 struct lpfc_dmabuf
*curr
;
3119 uint16_t txxri
= 0, rxxri
;
3121 uint8_t *ptr
= NULL
, *rx_databuf
= NULL
;
3124 int iocb_stat
= IOCB_SUCCESS
;
3125 unsigned long flags
;
3126 void *dataout
= NULL
;
3129 /* in case no data is returned return just the return code */
3130 bsg_reply
->reply_payload_rcv_len
= 0;
3132 if (job
->request_len
<
3133 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_test
)) {
3134 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3135 "2739 Received DIAG TEST request below minimum "
3138 goto loopback_test_exit
;
3141 if (job
->request_payload
.payload_len
!=
3142 job
->reply_payload
.payload_len
) {
3144 goto loopback_test_exit
;
3147 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
3148 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
3149 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
3151 goto loopback_test_exit
;
3154 if (!lpfc_is_link_up(phba
) || !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
3156 goto loopback_test_exit
;
3159 size
= job
->request_payload
.payload_len
;
3160 full_size
= size
+ ELX_LOOPBACK_HEADER_SZ
; /* plus the header */
3162 if ((size
== 0) || (size
> 80 * BUF_SZ_4K
)) {
3164 goto loopback_test_exit
;
3167 if (full_size
>= BUF_SZ_4K
) {
3169 * Allocate memory for ioctl data. If buffer is bigger than 64k,
3170 * then we allocate 64k and re-use that buffer over and over to
3171 * xfer the whole block. This is because Linux kernel has a
3172 * problem allocating more than 120k of kernel space memory. Saw
3173 * problem with GET_FCPTARGETMAPPING...
3175 if (size
<= (64 * 1024))
3176 total_mem
= full_size
;
3178 total_mem
= 64 * 1024;
3180 /* Allocate memory for ioctl data */
3181 total_mem
= BUF_SZ_4K
;
3183 dataout
= kmalloc(total_mem
, GFP_KERNEL
);
3184 if (dataout
== NULL
) {
3186 goto loopback_test_exit
;
3190 ptr
+= ELX_LOOPBACK_HEADER_SZ
;
3191 sg_copy_to_buffer(job
->request_payload
.sg_list
,
3192 job
->request_payload
.sg_cnt
,
3194 rc
= lpfcdiag_loop_self_reg(phba
, &rpi
);
3196 goto loopback_test_exit
;
3198 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3199 rc
= lpfcdiag_loop_get_xri(phba
, rpi
, &txxri
, &rxxri
);
3201 lpfcdiag_loop_self_unreg(phba
, rpi
);
3202 goto loopback_test_exit
;
3205 rc
= lpfcdiag_loop_post_rxbufs(phba
, rxxri
, full_size
);
3207 lpfcdiag_loop_self_unreg(phba
, rpi
);
3208 goto loopback_test_exit
;
3211 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
3212 SLI_CT_ELX_LOOPBACK
);
3214 lpfcdiag_loop_self_unreg(phba
, rpi
);
3216 goto loopback_test_exit
;
3219 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3220 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
3221 lpfc_bsg_event_ref(evt
);
3222 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3224 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
3225 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3226 rspiocbq
= lpfc_sli_get_iocbq(phba
);
3227 txbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3230 txbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &txbmp
->phys
);
3232 INIT_LIST_HEAD(&txbmp
->list
);
3233 txbpl
= (struct ulp_bde64
*) txbmp
->virt
;
3234 txbuffer
= diag_cmd_data_alloc(phba
,
3235 txbpl
, full_size
, 0);
3239 if (!cmdiocbq
|| !txbmp
|| !txbpl
|| !txbuffer
|| !txbmp
->virt
) {
3241 goto err_loopback_test_exit
;
3243 if ((phba
->sli_rev
< LPFC_SLI_REV4
) && !rspiocbq
) {
3245 goto err_loopback_test_exit
;
3248 cmd
= &cmdiocbq
->iocb
;
3249 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3250 rsp
= &rspiocbq
->iocb
;
3252 INIT_LIST_HEAD(&head
);
3253 list_add_tail(&head
, &txbuffer
->dma
.list
);
3254 list_for_each_entry(curr
, &head
, list
) {
3255 segment_len
= ((struct lpfc_dmabufext
*)curr
)->size
;
3256 if (current_offset
== 0) {
3258 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
3259 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
3260 ctreq
->RevisionId
.bits
.InId
= 0;
3261 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
3262 ctreq
->FsSubType
= 0;
3263 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_DATA
;
3264 ctreq
->CommandResponse
.bits
.Size
= size
;
3265 segment_offset
= ELX_LOOPBACK_HEADER_SZ
;
3269 BUG_ON(segment_offset
>= segment_len
);
3270 memcpy(curr
->virt
+ segment_offset
,
3271 ptr
+ current_offset
,
3272 segment_len
- segment_offset
);
3274 current_offset
+= segment_len
- segment_offset
;
3275 BUG_ON(current_offset
> size
);
3279 /* Build the XMIT_SEQUENCE iocb */
3280 num_bde
= (uint32_t)txbuffer
->flag
;
3282 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(txbmp
->phys
);
3283 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(txbmp
->phys
);
3284 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
3285 cmd
->un
.xseq64
.bdl
.bdeSize
= (num_bde
* sizeof(struct ulp_bde64
));
3287 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
3288 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
3289 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
3290 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
3292 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
3293 cmd
->ulpBdeCount
= 1;
3295 cmd
->ulpClass
= CLASS3
;
3297 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3298 cmd
->ulpContext
= txxri
;
3300 cmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
3301 cmd
->un
.ulpWord
[3] = phba
->sli4_hba
.rpi_ids
[rpi
];
3302 cmdiocbq
->context3
= txbmp
;
3303 cmdiocbq
->sli4_xritag
= NO_XRI
;
3304 cmd
->unsli3
.rcvsli3
.ox_id
= 0xffff;
3306 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
3307 cmdiocbq
->iocb_flag
|= LPFC_IO_LOOPBACK
;
3308 cmdiocbq
->vport
= phba
->pport
;
3309 cmdiocbq
->iocb_cmpl
= NULL
;
3310 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
3311 rspiocbq
, (phba
->fc_ratov
* 2) +
3314 if ((iocb_stat
!= IOCB_SUCCESS
) ||
3315 ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3316 (rsp
->ulpStatus
!= IOSTAT_SUCCESS
))) {
3317 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3318 "3126 Failed loopback test issue iocb: "
3319 "iocb_stat:x%x\n", iocb_stat
);
3321 goto err_loopback_test_exit
;
3325 time_left
= wait_event_interruptible_timeout(
3326 evt
->wq
, !list_empty(&evt
->events_to_see
),
3327 msecs_to_jiffies(1000 *
3328 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
)));
3330 if (list_empty(&evt
->events_to_see
)) {
3331 rc
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
3332 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3333 "3125 Not receiving unsolicited event, "
3336 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3337 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
3338 evdat
= list_entry(evt
->events_to_get
.prev
,
3339 typeof(*evdat
), node
);
3340 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3341 rx_databuf
= evdat
->data
;
3342 if (evdat
->len
!= full_size
) {
3343 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3344 "1603 Loopback test did not receive expected "
3345 "data length. actual length 0x%x expected "
3347 evdat
->len
, full_size
);
3349 } else if (rx_databuf
== NULL
)
3353 /* skip over elx loopback header */
3354 rx_databuf
+= ELX_LOOPBACK_HEADER_SZ
;
3355 bsg_reply
->reply_payload_rcv_len
=
3356 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3357 job
->reply_payload
.sg_cnt
,
3359 bsg_reply
->reply_payload_rcv_len
= size
;
3363 err_loopback_test_exit
:
3364 lpfcdiag_loop_self_unreg(phba
, rpi
);
3366 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3367 lpfc_bsg_event_unref(evt
); /* release ref */
3368 lpfc_bsg_event_unref(evt
); /* delete */
3369 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3371 if ((cmdiocbq
!= NULL
) && (iocb_stat
!= IOCB_TIMEDOUT
))
3372 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
3374 if (rspiocbq
!= NULL
)
3375 lpfc_sli_release_iocbq(phba
, rspiocbq
);
3377 if (txbmp
!= NULL
) {
3378 if (txbpl
!= NULL
) {
3379 if (txbuffer
!= NULL
)
3380 diag_cmd_data_free(phba
, txbuffer
);
3381 lpfc_mbuf_free(phba
, txbmp
->virt
, txbmp
->phys
);
3388 /* make error code available to userspace */
3389 bsg_reply
->result
= rc
;
3390 job
->dd_data
= NULL
;
3391 /* complete the job back to userspace if no error */
3392 if (rc
== IOCB_SUCCESS
)
3393 bsg_job_done(job
, bsg_reply
->result
,
3394 bsg_reply
->reply_payload_rcv_len
);
3399 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
3400 * @job: GET_DFC_REV fc_bsg_job
3403 lpfc_bsg_get_dfc_rev(struct bsg_job
*job
)
3405 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
3406 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
3407 struct lpfc_hba
*phba
= vport
->phba
;
3408 struct get_mgmt_rev_reply
*event_reply
;
3411 if (job
->request_len
<
3412 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev
)) {
3413 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3414 "2740 Received GET_DFC_REV request below "
3420 event_reply
= (struct get_mgmt_rev_reply
*)
3421 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
3423 if (job
->reply_len
<
3424 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev_reply
)) {
3425 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3426 "2741 Received GET_DFC_REV reply below "
3432 event_reply
->info
.a_Major
= MANAGEMENT_MAJOR_REV
;
3433 event_reply
->info
.a_Minor
= MANAGEMENT_MINOR_REV
;
3435 bsg_reply
->result
= rc
;
3437 bsg_job_done(job
, bsg_reply
->result
,
3438 bsg_reply
->reply_payload_rcv_len
);
3443 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
3444 * @phba: Pointer to HBA context object.
3445 * @pmboxq: Pointer to mailbox command.
3447 * This is completion handler function for mailbox commands issued from
3448 * lpfc_bsg_issue_mbox function. This function is called by the
3449 * mailbox event handler function with no lock held. This function
3450 * will wake up thread waiting on the wait queue pointed by context1
3454 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3456 struct bsg_job_data
*dd_data
;
3457 struct fc_bsg_reply
*bsg_reply
;
3458 struct bsg_job
*job
;
3460 unsigned long flags
;
3461 uint8_t *pmb
, *pmb_buf
;
3463 dd_data
= pmboxq
->ctx_ndlp
;
3466 * The outgoing buffer is readily referred from the dma buffer,
3467 * just need to get header part from mailboxq structure.
3469 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3470 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3471 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3473 /* Determine if job has been aborted */
3475 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3476 job
= dd_data
->set_job
;
3478 /* Prevent timeout handling from trying to abort job */
3479 job
->dd_data
= NULL
;
3481 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3483 /* Copy the mailbox data to the job if it is still active */
3486 bsg_reply
= job
->reply
;
3487 size
= job
->reply_payload
.payload_len
;
3488 bsg_reply
->reply_payload_rcv_len
=
3489 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3490 job
->reply_payload
.sg_cnt
,
3494 dd_data
->set_job
= NULL
;
3495 mempool_free(dd_data
->context_un
.mbox
.pmboxq
, phba
->mbox_mem_pool
);
3496 lpfc_bsg_dma_page_free(phba
, dd_data
->context_un
.mbox
.dmabuffers
);
3499 /* Complete the job if the job is still active */
3502 bsg_reply
->result
= 0;
3503 bsg_job_done(job
, bsg_reply
->result
,
3504 bsg_reply
->reply_payload_rcv_len
);
3510 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3511 * @phba: Pointer to HBA context object.
3512 * @mb: Pointer to a mailbox object.
3513 * @vport: Pointer to a vport object.
3515 * Some commands require the port to be offline, some may not be called from
3518 static int lpfc_bsg_check_cmd_access(struct lpfc_hba
*phba
,
3519 MAILBOX_t
*mb
, struct lpfc_vport
*vport
)
3521 /* return negative error values for bsg job */
3522 switch (mb
->mbxCommand
) {
3526 case MBX_CONFIG_LINK
:
3527 case MBX_CONFIG_RING
:
3528 case MBX_RESET_RING
:
3529 case MBX_UNREG_LOGIN
:
3531 case MBX_DUMP_CONTEXT
:
3535 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
3536 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3537 "2743 Command 0x%x is illegal in on-line "
3543 case MBX_WRITE_VPARMS
:
3546 case MBX_READ_CONFIG
:
3547 case MBX_READ_RCONFIG
:
3548 case MBX_READ_STATUS
:
3551 case MBX_READ_LNK_STAT
:
3552 case MBX_DUMP_MEMORY
:
3554 case MBX_UPDATE_CFG
:
3555 case MBX_KILL_BOARD
:
3556 case MBX_READ_TOPOLOGY
:
3558 case MBX_LOAD_EXP_ROM
:
3560 case MBX_DEL_LD_ENTRY
:
3563 case MBX_SLI4_CONFIG
:
3564 case MBX_READ_EVENT_LOG
:
3565 case MBX_READ_EVENT_LOG_STATUS
:
3566 case MBX_WRITE_EVENT_LOG
:
3567 case MBX_PORT_CAPABILITIES
:
3568 case MBX_PORT_IOV_CONTROL
:
3569 case MBX_RUN_BIU_DIAG64
:
3571 case MBX_SET_VARIABLE
:
3572 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3573 "1226 mbox: set_variable 0x%x, 0x%x\n",
3575 mb
->un
.varWords
[1]);
3576 if ((mb
->un
.varWords
[0] == SETVAR_MLOMNT
)
3577 && (mb
->un
.varWords
[1] == 1)) {
3578 phba
->wait_4_mlo_maint_flg
= 1;
3579 } else if (mb
->un
.varWords
[0] == SETVAR_MLORST
) {
3580 spin_lock_irq(&phba
->hbalock
);
3581 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
3582 spin_unlock_irq(&phba
->hbalock
);
3583 phba
->fc_topology
= LPFC_TOPOLOGY_PT_PT
;
3586 case MBX_READ_SPARM64
:
3588 case MBX_REG_LOGIN64
:
3589 case MBX_CONFIG_PORT
:
3590 case MBX_RUN_BIU_DIAG
:
3592 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3593 "2742 Unknown Command 0x%x\n",
3602 * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
3603 * @phba: Pointer to HBA context object.
3605 * This is routine clean up and reset BSG handling of multi-buffer mbox
3609 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba
*phba
)
3611 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
)
3614 /* free all memory, including dma buffers */
3615 lpfc_bsg_dma_page_list_free(phba
,
3616 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3617 lpfc_bsg_dma_page_free(phba
, phba
->mbox_ext_buf_ctx
.mbx_dmabuf
);
3618 /* multi-buffer write mailbox command pass-through complete */
3619 memset((char *)&phba
->mbox_ext_buf_ctx
, 0,
3620 sizeof(struct lpfc_mbox_ext_buf_ctx
));
3621 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3627 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3628 * @phba: Pointer to HBA context object.
3629 * @pmboxq: Pointer to mailbox command.
3631 * This is routine handles BSG job for mailbox commands completions with
3632 * multiple external buffers.
3634 static struct bsg_job
*
3635 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3637 struct bsg_job_data
*dd_data
;
3638 struct bsg_job
*job
;
3639 struct fc_bsg_reply
*bsg_reply
;
3640 uint8_t *pmb
, *pmb_buf
;
3641 unsigned long flags
;
3644 struct lpfc_dmabuf
*dmabuf
;
3645 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3648 dd_data
= pmboxq
->ctx_buf
;
3650 /* Determine if job has been aborted */
3651 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3652 job
= dd_data
->set_job
;
3654 bsg_reply
= job
->reply
;
3655 /* Prevent timeout handling from trying to abort job */
3656 job
->dd_data
= NULL
;
3658 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3661 * The outgoing buffer is readily referred from the dma buffer,
3662 * just need to get header part from mailboxq structure.
3665 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3666 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3667 /* Copy the byte swapped response mailbox back to the user */
3668 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3669 /* if there is any non-embedded extended data copy that too */
3670 dmabuf
= phba
->mbox_ext_buf_ctx
.mbx_dmabuf
;
3671 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3672 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3673 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3674 pmbx
= (uint8_t *)dmabuf
->virt
;
3675 /* byte swap the extended data following the mailbox command */
3676 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3677 &pmbx
[sizeof(MAILBOX_t
)],
3678 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[0].buf_len
);
3681 /* Complete the job if the job is still active */
3684 size
= job
->reply_payload
.payload_len
;
3685 bsg_reply
->reply_payload_rcv_len
=
3686 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3687 job
->reply_payload
.sg_cnt
,
3690 /* result for successful */
3691 bsg_reply
->result
= 0;
3693 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3694 "2937 SLI_CONFIG ext-buffer mailbox command "
3695 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3696 phba
->mbox_ext_buf_ctx
.nembType
,
3697 phba
->mbox_ext_buf_ctx
.mboxType
, size
);
3698 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
,
3699 phba
->mbox_ext_buf_ctx
.nembType
,
3700 phba
->mbox_ext_buf_ctx
.mboxType
,
3701 dma_ebuf
, sta_pos_addr
,
3702 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
, 0);
3704 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3705 "2938 SLI_CONFIG ext-buffer mailbox "
3706 "command (x%x/x%x) failure, rc:x%x\n",
3707 phba
->mbox_ext_buf_ctx
.nembType
,
3708 phba
->mbox_ext_buf_ctx
.mboxType
, rc
);
3713 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_DONE
;
3719 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3720 * @phba: Pointer to HBA context object.
3721 * @pmboxq: Pointer to mailbox command.
3723 * This is completion handler function for mailbox read commands with multiple
3727 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3729 struct bsg_job
*job
;
3730 struct fc_bsg_reply
*bsg_reply
;
3732 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3734 /* handle the BSG job with mailbox command */
3736 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3738 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3739 "2939 SLI_CONFIG ext-buffer rd mailbox command "
3740 "complete, ctxState:x%x, mbxStatus:x%x\n",
3741 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3743 if (pmboxq
->u
.mb
.mbxStatus
|| phba
->mbox_ext_buf_ctx
.numBuf
== 1)
3744 lpfc_bsg_mbox_ext_session_reset(phba
);
3746 /* free base driver mailbox structure memory */
3747 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3749 /* if the job is still active, call job done */
3751 bsg_reply
= job
->reply
;
3752 bsg_job_done(job
, bsg_reply
->result
,
3753 bsg_reply
->reply_payload_rcv_len
);
3759 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3760 * @phba: Pointer to HBA context object.
3761 * @pmboxq: Pointer to mailbox command.
3763 * This is completion handler function for mailbox write commands with multiple
3767 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3769 struct bsg_job
*job
;
3770 struct fc_bsg_reply
*bsg_reply
;
3772 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3774 /* handle the BSG job with the mailbox command */
3776 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3778 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3779 "2940 SLI_CONFIG ext-buffer wr mailbox command "
3780 "complete, ctxState:x%x, mbxStatus:x%x\n",
3781 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3783 /* free all memory, including dma buffers */
3784 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3785 lpfc_bsg_mbox_ext_session_reset(phba
);
3787 /* if the job is still active, call job done */
3789 bsg_reply
= job
->reply
;
3790 bsg_job_done(job
, bsg_reply
->result
,
3791 bsg_reply
->reply_payload_rcv_len
);
3798 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba
*phba
, enum nemb_type nemb_tp
,
3799 uint32_t index
, struct lpfc_dmabuf
*mbx_dmabuf
,
3800 struct lpfc_dmabuf
*ext_dmabuf
)
3802 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3804 /* pointer to the start of mailbox command */
3805 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)mbx_dmabuf
->virt
;
3807 if (nemb_tp
== nemb_mse
) {
3809 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3811 putPaddrHigh(mbx_dmabuf
->phys
+
3813 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3815 putPaddrLow(mbx_dmabuf
->phys
+
3817 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3818 "2943 SLI_CONFIG(mse)[%d], "
3819 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3821 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3823 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3825 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3828 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3830 putPaddrHigh(ext_dmabuf
->phys
);
3831 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3833 putPaddrLow(ext_dmabuf
->phys
);
3834 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3835 "2944 SLI_CONFIG(mse)[%d], "
3836 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3838 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3840 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3842 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3847 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3849 putPaddrHigh(mbx_dmabuf
->phys
+
3851 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3853 putPaddrLow(mbx_dmabuf
->phys
+
3855 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3856 "3007 SLI_CONFIG(hbd)[%d], "
3857 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3859 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3861 sli_config_emb1_subsys
.hbd
[index
]),
3862 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3864 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3868 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3870 putPaddrHigh(ext_dmabuf
->phys
);
3871 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3873 putPaddrLow(ext_dmabuf
->phys
);
3874 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3875 "3008 SLI_CONFIG(hbd)[%d], "
3876 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3878 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3880 sli_config_emb1_subsys
.hbd
[index
]),
3881 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3883 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3891 * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
3892 * @phba: Pointer to HBA context object.
3893 * @mb: Pointer to a BSG mailbox object.
3894 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3895 * @dmabuff: Pointer to a DMA buffer descriptor.
3897 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3898 * non-embedded external bufffers.
3901 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba
*phba
, struct bsg_job
*job
,
3902 enum nemb_type nemb_tp
,
3903 struct lpfc_dmabuf
*dmabuf
)
3905 struct fc_bsg_request
*bsg_request
= job
->request
;
3906 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3907 struct dfc_mbox_req
*mbox_req
;
3908 struct lpfc_dmabuf
*curr_dmabuf
, *next_dmabuf
;
3909 uint32_t ext_buf_cnt
, ext_buf_index
;
3910 struct lpfc_dmabuf
*ext_dmabuf
= NULL
;
3911 struct bsg_job_data
*dd_data
= NULL
;
3912 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3918 (struct dfc_mbox_req
*)bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
3920 /* pointer to the start of mailbox command */
3921 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3923 if (nemb_tp
== nemb_mse
) {
3924 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3925 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3926 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3927 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3928 "2945 Handled SLI_CONFIG(mse) rd, "
3929 "ext_buf_cnt(%d) out of range(%d)\n",
3931 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3935 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3936 "2941 Handled SLI_CONFIG(mse) rd, "
3937 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3939 /* sanity check on interface type for support */
3940 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
3941 LPFC_SLI_INTF_IF_TYPE_2
) {
3945 /* nemb_tp == nemb_hbd */
3946 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3947 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3948 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3949 "2946 Handled SLI_CONFIG(hbd) rd, "
3950 "ext_buf_cnt(%d) out of range(%d)\n",
3952 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3956 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3957 "2942 Handled SLI_CONFIG(hbd) rd, "
3958 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3961 /* before dma descriptor setup */
3962 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3963 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3965 /* reject non-embedded mailbox command with none external buffer */
3966 if (ext_buf_cnt
== 0) {
3969 } else if (ext_buf_cnt
> 1) {
3970 /* additional external read buffers */
3971 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3972 ext_dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
3977 list_add_tail(&ext_dmabuf
->list
,
3978 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3982 /* bsg tracking structure */
3983 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3989 /* mailbox command structure for base driver */
3990 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3995 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3997 /* for the first external buffer */
3998 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
4000 /* for the rest of external buffer descriptors if any */
4001 if (ext_buf_cnt
> 1) {
4003 list_for_each_entry_safe(curr_dmabuf
, next_dmabuf
,
4004 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
, list
) {
4005 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
,
4006 ext_buf_index
, dmabuf
,
4012 /* after dma descriptor setup */
4013 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
4014 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
4016 /* construct base driver mbox command */
4017 pmb
= &pmboxq
->u
.mb
;
4018 pmbx
= (uint8_t *)dmabuf
->virt
;
4019 memcpy(pmb
, pmbx
, sizeof(*pmb
));
4020 pmb
->mbxOwner
= OWN_HOST
;
4021 pmboxq
->vport
= phba
->pport
;
4023 /* multi-buffer handling context */
4024 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
4025 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_rd
;
4026 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
4027 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
4028 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
4029 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
4031 /* callback for multi-buffer read mailbox command */
4032 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_read_mbox_ext_cmpl
;
4034 /* context fields to callback function */
4035 pmboxq
->ctx_buf
= dd_data
;
4036 dd_data
->type
= TYPE_MBOX
;
4037 dd_data
->set_job
= job
;
4038 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4039 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
4040 job
->dd_data
= dd_data
;
4043 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4046 * Non-embedded mailbox subcommand data gets byte swapped here because
4047 * the lower level driver code only does the first 64 mailbox words.
4049 if ((!bsg_bf_get(lpfc_mbox_hdr_emb
,
4050 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) &&
4051 (nemb_tp
== nemb_mse
))
4052 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
4053 &pmbx
[sizeof(MAILBOX_t
)],
4054 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
4057 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4058 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4059 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4060 "2947 Issued SLI_CONFIG ext-buffer "
4061 "mailbox command, rc:x%x\n", rc
);
4062 return SLI_CONFIG_HANDLED
;
4064 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4065 "2948 Failed to issue SLI_CONFIG ext-buffer "
4066 "mailbox command, rc:x%x\n", rc
);
4071 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4072 lpfc_bsg_dma_page_list_free(phba
,
4073 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4075 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
4080 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
4081 * @phba: Pointer to HBA context object.
4082 * @mb: Pointer to a BSG mailbox object.
4083 * @dmabuff: Pointer to a DMA buffer descriptor.
4085 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
4086 * non-embedded external bufffers.
4089 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba
*phba
, struct bsg_job
*job
,
4090 enum nemb_type nemb_tp
,
4091 struct lpfc_dmabuf
*dmabuf
)
4093 struct fc_bsg_request
*bsg_request
= job
->request
;
4094 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
4095 struct dfc_mbox_req
*mbox_req
;
4096 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4097 uint32_t ext_buf_cnt
;
4098 struct bsg_job_data
*dd_data
= NULL
;
4099 LPFC_MBOXQ_t
*pmboxq
= NULL
;
4102 int rc
= SLI_CONFIG_NOT_HANDLED
, i
;
4105 (struct dfc_mbox_req
*)bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
4107 /* pointer to the start of mailbox command */
4108 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
4110 if (nemb_tp
== nemb_mse
) {
4111 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
4112 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
4113 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
4114 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4115 "2953 Failed SLI_CONFIG(mse) wr, "
4116 "ext_buf_cnt(%d) out of range(%d)\n",
4118 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
4121 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4122 "2949 Handled SLI_CONFIG(mse) wr, "
4123 "ext_buf_cnt:%d\n", ext_buf_cnt
);
4125 /* sanity check on interface type for support */
4126 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
4127 LPFC_SLI_INTF_IF_TYPE_2
)
4129 /* nemb_tp == nemb_hbd */
4130 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
4131 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
4132 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4133 "2954 Failed SLI_CONFIG(hbd) wr, "
4134 "ext_buf_cnt(%d) out of range(%d)\n",
4136 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
4139 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4140 "2950 Handled SLI_CONFIG(hbd) wr, "
4141 "ext_buf_cnt:%d\n", ext_buf_cnt
);
4144 /* before dma buffer descriptor setup */
4145 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
4146 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
4148 if (ext_buf_cnt
== 0)
4151 /* for the first external buffer */
4152 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
4154 /* after dma descriptor setup */
4155 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
4156 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
4158 /* log for looking forward */
4159 for (i
= 1; i
< ext_buf_cnt
; i
++) {
4160 if (nemb_tp
== nemb_mse
)
4161 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4162 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
4163 i
, sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
4166 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4167 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
4168 i
, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
4169 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
4173 /* multi-buffer handling context */
4174 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
4175 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_wr
;
4176 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
4177 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
4178 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
4179 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
4181 if (ext_buf_cnt
== 1) {
4182 /* bsg tracking structure */
4183 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4189 /* mailbox command structure for base driver */
4190 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4195 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4196 pmb
= &pmboxq
->u
.mb
;
4197 mbx
= (uint8_t *)dmabuf
->virt
;
4198 memcpy(pmb
, mbx
, sizeof(*pmb
));
4199 pmb
->mbxOwner
= OWN_HOST
;
4200 pmboxq
->vport
= phba
->pport
;
4202 /* callback for multi-buffer read mailbox command */
4203 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
4205 /* context fields to callback function */
4206 pmboxq
->ctx_buf
= dd_data
;
4207 dd_data
->type
= TYPE_MBOX
;
4208 dd_data
->set_job
= job
;
4209 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4210 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)mbx
;
4211 job
->dd_data
= dd_data
;
4215 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4216 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4217 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4218 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4219 "2955 Issued SLI_CONFIG ext-buffer "
4220 "mailbox command, rc:x%x\n", rc
);
4221 return SLI_CONFIG_HANDLED
;
4223 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4224 "2956 Failed to issue SLI_CONFIG ext-buffer "
4225 "mailbox command, rc:x%x\n", rc
);
4230 /* wait for additoinal external buffers */
4232 bsg_reply
->result
= 0;
4233 bsg_job_done(job
, bsg_reply
->result
,
4234 bsg_reply
->reply_payload_rcv_len
);
4235 return SLI_CONFIG_HANDLED
;
4239 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4246 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
4247 * @phba: Pointer to HBA context object.
4248 * @mb: Pointer to a BSG mailbox object.
4249 * @dmabuff: Pointer to a DMA buffer descriptor.
4251 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
4252 * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
4253 * with embedded sussystem 0x1 and opcodes with external HBDs.
4256 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba
*phba
, struct bsg_job
*job
,
4257 struct lpfc_dmabuf
*dmabuf
)
4259 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4262 int rc
= SLI_CONFIG_NOT_HANDLED
;
4264 /* state change on new multi-buffer pass-through mailbox command */
4265 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_HOST
;
4267 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
4269 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
4270 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
4271 subsys
= bsg_bf_get(lpfc_emb0_subcmnd_subsys
,
4272 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
4273 opcode
= bsg_bf_get(lpfc_emb0_subcmnd_opcode
,
4274 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
4275 if (subsys
== SLI_CONFIG_SUBSYS_FCOE
) {
4277 case FCOE_OPCODE_READ_FCF
:
4278 case FCOE_OPCODE_GET_DPORT_RESULTS
:
4279 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4280 "2957 Handled SLI_CONFIG "
4281 "subsys_fcoe, opcode:x%x\n",
4283 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4286 case FCOE_OPCODE_ADD_FCF
:
4287 case FCOE_OPCODE_SET_DPORT_MODE
:
4288 case LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
:
4289 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4290 "2958 Handled SLI_CONFIG "
4291 "subsys_fcoe, opcode:x%x\n",
4293 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
4297 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4298 "2959 Reject SLI_CONFIG "
4299 "subsys_fcoe, opcode:x%x\n",
4304 } else if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
4306 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES
:
4307 case COMN_OPCODE_GET_CNTL_ATTRIBUTES
:
4308 case COMN_OPCODE_GET_PROFILE_CONFIG
:
4309 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4310 "3106 Handled SLI_CONFIG "
4311 "subsys_comn, opcode:x%x\n",
4313 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4317 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4318 "3107 Reject SLI_CONFIG "
4319 "subsys_comn, opcode:x%x\n",
4325 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4326 "2977 Reject SLI_CONFIG "
4327 "subsys:x%d, opcode:x%x\n",
4332 subsys
= bsg_bf_get(lpfc_emb1_subcmnd_subsys
,
4333 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4334 opcode
= bsg_bf_get(lpfc_emb1_subcmnd_opcode
,
4335 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4336 if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
4338 case COMN_OPCODE_READ_OBJECT
:
4339 case COMN_OPCODE_READ_OBJECT_LIST
:
4340 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4341 "2960 Handled SLI_CONFIG "
4342 "subsys_comn, opcode:x%x\n",
4344 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4347 case COMN_OPCODE_WRITE_OBJECT
:
4348 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4349 "2961 Handled SLI_CONFIG "
4350 "subsys_comn, opcode:x%x\n",
4352 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
4356 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4357 "2962 Not handled SLI_CONFIG "
4358 "subsys_comn, opcode:x%x\n",
4360 rc
= SLI_CONFIG_NOT_HANDLED
;
4364 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4365 "2978 Not handled SLI_CONFIG "
4366 "subsys:x%d, opcode:x%x\n",
4368 rc
= SLI_CONFIG_NOT_HANDLED
;
4372 /* state reset on not handled new multi-buffer mailbox command */
4373 if (rc
!= SLI_CONFIG_HANDLED
)
4374 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
4380 * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
4381 * @phba: Pointer to HBA context object.
4383 * This routine is for requesting to abort a pass-through mailbox command with
4384 * multiple external buffers due to error condition.
4387 lpfc_bsg_mbox_ext_abort(struct lpfc_hba
*phba
)
4389 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
4390 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
4392 lpfc_bsg_mbox_ext_session_reset(phba
);
4397 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
4398 * @phba: Pointer to HBA context object.
4399 * @dmabuf: Pointer to a DMA buffer descriptor.
4401 * This routine extracts the next mailbox read external buffer back to
4402 * user space through BSG.
4405 lpfc_bsg_read_ebuf_get(struct lpfc_hba
*phba
, struct bsg_job
*job
)
4407 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
4408 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4409 struct lpfc_dmabuf
*dmabuf
;
4414 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4415 phba
->mbox_ext_buf_ctx
.seqNum
++;
4417 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4418 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4420 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4421 size
= bsg_bf_get(lpfc_mbox_sli_config_mse_len
,
4422 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[index
]);
4423 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4424 "2963 SLI_CONFIG (mse) ext-buffer rd get "
4425 "buffer[%d], size:%d\n", index
, size
);
4427 size
= bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
4428 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd
[index
]);
4429 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4430 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
4431 "buffer[%d], size:%d\n", index
, size
);
4433 if (list_empty(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
))
4435 dmabuf
= list_first_entry(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
,
4436 struct lpfc_dmabuf
, list
);
4437 list_del_init(&dmabuf
->list
);
4439 /* after dma buffer descriptor setup */
4440 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4441 mbox_rd
, dma_ebuf
, sta_pos_addr
,
4444 pbuf
= (uint8_t *)dmabuf
->virt
;
4445 bsg_reply
->reply_payload_rcv_len
=
4446 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4447 job
->reply_payload
.sg_cnt
,
4450 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4452 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4453 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4454 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
4455 "command session done\n");
4456 lpfc_bsg_mbox_ext_session_reset(phba
);
4459 bsg_reply
->result
= 0;
4460 bsg_job_done(job
, bsg_reply
->result
,
4461 bsg_reply
->reply_payload_rcv_len
);
4463 return SLI_CONFIG_HANDLED
;
4467 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
4468 * @phba: Pointer to HBA context object.
4469 * @dmabuf: Pointer to a DMA buffer descriptor.
4471 * This routine sets up the next mailbox read external buffer obtained
4472 * from user space through BSG.
4475 lpfc_bsg_write_ebuf_set(struct lpfc_hba
*phba
, struct bsg_job
*job
,
4476 struct lpfc_dmabuf
*dmabuf
)
4478 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
4479 struct bsg_job_data
*dd_data
= NULL
;
4480 LPFC_MBOXQ_t
*pmboxq
= NULL
;
4482 enum nemb_type nemb_tp
;
4488 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4489 phba
->mbox_ext_buf_ctx
.seqNum
++;
4490 nemb_tp
= phba
->mbox_ext_buf_ctx
.nembType
;
4492 pbuf
= (uint8_t *)dmabuf
->virt
;
4493 size
= job
->request_payload
.payload_len
;
4494 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4495 job
->request_payload
.sg_cnt
,
4498 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4499 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4500 "2966 SLI_CONFIG (mse) ext-buffer wr set "
4501 "buffer[%d], size:%d\n",
4502 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4505 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4506 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
4507 "buffer[%d], size:%d\n",
4508 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4512 /* set up external buffer descriptor and add to external buffer list */
4513 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, index
,
4514 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
,
4516 list_add_tail(&dmabuf
->list
, &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4518 /* after write dma buffer */
4519 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4520 mbox_wr
, dma_ebuf
, sta_pos_addr
,
4523 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4524 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4525 "2968 SLI_CONFIG ext-buffer wr all %d "
4526 "ebuffers received\n",
4527 phba
->mbox_ext_buf_ctx
.numBuf
);
4529 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4535 /* mailbox command structure for base driver */
4536 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4541 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4542 pbuf
= (uint8_t *)phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4543 pmb
= &pmboxq
->u
.mb
;
4544 memcpy(pmb
, pbuf
, sizeof(*pmb
));
4545 pmb
->mbxOwner
= OWN_HOST
;
4546 pmboxq
->vport
= phba
->pport
;
4548 /* callback for multi-buffer write mailbox command */
4549 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
4551 /* context fields to callback function */
4552 pmboxq
->ctx_buf
= dd_data
;
4553 dd_data
->type
= TYPE_MBOX
;
4554 dd_data
->set_job
= job
;
4555 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4556 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pbuf
;
4557 job
->dd_data
= dd_data
;
4560 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4562 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4563 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4564 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4565 "2969 Issued SLI_CONFIG ext-buffer "
4566 "mailbox command, rc:x%x\n", rc
);
4567 return SLI_CONFIG_HANDLED
;
4569 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4570 "2970 Failed to issue SLI_CONFIG ext-buffer "
4571 "mailbox command, rc:x%x\n", rc
);
4576 /* wait for additoinal external buffers */
4577 bsg_reply
->result
= 0;
4578 bsg_job_done(job
, bsg_reply
->result
,
4579 bsg_reply
->reply_payload_rcv_len
);
4580 return SLI_CONFIG_HANDLED
;
4584 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4585 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4592 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4593 * @phba: Pointer to HBA context object.
4594 * @mb: Pointer to a BSG mailbox object.
4595 * @dmabuff: Pointer to a DMA buffer descriptor.
4597 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4598 * command with multiple non-embedded external buffers.
4601 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba
*phba
, struct bsg_job
*job
,
4602 struct lpfc_dmabuf
*dmabuf
)
4606 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4607 "2971 SLI_CONFIG buffer (type:x%x)\n",
4608 phba
->mbox_ext_buf_ctx
.mboxType
);
4610 if (phba
->mbox_ext_buf_ctx
.mboxType
== mbox_rd
) {
4611 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_DONE
) {
4612 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4613 "2972 SLI_CONFIG rd buffer state "
4615 phba
->mbox_ext_buf_ctx
.state
);
4616 lpfc_bsg_mbox_ext_abort(phba
);
4619 rc
= lpfc_bsg_read_ebuf_get(phba
, job
);
4620 if (rc
== SLI_CONFIG_HANDLED
)
4621 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4622 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4623 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_HOST
) {
4624 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4625 "2973 SLI_CONFIG wr buffer state "
4627 phba
->mbox_ext_buf_ctx
.state
);
4628 lpfc_bsg_mbox_ext_abort(phba
);
4631 rc
= lpfc_bsg_write_ebuf_set(phba
, job
, dmabuf
);
4637 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4638 * @phba: Pointer to HBA context object.
4639 * @mb: Pointer to a BSG mailbox object.
4640 * @dmabuff: Pointer to a DMA buffer descriptor.
4642 * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
4643 * (0x9B) mailbox commands and external buffers.
4646 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba
*phba
, struct bsg_job
*job
,
4647 struct lpfc_dmabuf
*dmabuf
)
4649 struct fc_bsg_request
*bsg_request
= job
->request
;
4650 struct dfc_mbox_req
*mbox_req
;
4651 int rc
= SLI_CONFIG_NOT_HANDLED
;
4654 (struct dfc_mbox_req
*)bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
4656 /* mbox command with/without single external buffer */
4657 if (mbox_req
->extMboxTag
== 0 && mbox_req
->extSeqNum
== 0)
4660 /* mbox command and first external buffer */
4661 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
) {
4662 if (mbox_req
->extSeqNum
== 1) {
4663 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4664 "2974 SLI_CONFIG mailbox: tag:%d, "
4665 "seq:%d\n", mbox_req
->extMboxTag
,
4666 mbox_req
->extSeqNum
);
4667 rc
= lpfc_bsg_handle_sli_cfg_mbox(phba
, job
, dmabuf
);
4670 goto sli_cfg_ext_error
;
4674 * handle additional external buffers
4677 /* check broken pipe conditions */
4678 if (mbox_req
->extMboxTag
!= phba
->mbox_ext_buf_ctx
.mbxTag
)
4679 goto sli_cfg_ext_error
;
4680 if (mbox_req
->extSeqNum
> phba
->mbox_ext_buf_ctx
.numBuf
)
4681 goto sli_cfg_ext_error
;
4682 if (mbox_req
->extSeqNum
!= phba
->mbox_ext_buf_ctx
.seqNum
+ 1)
4683 goto sli_cfg_ext_error
;
4685 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4686 "2975 SLI_CONFIG mailbox external buffer: "
4687 "extSta:x%x, tag:%d, seq:%d\n",
4688 phba
->mbox_ext_buf_ctx
.state
, mbox_req
->extMboxTag
,
4689 mbox_req
->extSeqNum
);
4690 rc
= lpfc_bsg_handle_sli_cfg_ebuf(phba
, job
, dmabuf
);
4694 /* all other cases, broken pipe */
4695 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4696 "2976 SLI_CONFIG mailbox broken pipe: "
4697 "ctxSta:x%x, ctxNumBuf:%d "
4698 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4699 phba
->mbox_ext_buf_ctx
.state
,
4700 phba
->mbox_ext_buf_ctx
.numBuf
,
4701 phba
->mbox_ext_buf_ctx
.mbxTag
,
4702 phba
->mbox_ext_buf_ctx
.seqNum
,
4703 mbox_req
->extMboxTag
, mbox_req
->extSeqNum
);
4705 lpfc_bsg_mbox_ext_session_reset(phba
);
4711 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4712 * @phba: Pointer to HBA context object.
4713 * @mb: Pointer to a mailbox object.
4714 * @vport: Pointer to a vport object.
4716 * Allocate a tracking object, mailbox command memory, get a mailbox
4717 * from the mailbox pool, copy the caller mailbox command.
4719 * If offline and the sli is active we need to poll for the command (port is
4720 * being reset) and com-plete the job, otherwise issue the mailbox command and
4721 * let our completion handler finish the command.
4724 lpfc_bsg_issue_mbox(struct lpfc_hba
*phba
, struct bsg_job
*job
,
4725 struct lpfc_vport
*vport
)
4727 struct fc_bsg_request
*bsg_request
= job
->request
;
4728 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
4729 LPFC_MBOXQ_t
*pmboxq
= NULL
; /* internal mailbox queue */
4730 MAILBOX_t
*pmb
; /* shortcut to the pmboxq mailbox */
4731 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4732 uint8_t *pmbx
= NULL
;
4733 struct bsg_job_data
*dd_data
= NULL
; /* bsg data tracking structure */
4734 struct lpfc_dmabuf
*dmabuf
= NULL
;
4735 struct dfc_mbox_req
*mbox_req
;
4736 struct READ_EVENT_LOG_VAR
*rdEventLog
;
4737 uint32_t transmit_length
, receive_length
, mode
;
4738 struct lpfc_mbx_sli4_config
*sli4_config
;
4739 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
4740 struct ulp_bde64
*bde
;
4741 uint8_t *ext
= NULL
;
4746 /* in case no data is transferred */
4747 bsg_reply
->reply_payload_rcv_len
= 0;
4749 /* sanity check to protect driver */
4750 if (job
->reply_payload
.payload_len
> BSG_MBOX_SIZE
||
4751 job
->request_payload
.payload_len
> BSG_MBOX_SIZE
) {
4757 * Don't allow mailbox commands to be sent when blocked or when in
4758 * the middle of discovery
4760 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4766 (struct dfc_mbox_req
*)bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
4768 /* check if requested extended data lengths are valid */
4769 if ((mbox_req
->inExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t)) ||
4770 (mbox_req
->outExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t))) {
4775 dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
4776 if (!dmabuf
|| !dmabuf
->virt
) {
4781 /* Get the mailbox command or external buffer from BSG */
4782 pmbx
= (uint8_t *)dmabuf
->virt
;
4783 size
= job
->request_payload
.payload_len
;
4784 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4785 job
->request_payload
.sg_cnt
, pmbx
, size
);
4787 /* Handle possible SLI_CONFIG with non-embedded payloads */
4788 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4789 rc
= lpfc_bsg_handle_sli_cfg_ext(phba
, job
, dmabuf
);
4790 if (rc
== SLI_CONFIG_HANDLED
)
4794 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4797 rc
= lpfc_bsg_check_cmd_access(phba
, (MAILBOX_t
*)pmbx
, vport
);
4799 goto job_done
; /* must be negative */
4801 /* allocate our bsg tracking structure */
4802 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4804 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4805 "2727 Failed allocation of dd_data\n");
4810 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4815 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4817 pmb
= &pmboxq
->u
.mb
;
4818 memcpy(pmb
, pmbx
, sizeof(*pmb
));
4819 pmb
->mbxOwner
= OWN_HOST
;
4820 pmboxq
->vport
= vport
;
4822 /* If HBA encountered an error attention, allow only DUMP
4823 * or RESTART mailbox commands until the HBA is restarted.
4825 if (phba
->pport
->stopped
&&
4826 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4827 pmb
->mbxCommand
!= MBX_RESTART
&&
4828 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4829 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4830 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4831 "2797 mbox: Issued mailbox cmd "
4832 "0x%x while in stopped state.\n",
4835 /* extended mailbox commands will need an extended buffer */
4836 if (mbox_req
->inExtWLen
|| mbox_req
->outExtWLen
) {
4838 ext
= from
+ sizeof(MAILBOX_t
);
4839 pmboxq
->ctx_buf
= ext
;
4840 pmboxq
->in_ext_byte_len
=
4841 mbox_req
->inExtWLen
* sizeof(uint32_t);
4842 pmboxq
->out_ext_byte_len
=
4843 mbox_req
->outExtWLen
* sizeof(uint32_t);
4844 pmboxq
->mbox_offset_word
= mbox_req
->mbOffset
;
4847 /* biu diag will need a kernel buffer to transfer the data
4848 * allocate our own buffer and setup the mailbox command to
4851 if (pmb
->mbxCommand
== MBX_RUN_BIU_DIAG64
) {
4852 transmit_length
= pmb
->un
.varWords
[1];
4853 receive_length
= pmb
->un
.varWords
[4];
4854 /* transmit length cannot be greater than receive length or
4855 * mailbox extension size
4857 if ((transmit_length
> receive_length
) ||
4858 (transmit_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4862 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrHigh
=
4863 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4864 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrLow
=
4865 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4867 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrHigh
=
4868 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4869 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4870 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrLow
=
4871 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4872 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4873 } else if (pmb
->mbxCommand
== MBX_READ_EVENT_LOG
) {
4874 rdEventLog
= &pmb
->un
.varRdEventLog
;
4875 receive_length
= rdEventLog
->rcv_bde64
.tus
.f
.bdeSize
;
4876 mode
= bf_get(lpfc_event_log
, rdEventLog
);
4878 /* receive length cannot be greater than mailbox
4881 if (receive_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4886 /* mode zero uses a bde like biu diags command */
4888 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4889 + sizeof(MAILBOX_t
));
4890 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4891 + sizeof(MAILBOX_t
));
4893 } else if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4894 /* Let type 4 (well known data) through because the data is
4895 * returned in varwords[4-8]
4896 * otherwise check the recieve length and fetch the buffer addr
4898 if ((pmb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
4899 (pmb
->un
.varDmp
.type
!= DMP_WELL_KNOWN
)) {
4900 /* rebuild the command for sli4 using our own buffers
4901 * like we do for biu diags
4903 receive_length
= pmb
->un
.varWords
[2];
4904 /* receive length cannot be greater than mailbox
4907 if (receive_length
== 0) {
4911 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4912 + sizeof(MAILBOX_t
));
4913 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4914 + sizeof(MAILBOX_t
));
4915 } else if ((pmb
->mbxCommand
== MBX_UPDATE_CFG
) &&
4916 pmb
->un
.varUpdateCfg
.co
) {
4917 bde
= (struct ulp_bde64
*)&pmb
->un
.varWords
[4];
4919 /* bde size cannot be greater than mailbox ext size */
4920 if (bde
->tus
.f
.bdeSize
>
4921 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4925 bde
->addrHigh
= putPaddrHigh(dmabuf
->phys
4926 + sizeof(MAILBOX_t
));
4927 bde
->addrLow
= putPaddrLow(dmabuf
->phys
4928 + sizeof(MAILBOX_t
));
4929 } else if (pmb
->mbxCommand
== MBX_SLI4_CONFIG
) {
4930 /* Handling non-embedded SLI_CONFIG mailbox command */
4931 sli4_config
= &pmboxq
->u
.mqe
.un
.sli4_config
;
4932 if (!bf_get(lpfc_mbox_hdr_emb
,
4933 &sli4_config
->header
.cfg_mhdr
)) {
4934 /* rebuild the command for sli4 using our
4935 * own buffers like we do for biu diags
4937 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
4938 &pmb
->un
.varWords
[0];
4939 receive_length
= nembed_sge
->sge
[0].length
;
4941 /* receive length cannot be greater than
4942 * mailbox extension size
4944 if ((receive_length
== 0) ||
4946 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4951 nembed_sge
->sge
[0].pa_hi
=
4952 putPaddrHigh(dmabuf
->phys
4953 + sizeof(MAILBOX_t
));
4954 nembed_sge
->sge
[0].pa_lo
=
4955 putPaddrLow(dmabuf
->phys
4956 + sizeof(MAILBOX_t
));
4961 dd_data
->context_un
.mbox
.dmabuffers
= dmabuf
;
4963 /* setup wake call as IOCB callback */
4964 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_mbox_cmpl
;
4966 /* setup context field to pass wait_queue pointer to wake function */
4967 pmboxq
->ctx_ndlp
= dd_data
;
4968 dd_data
->type
= TYPE_MBOX
;
4969 dd_data
->set_job
= job
;
4970 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4971 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
4972 dd_data
->context_un
.mbox
.ext
= ext
;
4973 dd_data
->context_un
.mbox
.mbOffset
= mbox_req
->mbOffset
;
4974 dd_data
->context_un
.mbox
.inExtWLen
= mbox_req
->inExtWLen
;
4975 dd_data
->context_un
.mbox
.outExtWLen
= mbox_req
->outExtWLen
;
4976 job
->dd_data
= dd_data
;
4978 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4979 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4980 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4981 if (rc
!= MBX_SUCCESS
) {
4982 rc
= (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4986 /* job finished, copy the data */
4987 memcpy(pmbx
, pmb
, sizeof(*pmb
));
4988 bsg_reply
->reply_payload_rcv_len
=
4989 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4990 job
->reply_payload
.sg_cnt
,
4992 /* not waiting mbox already done */
4997 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4998 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
))
4999 return 1; /* job started */
5002 /* common exit for error or job completed inline */
5004 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
5005 lpfc_bsg_dma_page_free(phba
, dmabuf
);
5013 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
5014 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
5017 lpfc_bsg_mbox_cmd(struct bsg_job
*job
)
5019 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
5020 struct fc_bsg_request
*bsg_request
= job
->request
;
5021 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5022 struct lpfc_hba
*phba
= vport
->phba
;
5023 struct dfc_mbox_req
*mbox_req
;
5026 /* mix-and-match backward compatibility */
5027 bsg_reply
->reply_payload_rcv_len
= 0;
5028 if (job
->request_len
<
5029 sizeof(struct fc_bsg_request
) + sizeof(struct dfc_mbox_req
)) {
5030 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
5031 "2737 Mix-and-match backward compatibility "
5032 "between MBOX_REQ old size:%d and "
5033 "new request size:%d\n",
5034 (int)(job
->request_len
-
5035 sizeof(struct fc_bsg_request
)),
5036 (int)sizeof(struct dfc_mbox_req
));
5037 mbox_req
= (struct dfc_mbox_req
*)
5038 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
5039 mbox_req
->extMboxTag
= 0;
5040 mbox_req
->extSeqNum
= 0;
5043 rc
= lpfc_bsg_issue_mbox(phba
, job
, vport
);
5047 bsg_reply
->result
= 0;
5048 job
->dd_data
= NULL
;
5049 bsg_job_done(job
, bsg_reply
->result
,
5050 bsg_reply
->reply_payload_rcv_len
);
5052 /* job submitted, will complete later*/
5053 rc
= 0; /* return zero, no error */
5055 /* some error occurred */
5056 bsg_reply
->result
= rc
;
5057 job
->dd_data
= NULL
;
5064 * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
5065 * @phba: Pointer to HBA context object.
5066 * @cmdiocbq: Pointer to command iocb.
5067 * @rspiocbq: Pointer to response iocb.
5069 * This function is the completion handler for iocbs issued using
5070 * lpfc_menlo_cmd function. This function is called by the
5071 * ring event handler function without any lock held. This function
5072 * can be called from both worker thread context and interrupt
5073 * context. This function also can be called from another thread which
5074 * cleans up the SLI layer objects.
5075 * This function copies the contents of the response iocb to the
5076 * response iocb memory object provided by the caller of
5077 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
5078 * sleeps for the iocb completion.
5081 lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba
*phba
,
5082 struct lpfc_iocbq
*cmdiocbq
,
5083 struct lpfc_iocbq
*rspiocbq
)
5085 struct bsg_job_data
*dd_data
;
5086 struct bsg_job
*job
;
5087 struct fc_bsg_reply
*bsg_reply
;
5089 struct lpfc_dmabuf
*bmp
, *cmp
, *rmp
;
5090 struct lpfc_bsg_menlo
*menlo
;
5091 unsigned long flags
;
5092 struct menlo_response
*menlo_resp
;
5093 unsigned int rsp_size
;
5096 dd_data
= cmdiocbq
->context1
;
5097 cmp
= cmdiocbq
->context2
;
5098 bmp
= cmdiocbq
->context3
;
5099 menlo
= &dd_data
->context_un
.menlo
;
5101 rsp
= &rspiocbq
->iocb
;
5103 /* Determine if job has been aborted */
5104 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
5105 job
= dd_data
->set_job
;
5107 bsg_reply
= job
->reply
;
5108 /* Prevent timeout handling from trying to abort job */
5109 job
->dd_data
= NULL
;
5111 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5113 /* Copy the job data or set the failing status for the job */
5116 /* always return the xri, this would be used in the case
5117 * of a menlo download to allow the data to be sent as a
5118 * continuation of the exchange.
5121 menlo_resp
= (struct menlo_response
*)
5122 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
5123 menlo_resp
->xri
= rsp
->ulpContext
;
5124 if (rsp
->ulpStatus
) {
5125 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
5126 switch (rsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) {
5127 case IOERR_SEQUENCE_TIMEOUT
:
5130 case IOERR_INVALID_RPI
:
5141 rsp_size
= rsp
->un
.genreq64
.bdl
.bdeSize
;
5142 bsg_reply
->reply_payload_rcv_len
=
5143 lpfc_bsg_copy_data(rmp
, &job
->reply_payload
,
5149 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
5150 lpfc_free_bsg_buffers(phba
, cmp
);
5151 lpfc_free_bsg_buffers(phba
, rmp
);
5152 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
5156 /* Complete the job if active */
5159 bsg_reply
->result
= rc
;
5160 bsg_job_done(job
, bsg_reply
->result
,
5161 bsg_reply
->reply_payload_rcv_len
);
5168 * lpfc_menlo_cmd - send an ioctl for menlo hardware
5169 * @job: fc_bsg_job to handle
5171 * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
5172 * all the command completions will return the xri for the command.
5173 * For menlo data requests a gen request 64 CX is used to continue the exchange
5174 * supplied in the menlo request header xri field.
5177 lpfc_menlo_cmd(struct bsg_job
*job
)
5179 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
5180 struct fc_bsg_request
*bsg_request
= job
->request
;
5181 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5182 struct lpfc_hba
*phba
= vport
->phba
;
5183 struct lpfc_iocbq
*cmdiocbq
;
5186 struct menlo_command
*menlo_cmd
;
5187 struct lpfc_dmabuf
*bmp
= NULL
, *cmp
= NULL
, *rmp
= NULL
;
5190 struct bsg_job_data
*dd_data
;
5191 struct ulp_bde64
*bpl
= NULL
;
5193 /* in case no data is returned return just the return code */
5194 bsg_reply
->reply_payload_rcv_len
= 0;
5196 if (job
->request_len
<
5197 sizeof(struct fc_bsg_request
) +
5198 sizeof(struct menlo_command
)) {
5199 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5200 "2784 Received MENLO_CMD request below "
5206 if (job
->reply_len
<
5207 sizeof(struct fc_bsg_request
) + sizeof(struct menlo_response
)) {
5208 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5209 "2785 Received MENLO_CMD reply below "
5215 if (!(phba
->menlo_flag
& HBA_MENLO_SUPPORT
)) {
5216 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5217 "2786 Adapter does not support menlo "
5223 menlo_cmd
= (struct menlo_command
*)
5224 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
5226 /* allocate our bsg tracking structure */
5227 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
5229 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5230 "2787 Failed allocation of dd_data\n");
5235 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5241 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
5247 INIT_LIST_HEAD(&bmp
->list
);
5249 bpl
= (struct ulp_bde64
*)bmp
->virt
;
5250 request_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
);
5251 cmp
= lpfc_alloc_bsg_buffers(phba
, job
->request_payload
.payload_len
,
5252 1, bpl
, &request_nseg
);
5257 lpfc_bsg_copy_data(cmp
, &job
->request_payload
,
5258 job
->request_payload
.payload_len
, 1);
5260 bpl
+= request_nseg
;
5261 reply_nseg
= LPFC_BPL_SIZE
/sizeof(struct ulp_bde64
) - request_nseg
;
5262 rmp
= lpfc_alloc_bsg_buffers(phba
, job
->reply_payload
.payload_len
, 0,
5269 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
5275 cmd
= &cmdiocbq
->iocb
;
5276 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
5277 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
5278 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
5279 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
5280 cmd
->un
.genreq64
.bdl
.bdeSize
=
5281 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
5282 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
5283 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
5284 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CMD
;
5285 cmd
->un
.genreq64
.w5
.hcsw
.Type
= MENLO_TRANSPORT_TYPE
; /* 0xfe */
5286 cmd
->ulpBdeCount
= 1;
5287 cmd
->ulpClass
= CLASS3
;
5288 cmd
->ulpOwner
= OWN_CHIP
;
5289 cmd
->ulpLe
= 1; /* Limited Edition */
5290 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
5291 cmdiocbq
->vport
= phba
->pport
;
5292 /* We want the firmware to timeout before we do */
5293 cmd
->ulpTimeout
= MENLO_TIMEOUT
- 5;
5294 cmdiocbq
->iocb_cmpl
= lpfc_bsg_menlo_cmd_cmp
;
5295 cmdiocbq
->context1
= dd_data
;
5296 cmdiocbq
->context2
= cmp
;
5297 cmdiocbq
->context3
= bmp
;
5298 if (menlo_cmd
->cmd
== LPFC_BSG_VENDOR_MENLO_CMD
) {
5299 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
5300 cmd
->ulpPU
= MENLO_PU
; /* 3 */
5301 cmd
->un
.ulpWord
[4] = MENLO_DID
; /* 0x0000FC0E */
5302 cmd
->ulpContext
= MENLO_CONTEXT
; /* 0 */
5304 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CX
;
5306 cmd
->un
.ulpWord
[4] = 0;
5307 cmd
->ulpContext
= menlo_cmd
->xri
;
5310 dd_data
->type
= TYPE_MENLO
;
5311 dd_data
->set_job
= job
;
5312 dd_data
->context_un
.menlo
.cmdiocbq
= cmdiocbq
;
5313 dd_data
->context_un
.menlo
.rmp
= rmp
;
5314 job
->dd_data
= dd_data
;
5316 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
5318 if (rc
== IOCB_SUCCESS
)
5319 return 0; /* done for now */
5321 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
5324 lpfc_free_bsg_buffers(phba
, rmp
);
5326 lpfc_free_bsg_buffers(phba
, cmp
);
5329 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
5334 /* make error code available to userspace */
5335 bsg_reply
->result
= rc
;
5336 job
->dd_data
= NULL
;
5341 lpfc_forced_link_speed(struct bsg_job
*job
)
5343 struct Scsi_Host
*shost
= fc_bsg_to_shost(job
);
5344 struct lpfc_vport
*vport
= shost_priv(shost
);
5345 struct lpfc_hba
*phba
= vport
->phba
;
5346 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5347 struct forced_link_speed_support_reply
*forced_reply
;
5350 if (job
->request_len
<
5351 sizeof(struct fc_bsg_request
) +
5352 sizeof(struct get_forced_link_speed_support
)) {
5353 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5354 "0048 Received FORCED_LINK_SPEED request "
5355 "below minimum size\n");
5360 forced_reply
= (struct forced_link_speed_support_reply
*)
5361 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
5363 if (job
->reply_len
<
5364 sizeof(struct fc_bsg_request
) +
5365 sizeof(struct forced_link_speed_support_reply
)) {
5366 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5367 "0049 Received FORCED_LINK_SPEED reply below "
5373 forced_reply
->supported
= (phba
->hba_flag
& HBA_FORCED_LINK_SPEED
)
5374 ? LPFC_FORCED_LINK_SPEED_SUPPORTED
5375 : LPFC_FORCED_LINK_SPEED_NOT_SUPPORTED
;
5377 bsg_reply
->result
= rc
;
5379 bsg_job_done(job
, bsg_reply
->result
,
5380 bsg_reply
->reply_payload_rcv_len
);
5385 * lpfc_check_fwlog_support: Check FW log support on the adapter
5386 * @phba: Pointer to HBA context object.
5388 * Check if FW Logging support by the adapter
5391 lpfc_check_fwlog_support(struct lpfc_hba
*phba
)
5393 struct lpfc_ras_fwlog
*ras_fwlog
= NULL
;
5395 ras_fwlog
= &phba
->ras_fwlog
;
5397 if (ras_fwlog
->ras_hwsupport
== false)
5399 else if (ras_fwlog
->ras_enabled
== false)
5406 * lpfc_bsg_get_ras_config: Get RAS configuration settings
5407 * @job: fc_bsg_job to handle
5409 * Get RAS configuration values set.
5412 lpfc_bsg_get_ras_config(struct bsg_job
*job
)
5414 struct Scsi_Host
*shost
= fc_bsg_to_shost(job
);
5415 struct lpfc_vport
*vport
= shost_priv(shost
);
5416 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5417 struct lpfc_hba
*phba
= vport
->phba
;
5418 struct lpfc_bsg_get_ras_config_reply
*ras_reply
;
5419 struct lpfc_ras_fwlog
*ras_fwlog
= &phba
->ras_fwlog
;
5422 if (job
->request_len
<
5423 sizeof(struct fc_bsg_request
) +
5424 sizeof(struct lpfc_bsg_ras_req
)) {
5425 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
5426 "6192 FW_LOG request received "
5427 "below minimum size\n");
5432 /* Check FW log status */
5433 rc
= lpfc_check_fwlog_support(phba
);
5437 ras_reply
= (struct lpfc_bsg_get_ras_config_reply
*)
5438 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
5440 /* Current logging state */
5441 spin_lock_irq(&phba
->hbalock
);
5442 if (ras_fwlog
->state
== ACTIVE
)
5443 ras_reply
->state
= LPFC_RASLOG_STATE_RUNNING
;
5445 ras_reply
->state
= LPFC_RASLOG_STATE_STOPPED
;
5446 spin_unlock_irq(&phba
->hbalock
);
5448 ras_reply
->log_level
= phba
->ras_fwlog
.fw_loglevel
;
5449 ras_reply
->log_buff_sz
= phba
->cfg_ras_fwlog_buffsize
;
5452 /* make error code available to userspace */
5453 bsg_reply
->result
= rc
;
5455 /* complete the job back to userspace */
5457 bsg_job_done(job
, bsg_reply
->result
,
5458 bsg_reply
->reply_payload_rcv_len
);
5463 * lpfc_bsg_set_ras_config: Set FW logging parameters
5464 * @job: fc_bsg_job to handle
5466 * Set log-level parameters for FW-logging in host memory
5469 lpfc_bsg_set_ras_config(struct bsg_job
*job
)
5471 struct Scsi_Host
*shost
= fc_bsg_to_shost(job
);
5472 struct lpfc_vport
*vport
= shost_priv(shost
);
5473 struct lpfc_hba
*phba
= vport
->phba
;
5474 struct lpfc_bsg_set_ras_config_req
*ras_req
;
5475 struct fc_bsg_request
*bsg_request
= job
->request
;
5476 struct lpfc_ras_fwlog
*ras_fwlog
= &phba
->ras_fwlog
;
5477 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5478 uint8_t action
= 0, log_level
= 0;
5479 int rc
= 0, action_status
= 0;
5481 if (job
->request_len
<
5482 sizeof(struct fc_bsg_request
) +
5483 sizeof(struct lpfc_bsg_set_ras_config_req
)) {
5484 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
5485 "6182 Received RAS_LOG request "
5486 "below minimum size\n");
5491 /* Check FW log status */
5492 rc
= lpfc_check_fwlog_support(phba
);
5496 ras_req
= (struct lpfc_bsg_set_ras_config_req
*)
5497 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
5498 action
= ras_req
->action
;
5499 log_level
= ras_req
->log_level
;
5501 if (action
== LPFC_RASACTION_STOP_LOGGING
) {
5502 /* Check if already disabled */
5503 spin_lock_irq(&phba
->hbalock
);
5504 if (ras_fwlog
->state
!= ACTIVE
) {
5505 spin_unlock_irq(&phba
->hbalock
);
5509 spin_unlock_irq(&phba
->hbalock
);
5511 /* Disable logging */
5512 lpfc_ras_stop_fwlog(phba
);
5514 /*action = LPFC_RASACTION_START_LOGGING*/
5516 /* Even though FW-logging is active re-initialize
5517 * FW-logging with new log-level. Return status
5518 * "Logging already Running" to caller.
5520 spin_lock_irq(&phba
->hbalock
);
5521 if (ras_fwlog
->state
!= INACTIVE
)
5522 action_status
= -EINPROGRESS
;
5523 spin_unlock_irq(&phba
->hbalock
);
5525 /* Enable logging */
5526 rc
= lpfc_sli4_ras_fwlog_init(phba
, log_level
,
5527 LPFC_RAS_ENABLE_LOGGING
);
5533 /* Check if FW-logging is re-initialized */
5534 if (action_status
== -EINPROGRESS
)
5538 /* make error code available to userspace */
5539 bsg_reply
->result
= rc
;
5541 /* complete the job back to userspace */
5543 bsg_job_done(job
, bsg_reply
->result
,
5544 bsg_reply
->reply_payload_rcv_len
);
5550 * lpfc_bsg_get_ras_lwpd: Get log write position data
5551 * @job: fc_bsg_job to handle
5553 * Get Offset/Wrap count of the log message written
5557 lpfc_bsg_get_ras_lwpd(struct bsg_job
*job
)
5559 struct Scsi_Host
*shost
= fc_bsg_to_shost(job
);
5560 struct lpfc_vport
*vport
= shost_priv(shost
);
5561 struct lpfc_bsg_get_ras_lwpd
*ras_reply
;
5562 struct lpfc_hba
*phba
= vport
->phba
;
5563 struct lpfc_ras_fwlog
*ras_fwlog
= &phba
->ras_fwlog
;
5564 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5565 u32
*lwpd_ptr
= NULL
;
5568 rc
= lpfc_check_fwlog_support(phba
);
5572 if (job
->request_len
<
5573 sizeof(struct fc_bsg_request
) +
5574 sizeof(struct lpfc_bsg_ras_req
)) {
5575 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
5576 "6183 Received RAS_LOG request "
5577 "below minimum size\n");
5582 ras_reply
= (struct lpfc_bsg_get_ras_lwpd
*)
5583 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
5585 if (!ras_fwlog
->lwpd
.virt
) {
5586 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
5587 "6193 Restart FW Logging\n");
5592 /* Get lwpd offset */
5593 lwpd_ptr
= (uint32_t *)(ras_fwlog
->lwpd
.virt
);
5594 ras_reply
->offset
= be32_to_cpu(*lwpd_ptr
& 0xffffffff);
5596 /* Get wrap count */
5597 ras_reply
->wrap_count
= be32_to_cpu(*(++lwpd_ptr
) & 0xffffffff);
5600 /* make error code available to userspace */
5601 bsg_reply
->result
= rc
;
5603 /* complete the job back to userspace */
5605 bsg_job_done(job
, bsg_reply
->result
,
5606 bsg_reply
->reply_payload_rcv_len
);
5612 * lpfc_bsg_get_ras_fwlog: Read FW log
5613 * @job: fc_bsg_job to handle
5615 * Copy the FW log into the passed buffer.
5618 lpfc_bsg_get_ras_fwlog(struct bsg_job
*job
)
5620 struct Scsi_Host
*shost
= fc_bsg_to_shost(job
);
5621 struct lpfc_vport
*vport
= shost_priv(shost
);
5622 struct lpfc_hba
*phba
= vport
->phba
;
5623 struct fc_bsg_request
*bsg_request
= job
->request
;
5624 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5625 struct lpfc_bsg_get_fwlog_req
*ras_req
;
5626 u32 rd_offset
, rd_index
, offset
;
5627 void *src
, *fwlog_buff
;
5628 struct lpfc_ras_fwlog
*ras_fwlog
= NULL
;
5629 struct lpfc_dmabuf
*dmabuf
, *next
;
5632 ras_fwlog
= &phba
->ras_fwlog
;
5634 rc
= lpfc_check_fwlog_support(phba
);
5638 /* Logging to be stopped before reading */
5639 spin_lock_irq(&phba
->hbalock
);
5640 if (ras_fwlog
->state
== ACTIVE
) {
5641 spin_unlock_irq(&phba
->hbalock
);
5645 spin_unlock_irq(&phba
->hbalock
);
5647 if (job
->request_len
<
5648 sizeof(struct fc_bsg_request
) +
5649 sizeof(struct lpfc_bsg_get_fwlog_req
)) {
5650 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
5651 "6184 Received RAS_LOG request "
5652 "below minimum size\n");
5657 ras_req
= (struct lpfc_bsg_get_fwlog_req
*)
5658 bsg_request
->rqst_data
.h_vendor
.vendor_cmd
;
5659 rd_offset
= ras_req
->read_offset
;
5661 /* Allocate memory to read fw log*/
5662 fwlog_buff
= vmalloc(ras_req
->read_size
);
5668 rd_index
= (rd_offset
/ LPFC_RAS_MAX_ENTRY_SIZE
);
5669 offset
= (rd_offset
% LPFC_RAS_MAX_ENTRY_SIZE
);
5671 list_for_each_entry_safe(dmabuf
, next
,
5672 &ras_fwlog
->fwlog_buff_list
, list
) {
5674 if (dmabuf
->buffer_tag
< rd_index
)
5677 src
= dmabuf
->virt
+ offset
;
5678 memcpy(fwlog_buff
, src
, ras_req
->read_size
);
5682 bsg_reply
->reply_payload_rcv_len
=
5683 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
5684 job
->reply_payload
.sg_cnt
,
5685 fwlog_buff
, ras_req
->read_size
);
5690 bsg_reply
->result
= rc
;
5692 bsg_job_done(job
, bsg_reply
->result
,
5693 bsg_reply
->reply_payload_rcv_len
);
5699 lpfc_get_trunk_info(struct bsg_job
*job
)
5701 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
5702 struct lpfc_hba
*phba
= vport
->phba
;
5703 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5704 struct lpfc_trunk_info
*event_reply
;
5707 if (job
->request_len
<
5708 sizeof(struct fc_bsg_request
) + sizeof(struct get_trunk_info_req
)) {
5709 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
5710 "2744 Received GET TRUNK _INFO request below "
5716 event_reply
= (struct lpfc_trunk_info
*)
5717 bsg_reply
->reply_data
.vendor_reply
.vendor_rsp
;
5719 if (job
->reply_len
<
5720 sizeof(struct fc_bsg_request
) + sizeof(struct lpfc_trunk_info
)) {
5721 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
5722 "2728 Received GET TRUNK _INFO reply below "
5727 if (event_reply
== NULL
) {
5732 bsg_bf_set(lpfc_trunk_info_link_status
, event_reply
,
5733 (phba
->link_state
>= LPFC_LINK_UP
) ? 1 : 0);
5735 bsg_bf_set(lpfc_trunk_info_trunk_active0
, event_reply
,
5736 (phba
->trunk_link
.link0
.state
== LPFC_LINK_UP
) ? 1 : 0);
5738 bsg_bf_set(lpfc_trunk_info_trunk_active1
, event_reply
,
5739 (phba
->trunk_link
.link1
.state
== LPFC_LINK_UP
) ? 1 : 0);
5741 bsg_bf_set(lpfc_trunk_info_trunk_active2
, event_reply
,
5742 (phba
->trunk_link
.link2
.state
== LPFC_LINK_UP
) ? 1 : 0);
5744 bsg_bf_set(lpfc_trunk_info_trunk_active3
, event_reply
,
5745 (phba
->trunk_link
.link3
.state
== LPFC_LINK_UP
) ? 1 : 0);
5747 bsg_bf_set(lpfc_trunk_info_trunk_config0
, event_reply
,
5748 bf_get(lpfc_conf_trunk_port0
, &phba
->sli4_hba
));
5750 bsg_bf_set(lpfc_trunk_info_trunk_config1
, event_reply
,
5751 bf_get(lpfc_conf_trunk_port1
, &phba
->sli4_hba
));
5753 bsg_bf_set(lpfc_trunk_info_trunk_config2
, event_reply
,
5754 bf_get(lpfc_conf_trunk_port2
, &phba
->sli4_hba
));
5756 bsg_bf_set(lpfc_trunk_info_trunk_config3
, event_reply
,
5757 bf_get(lpfc_conf_trunk_port3
, &phba
->sli4_hba
));
5759 event_reply
->port_speed
= phba
->sli4_hba
.link_state
.speed
/ 1000;
5760 event_reply
->logical_speed
=
5761 phba
->sli4_hba
.link_state
.logical_speed
/ 1000;
5763 bsg_reply
->result
= rc
;
5765 bsg_job_done(job
, bsg_reply
->result
,
5766 bsg_reply
->reply_payload_rcv_len
);
5772 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
5773 * @job: fc_bsg_job to handle
5776 lpfc_bsg_hst_vendor(struct bsg_job
*job
)
5778 struct fc_bsg_request
*bsg_request
= job
->request
;
5779 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5780 int command
= bsg_request
->rqst_data
.h_vendor
.vendor_cmd
[0];
5784 case LPFC_BSG_VENDOR_SET_CT_EVENT
:
5785 rc
= lpfc_bsg_hba_set_event(job
);
5787 case LPFC_BSG_VENDOR_GET_CT_EVENT
:
5788 rc
= lpfc_bsg_hba_get_event(job
);
5790 case LPFC_BSG_VENDOR_SEND_MGMT_RESP
:
5791 rc
= lpfc_bsg_send_mgmt_rsp(job
);
5793 case LPFC_BSG_VENDOR_DIAG_MODE
:
5794 rc
= lpfc_bsg_diag_loopback_mode(job
);
5796 case LPFC_BSG_VENDOR_DIAG_MODE_END
:
5797 rc
= lpfc_sli4_bsg_diag_mode_end(job
);
5799 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK
:
5800 rc
= lpfc_bsg_diag_loopback_run(job
);
5802 case LPFC_BSG_VENDOR_LINK_DIAG_TEST
:
5803 rc
= lpfc_sli4_bsg_link_diag_test(job
);
5805 case LPFC_BSG_VENDOR_GET_MGMT_REV
:
5806 rc
= lpfc_bsg_get_dfc_rev(job
);
5808 case LPFC_BSG_VENDOR_MBOX
:
5809 rc
= lpfc_bsg_mbox_cmd(job
);
5811 case LPFC_BSG_VENDOR_MENLO_CMD
:
5812 case LPFC_BSG_VENDOR_MENLO_DATA
:
5813 rc
= lpfc_menlo_cmd(job
);
5815 case LPFC_BSG_VENDOR_FORCED_LINK_SPEED
:
5816 rc
= lpfc_forced_link_speed(job
);
5818 case LPFC_BSG_VENDOR_RAS_GET_LWPD
:
5819 rc
= lpfc_bsg_get_ras_lwpd(job
);
5821 case LPFC_BSG_VENDOR_RAS_GET_FWLOG
:
5822 rc
= lpfc_bsg_get_ras_fwlog(job
);
5824 case LPFC_BSG_VENDOR_RAS_GET_CONFIG
:
5825 rc
= lpfc_bsg_get_ras_config(job
);
5827 case LPFC_BSG_VENDOR_RAS_SET_CONFIG
:
5828 rc
= lpfc_bsg_set_ras_config(job
);
5830 case LPFC_BSG_VENDOR_GET_TRUNK_INFO
:
5831 rc
= lpfc_get_trunk_info(job
);
5835 bsg_reply
->reply_payload_rcv_len
= 0;
5836 /* make error code available to userspace */
5837 bsg_reply
->result
= rc
;
5845 * lpfc_bsg_request - handle a bsg request from the FC transport
5846 * @job: bsg_job to handle
5849 lpfc_bsg_request(struct bsg_job
*job
)
5851 struct fc_bsg_request
*bsg_request
= job
->request
;
5852 struct fc_bsg_reply
*bsg_reply
= job
->reply
;
5856 msgcode
= bsg_request
->msgcode
;
5858 case FC_BSG_HST_VENDOR
:
5859 rc
= lpfc_bsg_hst_vendor(job
);
5861 case FC_BSG_RPT_ELS
:
5862 rc
= lpfc_bsg_rport_els(job
);
5865 rc
= lpfc_bsg_send_mgmt_cmd(job
);
5869 bsg_reply
->reply_payload_rcv_len
= 0;
5870 /* make error code available to userspace */
5871 bsg_reply
->result
= rc
;
5879 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
5880 * @job: bsg_job that has timed out
5882 * This function just aborts the job's IOCB. The aborted IOCB will return to
5883 * the waiting function which will handle passing the error back to userspace
5886 lpfc_bsg_timeout(struct bsg_job
*job
)
5888 struct lpfc_vport
*vport
= shost_priv(fc_bsg_to_shost(job
));
5889 struct lpfc_hba
*phba
= vport
->phba
;
5890 struct lpfc_iocbq
*cmdiocb
;
5891 struct lpfc_sli_ring
*pring
;
5892 struct bsg_job_data
*dd_data
;
5893 unsigned long flags
;
5895 LIST_HEAD(completions
);
5896 struct lpfc_iocbq
*check_iocb
, *next_iocb
;
5898 pring
= lpfc_phba_elsring(phba
);
5899 if (unlikely(!pring
))
5902 /* if job's driver data is NULL, the command completed or is in the
5903 * the process of completing. In this case, return status to request
5904 * so the timeout is retried. This avoids double completion issues
5905 * and the request will be pulled off the timer queue when the
5906 * command's completion handler executes. Otherwise, prevent the
5907 * command's completion handler from executing the job done callback
5908 * and continue processing to abort the outstanding the command.
5911 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
5912 dd_data
= (struct bsg_job_data
*)job
->dd_data
;
5914 dd_data
->set_job
= NULL
;
5915 job
->dd_data
= NULL
;
5917 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5921 switch (dd_data
->type
) {
5923 /* Check to see if IOCB was issued to the port or not. If not,
5924 * remove it from the txq queue and call cancel iocbs.
5925 * Otherwise, call abort iotag
5927 cmdiocb
= dd_data
->context_un
.iocb
.cmdiocbq
;
5928 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5930 spin_lock_irqsave(&phba
->hbalock
, flags
);
5931 /* make sure the I/O abort window is still open */
5932 if (!(cmdiocb
->iocb_flag
& LPFC_IO_CMD_OUTSTANDING
)) {
5933 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5936 list_for_each_entry_safe(check_iocb
, next_iocb
, &pring
->txq
,
5938 if (check_iocb
== cmdiocb
) {
5939 list_move_tail(&check_iocb
->list
, &completions
);
5943 if (list_empty(&completions
))
5944 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5945 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5946 if (!list_empty(&completions
)) {
5947 lpfc_sli_cancel_iocbs(phba
, &completions
,
5948 IOSTAT_LOCAL_REJECT
,
5954 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5958 /* Update the ext buf ctx state if needed */
5960 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
5961 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
5962 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5965 /* Check to see if IOCB was issued to the port or not. If not,
5966 * remove it from the txq queue and call cancel iocbs.
5967 * Otherwise, call abort iotag.
5969 cmdiocb
= dd_data
->context_un
.menlo
.cmdiocbq
;
5970 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5972 spin_lock_irqsave(&phba
->hbalock
, flags
);
5973 list_for_each_entry_safe(check_iocb
, next_iocb
, &pring
->txq
,
5975 if (check_iocb
== cmdiocb
) {
5976 list_move_tail(&check_iocb
->list
, &completions
);
5980 if (list_empty(&completions
))
5981 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5982 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5983 if (!list_empty(&completions
)) {
5984 lpfc_sli_cancel_iocbs(phba
, &completions
,
5985 IOSTAT_LOCAL_REJECT
,
5990 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5994 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
5995 * otherwise an error message will be displayed on the console
5996 * so always return success (zero)