1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
21 #include <linux/interrupt.h>
22 #include <linux/mempool.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
26 #include <linux/list.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
31 #include <scsi/scsi_bsg_fc.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_debugfs.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_version.h"
49 struct lpfc_bsg_event
{
50 struct list_head node
;
54 /* Event type and waiter identifiers */
59 /* next two flags are here for the auto-delete logic */
60 unsigned long wait_time_stamp
;
63 /* seen and not seen events */
64 struct list_head events_to_get
;
65 struct list_head events_to_see
;
67 /* job waiting for this event to finish */
68 struct fc_bsg_job
*set_job
;
71 struct lpfc_bsg_iocb
{
72 struct lpfc_iocbq
*cmdiocbq
;
73 struct lpfc_iocbq
*rspiocbq
;
74 struct lpfc_dmabuf
*bmp
;
75 struct lpfc_nodelist
*ndlp
;
77 /* job waiting for this iocb to finish */
78 struct fc_bsg_job
*set_job
;
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 */
90 /* job waiting for this mbox command to finish */
91 struct fc_bsg_job
*set_job
;
94 #define MENLO_DID 0x0000FC0E
96 struct lpfc_bsg_menlo
{
97 struct lpfc_iocbq
*cmdiocbq
;
98 struct lpfc_iocbq
*rspiocbq
;
99 struct lpfc_dmabuf
*bmp
;
101 /* job waiting for this iocb to finish */
102 struct fc_bsg_job
*set_job
;
109 struct bsg_job_data
{
112 struct lpfc_bsg_event
*evt
;
113 struct lpfc_bsg_iocb iocb
;
114 struct lpfc_bsg_mbox mbox
;
115 struct lpfc_bsg_menlo menlo
;
120 struct list_head node
;
127 #define BUF_SZ_4K 4096
128 #define SLI_CT_ELX_LOOPBACK 0x10
130 enum ELX_LOOPBACK_CMD
{
131 ELX_LOOPBACK_XRI_SETUP
,
135 #define ELX_LOOPBACK_HEADER_SZ \
136 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
138 struct lpfc_dmabufext
{
139 struct lpfc_dmabuf dma
;
145 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
146 * @phba: Pointer to HBA context object.
147 * @cmdiocbq: Pointer to command iocb.
148 * @rspiocbq: Pointer to response iocb.
150 * This function is the completion handler for iocbs issued using
151 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
152 * ring event handler function without any lock held. This function
153 * can be called from both worker thread context and interrupt
154 * context. This function also can be called from another thread which
155 * cleans up the SLI layer objects.
156 * This function copies the contents of the response iocb to the
157 * response iocb memory object provided by the caller of
158 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
159 * sleeps for the iocb completion.
162 lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba
*phba
,
163 struct lpfc_iocbq
*cmdiocbq
,
164 struct lpfc_iocbq
*rspiocbq
)
166 struct bsg_job_data
*dd_data
;
167 struct fc_bsg_job
*job
;
169 struct lpfc_dmabuf
*bmp
;
170 struct lpfc_nodelist
*ndlp
;
171 struct lpfc_bsg_iocb
*iocb
;
175 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
176 dd_data
= cmdiocbq
->context2
;
178 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
179 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
183 iocb
= &dd_data
->context_un
.iocb
;
185 job
->dd_data
= NULL
; /* so timeout handler does not reply */
188 rsp
= &rspiocbq
->iocb
;
189 ndlp
= cmdiocbq
->context1
;
191 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
192 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
193 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
194 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
196 if (rsp
->ulpStatus
) {
197 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
198 switch (rsp
->un
.ulpWord
[4] & 0xff) {
199 case IOERR_SEQUENCE_TIMEOUT
:
202 case IOERR_INVALID_RPI
:
212 job
->reply
->reply_payload_rcv_len
=
213 rsp
->un
.genreq64
.bdl
.bdeSize
;
215 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
216 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
220 /* make error code available to userspace */
221 job
->reply
->result
= rc
;
222 /* complete the job back to userspace */
224 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
229 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
230 * @job: fc_bsg_job to handle
233 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job
*job
)
235 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
236 struct lpfc_hba
*phba
= vport
->phba
;
237 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
238 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
239 struct ulp_bde64
*bpl
= NULL
;
241 struct lpfc_iocbq
*cmdiocbq
= NULL
;
243 struct lpfc_dmabuf
*bmp
= NULL
;
246 struct scatterlist
*sgel
= NULL
;
249 struct bsg_job_data
*dd_data
;
254 /* in case no data is transferred */
255 job
->reply
->reply_payload_rcv_len
= 0;
257 /* allocate our bsg tracking structure */
258 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
260 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
261 "2733 Failed allocation of dd_data\n");
266 if (!lpfc_nlp_get(ndlp
)) {
271 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
277 if (ndlp
->nlp_flag
& NLP_ELS_SND_MASK
) {
282 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
288 cmd
= &cmdiocbq
->iocb
;
289 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
295 INIT_LIST_HEAD(&bmp
->list
);
296 bpl
= (struct ulp_bde64
*) bmp
->virt
;
297 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
298 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
299 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
300 busaddr
= sg_dma_address(sgel
);
301 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
302 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
303 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
304 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
305 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
309 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
310 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
311 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
312 busaddr
= sg_dma_address(sgel
);
313 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
314 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
315 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
316 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
317 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
321 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
322 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
323 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
324 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
325 cmd
->un
.genreq64
.bdl
.bdeSize
=
326 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
327 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
328 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
329 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
330 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
331 cmd
->un
.genreq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
332 cmd
->ulpBdeCount
= 1;
334 cmd
->ulpClass
= CLASS3
;
335 cmd
->ulpContext
= ndlp
->nlp_rpi
;
336 if (phba
->sli_rev
== LPFC_SLI_REV4
)
337 cmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
338 cmd
->ulpOwner
= OWN_CHIP
;
339 cmdiocbq
->vport
= phba
->pport
;
340 cmdiocbq
->context3
= bmp
;
341 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
342 timeout
= phba
->fc_ratov
* 2;
343 cmd
->ulpTimeout
= timeout
;
345 cmdiocbq
->iocb_cmpl
= lpfc_bsg_send_mgmt_cmd_cmp
;
346 cmdiocbq
->context1
= ndlp
;
347 cmdiocbq
->context2
= dd_data
;
348 dd_data
->type
= TYPE_IOCB
;
349 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
350 dd_data
->context_un
.iocb
.set_job
= job
;
351 dd_data
->context_un
.iocb
.bmp
= bmp
;
353 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
354 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
358 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
359 writel(creg_val
, phba
->HCregaddr
);
360 readl(phba
->HCregaddr
); /* flush */
363 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
364 if (iocb_stat
== IOCB_SUCCESS
)
365 return 0; /* done for now */
366 else if (iocb_stat
== IOCB_BUSY
)
372 /* iocb failed so cleanup */
373 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
374 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
375 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
376 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
378 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
381 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
389 /* make error code available to userspace */
390 job
->reply
->result
= rc
;
396 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
397 * @phba: Pointer to HBA context object.
398 * @cmdiocbq: Pointer to command iocb.
399 * @rspiocbq: Pointer to response iocb.
401 * This function is the completion handler for iocbs issued using
402 * lpfc_bsg_rport_els_cmp function. This function is called by the
403 * ring event handler function without any lock held. This function
404 * can be called from both worker thread context and interrupt
405 * context. This function also can be called from other thread which
406 * cleans up the SLI layer objects.
407 * This function copies the contents of the response iocb to the
408 * response iocb memory object provided by the caller of
409 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
410 * sleeps for the iocb completion.
413 lpfc_bsg_rport_els_cmp(struct lpfc_hba
*phba
,
414 struct lpfc_iocbq
*cmdiocbq
,
415 struct lpfc_iocbq
*rspiocbq
)
417 struct bsg_job_data
*dd_data
;
418 struct fc_bsg_job
*job
;
420 struct lpfc_nodelist
*ndlp
;
421 struct lpfc_dmabuf
*pbuflist
= NULL
;
422 struct fc_bsg_ctels_reply
*els_reply
;
427 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
428 dd_data
= cmdiocbq
->context1
;
429 /* normal completion and timeout crossed paths, already done */
431 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
435 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
436 if (cmdiocbq
->context2
&& rspiocbq
)
437 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
438 &rspiocbq
->iocb
, sizeof(IOCB_t
));
440 job
= dd_data
->context_un
.iocb
.set_job
;
441 cmdiocbq
= dd_data
->context_un
.iocb
.cmdiocbq
;
442 rspiocbq
= dd_data
->context_un
.iocb
.rspiocbq
;
443 rsp
= &rspiocbq
->iocb
;
444 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
446 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
447 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
448 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
449 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
451 if (job
->reply
->result
== -EAGAIN
)
453 else if (rsp
->ulpStatus
== IOSTAT_SUCCESS
)
454 job
->reply
->reply_payload_rcv_len
=
455 rsp
->un
.elsreq64
.bdl
.bdeSize
;
456 else if (rsp
->ulpStatus
== IOSTAT_LS_RJT
) {
457 job
->reply
->reply_payload_rcv_len
=
458 sizeof(struct fc_bsg_ctels_reply
);
459 /* LS_RJT data returned in word 4 */
460 rjt_data
= (uint8_t *)&rsp
->un
.ulpWord
[4];
461 els_reply
= &job
->reply
->reply_data
.ctels_reply
;
462 els_reply
->status
= FC_CTELS_STATUS_REJECT
;
463 els_reply
->rjt_data
.action
= rjt_data
[3];
464 els_reply
->rjt_data
.reason_code
= rjt_data
[2];
465 els_reply
->rjt_data
.reason_explanation
= rjt_data
[1];
466 els_reply
->rjt_data
.vendor_unique
= rjt_data
[0];
470 pbuflist
= (struct lpfc_dmabuf
*) cmdiocbq
->context3
;
471 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
472 lpfc_sli_release_iocbq(phba
, rspiocbq
);
473 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
476 /* make error code available to userspace */
477 job
->reply
->result
= rc
;
479 /* complete the job back to userspace */
481 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
486 * lpfc_bsg_rport_els - send an ELS command from a bsg request
487 * @job: fc_bsg_job to handle
490 lpfc_bsg_rport_els(struct fc_bsg_job
*job
)
492 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
493 struct lpfc_hba
*phba
= vport
->phba
;
494 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
495 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
499 struct lpfc_iocbq
*rspiocbq
;
500 struct lpfc_iocbq
*cmdiocbq
;
503 struct lpfc_dmabuf
*pcmd
;
504 struct lpfc_dmabuf
*prsp
;
505 struct lpfc_dmabuf
*pbuflist
= NULL
;
506 struct ulp_bde64
*bpl
;
509 struct scatterlist
*sgel
= NULL
;
512 struct bsg_job_data
*dd_data
;
516 /* in case no data is transferred */
517 job
->reply
->reply_payload_rcv_len
= 0;
519 /* allocate our bsg tracking structure */
520 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
522 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
523 "2735 Failed allocation of dd_data\n");
528 if (!lpfc_nlp_get(ndlp
)) {
533 elscmd
= job
->request
->rqst_data
.r_els
.els_code
;
534 cmdsize
= job
->request_payload
.payload_len
;
535 rspsize
= job
->reply_payload
.payload_len
;
536 rspiocbq
= lpfc_sli_get_iocbq(phba
);
543 rsp
= &rspiocbq
->iocb
;
546 cmdiocbq
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
,
547 ndlp
->nlp_DID
, elscmd
);
553 /* prep els iocb set context1 to the ndlp, context2 to the command
554 * dmabuf, context3 holds the data dmabuf
556 pcmd
= (struct lpfc_dmabuf
*) cmdiocbq
->context2
;
557 prsp
= (struct lpfc_dmabuf
*) pcmd
->list
.next
;
558 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
560 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
562 cmdiocbq
->context2
= NULL
;
564 pbuflist
= (struct lpfc_dmabuf
*) cmdiocbq
->context3
;
565 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
567 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
568 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
569 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
570 busaddr
= sg_dma_address(sgel
);
571 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
572 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
573 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
574 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
575 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
579 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
580 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
581 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
582 busaddr
= sg_dma_address(sgel
);
583 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
584 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
585 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
586 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
587 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
590 cmdiocbq
->iocb
.un
.elsreq64
.bdl
.bdeSize
=
591 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
592 cmdiocbq
->iocb
.ulpContext
= rpi
;
593 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
594 cmdiocbq
->context1
= NULL
;
595 cmdiocbq
->context2
= NULL
;
597 cmdiocbq
->iocb_cmpl
= lpfc_bsg_rport_els_cmp
;
598 cmdiocbq
->context1
= dd_data
;
599 cmdiocbq
->context2
= rspiocbq
;
600 dd_data
->type
= TYPE_IOCB
;
601 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
602 dd_data
->context_un
.iocb
.rspiocbq
= rspiocbq
;
603 dd_data
->context_un
.iocb
.set_job
= job
;
604 dd_data
->context_un
.iocb
.bmp
= NULL
;
605 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
607 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
608 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
612 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
613 writel(creg_val
, phba
->HCregaddr
);
614 readl(phba
->HCregaddr
); /* flush */
616 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
618 if (rc
== IOCB_SUCCESS
)
619 return 0; /* done for now */
620 else if (rc
== IOCB_BUSY
)
626 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
627 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
628 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
629 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
631 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
633 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
636 lpfc_sli_release_iocbq(phba
, rspiocbq
);
642 /* make error code available to userspace */
643 job
->reply
->result
= rc
;
649 * lpfc_bsg_event_free - frees an allocated event structure
650 * @kref: Pointer to a kref.
652 * Called from kref_put. Back cast the kref into an event structure address.
653 * Free any events to get, delete associated nodes, free any events to see,
654 * free any data then free the event itself.
657 lpfc_bsg_event_free(struct kref
*kref
)
659 struct lpfc_bsg_event
*evt
= container_of(kref
, struct lpfc_bsg_event
,
661 struct event_data
*ed
;
663 list_del(&evt
->node
);
665 while (!list_empty(&evt
->events_to_get
)) {
666 ed
= list_entry(evt
->events_to_get
.next
, typeof(*ed
), node
);
672 while (!list_empty(&evt
->events_to_see
)) {
673 ed
= list_entry(evt
->events_to_see
.next
, typeof(*ed
), node
);
683 * lpfc_bsg_event_ref - increments the kref for an event
684 * @evt: Pointer to an event structure.
687 lpfc_bsg_event_ref(struct lpfc_bsg_event
*evt
)
689 kref_get(&evt
->kref
);
693 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
694 * @evt: Pointer to an event structure.
697 lpfc_bsg_event_unref(struct lpfc_bsg_event
*evt
)
699 kref_put(&evt
->kref
, lpfc_bsg_event_free
);
703 * lpfc_bsg_event_new - allocate and initialize a event structure
704 * @ev_mask: Mask of events.
705 * @ev_reg_id: Event reg id.
706 * @ev_req_id: Event request id.
708 static struct lpfc_bsg_event
*
709 lpfc_bsg_event_new(uint32_t ev_mask
, int ev_reg_id
, uint32_t ev_req_id
)
711 struct lpfc_bsg_event
*evt
= kzalloc(sizeof(*evt
), GFP_KERNEL
);
716 INIT_LIST_HEAD(&evt
->events_to_get
);
717 INIT_LIST_HEAD(&evt
->events_to_see
);
718 evt
->type_mask
= ev_mask
;
719 evt
->req_id
= ev_req_id
;
720 evt
->reg_id
= ev_reg_id
;
721 evt
->wait_time_stamp
= jiffies
;
722 init_waitqueue_head(&evt
->wq
);
723 kref_init(&evt
->kref
);
728 * diag_cmd_data_free - Frees an lpfc dma buffer extension
729 * @phba: Pointer to HBA context object.
730 * @mlist: Pointer to an lpfc dma buffer extension.
733 diag_cmd_data_free(struct lpfc_hba
*phba
, struct lpfc_dmabufext
*mlist
)
735 struct lpfc_dmabufext
*mlast
;
736 struct pci_dev
*pcidev
;
737 struct list_head head
, *curr
, *next
;
739 if ((!mlist
) || (!lpfc_is_link_up(phba
) &&
740 (phba
->link_flag
& LS_LOOPBACK_MODE
))) {
744 pcidev
= phba
->pcidev
;
745 list_add_tail(&head
, &mlist
->dma
.list
);
747 list_for_each_safe(curr
, next
, &head
) {
748 mlast
= list_entry(curr
, struct lpfc_dmabufext
, dma
.list
);
750 dma_free_coherent(&pcidev
->dev
,
760 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
765 * This function is called when an unsolicited CT command is received. It
766 * forwards the event to any processes registered to receive CT events.
769 lpfc_bsg_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
770 struct lpfc_iocbq
*piocbq
)
772 uint32_t evt_req_id
= 0;
775 struct lpfc_dmabuf
*dmabuf
= NULL
;
776 struct lpfc_bsg_event
*evt
;
777 struct event_data
*evt_dat
= NULL
;
778 struct lpfc_iocbq
*iocbq
;
780 struct list_head head
;
781 struct ulp_bde64
*bde
;
784 struct lpfc_dmabuf
*bdeBuf1
= piocbq
->context2
;
785 struct lpfc_dmabuf
*bdeBuf2
= piocbq
->context3
;
786 struct lpfc_hbq_entry
*hbqe
;
787 struct lpfc_sli_ct_request
*ct_req
;
788 struct fc_bsg_job
*job
= NULL
;
792 INIT_LIST_HEAD(&head
);
793 list_add_tail(&head
, &piocbq
->list
);
795 if (piocbq
->iocb
.ulpBdeCount
== 0 ||
796 piocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
== 0)
797 goto error_ct_unsol_exit
;
799 if (phba
->link_state
== LPFC_HBA_ERROR
||
800 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)))
801 goto error_ct_unsol_exit
;
803 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
806 dma_addr
= getPaddr(piocbq
->iocb
.un
.cont64
[0].addrHigh
,
807 piocbq
->iocb
.un
.cont64
[0].addrLow
);
808 dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
, dma_addr
);
811 goto error_ct_unsol_exit
;
812 ct_req
= (struct lpfc_sli_ct_request
*)dmabuf
->virt
;
813 evt_req_id
= ct_req
->FsType
;
814 cmd
= ct_req
->CommandResponse
.bits
.CmdRsp
;
815 len
= ct_req
->CommandResponse
.bits
.Size
;
816 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
817 lpfc_sli_ringpostbuf_put(phba
, pring
, dmabuf
);
819 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
820 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
821 if (!(evt
->type_mask
& FC_REG_CT_EVENT
) ||
822 evt
->req_id
!= evt_req_id
)
825 lpfc_bsg_event_ref(evt
);
826 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
827 evt_dat
= kzalloc(sizeof(*evt_dat
), GFP_KERNEL
);
828 if (evt_dat
== NULL
) {
829 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
830 lpfc_bsg_event_unref(evt
);
831 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
832 "2614 Memory allocation failed for "
837 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
838 /* take accumulated byte count from the last iocbq */
839 iocbq
= list_entry(head
.prev
, typeof(*iocbq
), list
);
840 evt_dat
->len
= iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
;
842 list_for_each_entry(iocbq
, &head
, list
) {
843 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++)
845 iocbq
->iocb
.un
.cont64
[i
].tus
.f
.bdeSize
;
849 evt_dat
->data
= kzalloc(evt_dat
->len
, GFP_KERNEL
);
850 if (evt_dat
->data
== NULL
) {
851 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
852 "2615 Memory allocation failed for "
853 "CT event data, size %d\n",
856 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
857 lpfc_bsg_event_unref(evt
);
858 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
859 goto error_ct_unsol_exit
;
862 list_for_each_entry(iocbq
, &head
, list
) {
864 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
865 bdeBuf1
= iocbq
->context2
;
866 bdeBuf2
= iocbq
->context3
;
868 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++) {
869 if (phba
->sli3_options
&
870 LPFC_SLI3_HBQ_ENABLED
) {
872 hbqe
= (struct lpfc_hbq_entry
*)
873 &iocbq
->iocb
.un
.ulpWord
[0];
874 size
= hbqe
->bde
.tus
.f
.bdeSize
;
877 hbqe
= (struct lpfc_hbq_entry
*)
880 size
= hbqe
->bde
.tus
.f
.bdeSize
;
883 if ((offset
+ size
) > evt_dat
->len
)
884 size
= evt_dat
->len
- offset
;
886 size
= iocbq
->iocb
.un
.cont64
[i
].
888 bde
= &iocbq
->iocb
.un
.cont64
[i
];
889 dma_addr
= getPaddr(bde
->addrHigh
,
891 dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
895 lpfc_printf_log(phba
, KERN_ERR
,
896 LOG_LIBDFC
, "2616 No dmabuf "
897 "found for iocbq 0x%p\n",
899 kfree(evt_dat
->data
);
901 spin_lock_irqsave(&phba
->ct_ev_lock
,
903 lpfc_bsg_event_unref(evt
);
904 spin_unlock_irqrestore(
905 &phba
->ct_ev_lock
, flags
);
906 goto error_ct_unsol_exit
;
908 memcpy((char *)(evt_dat
->data
) + offset
,
911 if (evt_req_id
!= SLI_CT_ELX_LOOPBACK
&&
912 !(phba
->sli3_options
&
913 LPFC_SLI3_HBQ_ENABLED
)) {
914 lpfc_sli_ringpostbuf_put(phba
, pring
,
918 case ELX_LOOPBACK_DATA
:
919 diag_cmd_data_free(phba
,
920 (struct lpfc_dmabufext
*)
923 case ELX_LOOPBACK_XRI_SETUP
:
924 if ((phba
->sli_rev
==
926 (phba
->sli3_options
&
927 LPFC_SLI3_HBQ_ENABLED
929 lpfc_in_buf_free(phba
,
932 lpfc_post_buffer(phba
,
938 if (!(phba
->sli3_options
&
939 LPFC_SLI3_HBQ_ENABLED
))
940 lpfc_post_buffer(phba
,
949 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
950 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
951 evt_dat
->immed_dat
= phba
->ctx_idx
;
952 phba
->ctx_idx
= (phba
->ctx_idx
+ 1) % 64;
953 /* Provide warning for over-run of the ct_ctx array */
954 if (phba
->ct_ctx
[evt_dat
->immed_dat
].flags
&
956 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
957 "2717 CT context array entry "
958 "[%d] over-run: oxid:x%x, "
959 "sid:x%x\n", phba
->ctx_idx
,
961 evt_dat
->immed_dat
].oxid
,
963 evt_dat
->immed_dat
].SID
);
964 phba
->ct_ctx
[evt_dat
->immed_dat
].rxid
=
965 piocbq
->iocb
.ulpContext
;
966 phba
->ct_ctx
[evt_dat
->immed_dat
].oxid
=
967 piocbq
->iocb
.unsli3
.rcvsli3
.ox_id
;
968 phba
->ct_ctx
[evt_dat
->immed_dat
].SID
=
969 piocbq
->iocb
.un
.rcvels
.remoteID
;
970 phba
->ct_ctx
[evt_dat
->immed_dat
].flags
= UNSOL_VALID
;
972 evt_dat
->immed_dat
= piocbq
->iocb
.ulpContext
;
974 evt_dat
->type
= FC_REG_CT_EVENT
;
975 list_add(&evt_dat
->node
, &evt
->events_to_see
);
976 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
) {
977 wake_up_interruptible(&evt
->wq
);
978 lpfc_bsg_event_unref(evt
);
982 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
983 lpfc_bsg_event_unref(evt
);
988 job
->reply
->reply_payload_rcv_len
= size
;
989 /* make error code available to userspace */
990 job
->reply
->result
= 0;
992 /* complete the job back to userspace */
993 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
995 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
998 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1000 error_ct_unsol_exit
:
1001 if (!list_empty(&head
))
1003 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
)
1009 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1010 * @job: SET_EVENT fc_bsg_job
1013 lpfc_bsg_hba_set_event(struct fc_bsg_job
*job
)
1015 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1016 struct lpfc_hba
*phba
= vport
->phba
;
1017 struct set_ct_event
*event_req
;
1018 struct lpfc_bsg_event
*evt
;
1020 struct bsg_job_data
*dd_data
= NULL
;
1022 unsigned long flags
;
1024 if (job
->request_len
<
1025 sizeof(struct fc_bsg_request
) + sizeof(struct set_ct_event
)) {
1026 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1027 "2612 Received SET_CT_EVENT below minimum "
1033 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1034 if (dd_data
== NULL
) {
1035 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1036 "2734 Failed allocation of dd_data\n");
1041 event_req
= (struct set_ct_event
*)
1042 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1043 ev_mask
= ((uint32_t)(unsigned long)event_req
->type_mask
&
1045 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1046 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1047 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1048 lpfc_bsg_event_ref(evt
);
1049 evt
->wait_time_stamp
= jiffies
;
1053 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1055 if (&evt
->node
== &phba
->ct_ev_waiters
) {
1056 /* no event waiting struct yet - first call */
1057 evt
= lpfc_bsg_event_new(ev_mask
, event_req
->ev_reg_id
,
1058 event_req
->ev_req_id
);
1060 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1061 "2617 Failed allocation of event "
1067 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1068 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1069 lpfc_bsg_event_ref(evt
);
1070 evt
->wait_time_stamp
= jiffies
;
1071 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1074 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1076 dd_data
->type
= TYPE_EVT
;
1077 dd_data
->context_un
.evt
= evt
;
1078 evt
->set_job
= job
; /* for unsolicited command */
1079 job
->dd_data
= dd_data
; /* for fc transport timeout callback*/
1080 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1081 return 0; /* call job done later */
1084 if (dd_data
!= NULL
)
1087 job
->dd_data
= NULL
;
1092 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1093 * @job: GET_EVENT fc_bsg_job
1096 lpfc_bsg_hba_get_event(struct fc_bsg_job
*job
)
1098 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1099 struct lpfc_hba
*phba
= vport
->phba
;
1100 struct get_ct_event
*event_req
;
1101 struct get_ct_event_reply
*event_reply
;
1102 struct lpfc_bsg_event
*evt
;
1103 struct event_data
*evt_dat
= NULL
;
1104 unsigned long flags
;
1107 if (job
->request_len
<
1108 sizeof(struct fc_bsg_request
) + sizeof(struct get_ct_event
)) {
1109 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1110 "2613 Received GET_CT_EVENT request below "
1116 event_req
= (struct get_ct_event
*)
1117 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1119 event_reply
= (struct get_ct_event_reply
*)
1120 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
1121 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1122 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1123 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1124 if (list_empty(&evt
->events_to_get
))
1126 lpfc_bsg_event_ref(evt
);
1127 evt
->wait_time_stamp
= jiffies
;
1128 evt_dat
= list_entry(evt
->events_to_get
.prev
,
1129 struct event_data
, node
);
1130 list_del(&evt_dat
->node
);
1134 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1136 /* The app may continue to ask for event data until it gets
1137 * an error indicating that there isn't anymore
1139 if (evt_dat
== NULL
) {
1140 job
->reply
->reply_payload_rcv_len
= 0;
1145 if (evt_dat
->len
> job
->request_payload
.payload_len
) {
1146 evt_dat
->len
= job
->request_payload
.payload_len
;
1147 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1148 "2618 Truncated event data at %d "
1150 job
->request_payload
.payload_len
);
1153 event_reply
->type
= evt_dat
->type
;
1154 event_reply
->immed_data
= evt_dat
->immed_dat
;
1155 if (evt_dat
->len
> 0)
1156 job
->reply
->reply_payload_rcv_len
=
1157 sg_copy_from_buffer(job
->request_payload
.sg_list
,
1158 job
->request_payload
.sg_cnt
,
1159 evt_dat
->data
, evt_dat
->len
);
1161 job
->reply
->reply_payload_rcv_len
= 0;
1164 kfree(evt_dat
->data
);
1168 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1169 lpfc_bsg_event_unref(evt
);
1170 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1171 job
->dd_data
= NULL
;
1172 job
->reply
->result
= 0;
1177 job
->dd_data
= NULL
;
1178 job
->reply
->result
= rc
;
1183 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1184 * @phba: Pointer to HBA context object.
1185 * @cmdiocbq: Pointer to command iocb.
1186 * @rspiocbq: Pointer to response iocb.
1188 * This function is the completion handler for iocbs issued using
1189 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1190 * ring event handler function without any lock held. This function
1191 * can be called from both worker thread context and interrupt
1192 * context. This function also can be called from other thread which
1193 * cleans up the SLI layer objects.
1194 * This function copy the contents of the response iocb to the
1195 * response iocb memory object provided by the caller of
1196 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1197 * sleeps for the iocb completion.
1200 lpfc_issue_ct_rsp_cmp(struct lpfc_hba
*phba
,
1201 struct lpfc_iocbq
*cmdiocbq
,
1202 struct lpfc_iocbq
*rspiocbq
)
1204 struct bsg_job_data
*dd_data
;
1205 struct fc_bsg_job
*job
;
1207 struct lpfc_dmabuf
*bmp
;
1208 struct lpfc_nodelist
*ndlp
;
1209 unsigned long flags
;
1212 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1213 dd_data
= cmdiocbq
->context2
;
1214 /* normal completion and timeout crossed paths, already done */
1216 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1220 job
= dd_data
->context_un
.iocb
.set_job
;
1221 bmp
= dd_data
->context_un
.iocb
.bmp
;
1222 rsp
= &rspiocbq
->iocb
;
1223 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
1225 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1226 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1228 if (rsp
->ulpStatus
) {
1229 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1230 switch (rsp
->un
.ulpWord
[4] & 0xff) {
1231 case IOERR_SEQUENCE_TIMEOUT
:
1234 case IOERR_INVALID_RPI
:
1244 job
->reply
->reply_payload_rcv_len
=
1245 rsp
->un
.genreq64
.bdl
.bdeSize
;
1247 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1248 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1252 /* make error code available to userspace */
1253 job
->reply
->result
= rc
;
1254 job
->dd_data
= NULL
;
1255 /* complete the job back to userspace */
1257 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1262 * lpfc_issue_ct_rsp - issue a ct response
1263 * @phba: Pointer to HBA context object.
1264 * @job: Pointer to the job object.
1265 * @tag: tag index value into the ports context exchange array.
1266 * @bmp: Pointer to a dma buffer descriptor.
1267 * @num_entry: Number of enties in the bde.
1270 lpfc_issue_ct_rsp(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
, uint32_t tag
,
1271 struct lpfc_dmabuf
*bmp
, int num_entry
)
1274 struct lpfc_iocbq
*ctiocb
= NULL
;
1276 struct lpfc_nodelist
*ndlp
= NULL
;
1277 struct bsg_job_data
*dd_data
;
1280 /* allocate our bsg tracking structure */
1281 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1283 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1284 "2736 Failed allocation of dd_data\n");
1289 /* Allocate buffer for command iocb */
1290 ctiocb
= lpfc_sli_get_iocbq(phba
);
1296 icmd
= &ctiocb
->iocb
;
1297 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
1298 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
1299 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
1300 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1301 icmd
->un
.xseq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
1302 icmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
1303 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1304 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_SOL_CTL
;
1305 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1307 /* Fill in rest of iocb */
1308 icmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
1309 icmd
->ulpBdeCount
= 1;
1311 icmd
->ulpClass
= CLASS3
;
1312 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1313 /* Do not issue unsol response if oxid not marked as valid */
1314 if (!(phba
->ct_ctx
[tag
].flags
& UNSOL_VALID
)) {
1316 goto issue_ct_rsp_exit
;
1318 icmd
->ulpContext
= phba
->ct_ctx
[tag
].rxid
;
1319 icmd
->unsli3
.rcvsli3
.ox_id
= phba
->ct_ctx
[tag
].oxid
;
1320 ndlp
= lpfc_findnode_did(phba
->pport
, phba
->ct_ctx
[tag
].SID
);
1322 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1323 "2721 ndlp null for oxid %x SID %x\n",
1325 phba
->ct_ctx
[tag
].SID
);
1327 goto issue_ct_rsp_exit
;
1330 /* Check if the ndlp is active */
1331 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1333 goto issue_ct_rsp_exit
;
1336 /* get a refernece count so the ndlp doesn't go away while
1339 if (!lpfc_nlp_get(ndlp
)) {
1341 goto issue_ct_rsp_exit
;
1344 icmd
->un
.ulpWord
[3] =
1345 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
1347 /* The exchange is done, mark the entry as invalid */
1348 phba
->ct_ctx
[tag
].flags
&= ~UNSOL_VALID
;
1350 icmd
->ulpContext
= (ushort
) tag
;
1352 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
1354 /* Xmit CT response on exchange <xid> */
1355 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1356 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1357 icmd
->ulpContext
, icmd
->ulpIoTag
, tag
, phba
->link_state
);
1359 ctiocb
->iocb_cmpl
= NULL
;
1360 ctiocb
->iocb_flag
|= LPFC_IO_LIBDFC
;
1361 ctiocb
->vport
= phba
->pport
;
1362 ctiocb
->context3
= bmp
;
1364 ctiocb
->iocb_cmpl
= lpfc_issue_ct_rsp_cmp
;
1365 ctiocb
->context2
= dd_data
;
1366 ctiocb
->context1
= ndlp
;
1367 dd_data
->type
= TYPE_IOCB
;
1368 dd_data
->context_un
.iocb
.cmdiocbq
= ctiocb
;
1369 dd_data
->context_un
.iocb
.rspiocbq
= NULL
;
1370 dd_data
->context_un
.iocb
.set_job
= job
;
1371 dd_data
->context_un
.iocb
.bmp
= bmp
;
1372 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
1374 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1375 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1377 goto issue_ct_rsp_exit
;
1379 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1380 writel(creg_val
, phba
->HCregaddr
);
1381 readl(phba
->HCregaddr
); /* flush */
1384 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
1386 if (rc
== IOCB_SUCCESS
)
1387 return 0; /* done for now */
1390 lpfc_sli_release_iocbq(phba
, ctiocb
);
1398 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1399 * @job: SEND_MGMT_RESP fc_bsg_job
1402 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job
*job
)
1404 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1405 struct lpfc_hba
*phba
= vport
->phba
;
1406 struct send_mgmt_resp
*mgmt_resp
= (struct send_mgmt_resp
*)
1407 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1408 struct ulp_bde64
*bpl
;
1409 struct lpfc_dmabuf
*bmp
= NULL
;
1410 struct scatterlist
*sgel
= NULL
;
1414 uint32_t tag
= mgmt_resp
->tag
;
1415 unsigned long reqbfrcnt
=
1416 (unsigned long)job
->request_payload
.payload_len
;
1419 /* in case no data is transferred */
1420 job
->reply
->reply_payload_rcv_len
= 0;
1422 if (!reqbfrcnt
|| (reqbfrcnt
> (80 * BUF_SZ_4K
))) {
1424 goto send_mgmt_rsp_exit
;
1427 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1430 goto send_mgmt_rsp_exit
;
1433 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
1436 goto send_mgmt_rsp_free_bmp
;
1439 INIT_LIST_HEAD(&bmp
->list
);
1440 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1441 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1442 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1443 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
1444 busaddr
= sg_dma_address(sgel
);
1445 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1446 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1447 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
1448 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
1449 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
1453 rc
= lpfc_issue_ct_rsp(phba
, job
, tag
, bmp
, request_nseg
);
1455 if (rc
== IOCB_SUCCESS
)
1456 return 0; /* done for now */
1458 /* TBD need to handle a timeout */
1459 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1460 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1462 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1464 send_mgmt_rsp_free_bmp
:
1467 /* make error code available to userspace */
1468 job
->reply
->result
= rc
;
1469 job
->dd_data
= NULL
;
1474 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1475 * @phba: Pointer to HBA context object.
1477 * This function is responsible for preparing driver for diag loopback
1481 lpfc_bsg_diag_mode_enter(struct lpfc_hba
*phba
)
1483 struct lpfc_vport
**vports
;
1484 struct Scsi_Host
*shost
;
1485 struct lpfc_sli
*psli
;
1486 struct lpfc_sli_ring
*pring
;
1493 pring
= &psli
->ring
[LPFC_FCP_RING
];
1497 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1498 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
1499 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
1502 vports
= lpfc_create_vport_work_array(phba
);
1504 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1505 shost
= lpfc_shost_from_vport(vports
[i
]);
1506 scsi_block_requests(shost
);
1508 lpfc_destroy_vport_work_array(phba
, vports
);
1510 shost
= lpfc_shost_from_vport(phba
->pport
);
1511 scsi_block_requests(shost
);
1514 while (pring
->txcmplq_cnt
) {
1515 if (i
++ > 500) /* wait up to 5 seconds */
1523 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1524 * @phba: Pointer to HBA context object.
1526 * This function is responsible for driver exit processing of setting up
1527 * diag loopback mode on device.
1530 lpfc_bsg_diag_mode_exit(struct lpfc_hba
*phba
)
1532 struct Scsi_Host
*shost
;
1533 struct lpfc_vport
**vports
;
1536 vports
= lpfc_create_vport_work_array(phba
);
1538 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1539 shost
= lpfc_shost_from_vport(vports
[i
]);
1540 scsi_unblock_requests(shost
);
1542 lpfc_destroy_vport_work_array(phba
, vports
);
1544 shost
= lpfc_shost_from_vport(phba
->pport
);
1545 scsi_unblock_requests(shost
);
1551 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1552 * @phba: Pointer to HBA context object.
1553 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1555 * This function is responsible for placing an sli3 port into diagnostic
1556 * loopback mode in order to perform a diagnostic loopback test.
1557 * All new scsi requests are blocked, a small delay is used to allow the
1558 * scsi requests to complete then the link is brought down. If the link is
1559 * is placed in loopback mode then scsi requests are again allowed
1560 * so the scsi mid-layer doesn't give up on the port.
1561 * All of this is done in-line.
1564 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1566 struct diag_mode_set
*loopback_mode
;
1567 uint32_t link_flags
;
1569 LPFC_MBOXQ_t
*pmboxq
;
1570 int mbxstatus
= MBX_SUCCESS
;
1574 /* no data to return just the return code */
1575 job
->reply
->reply_payload_rcv_len
= 0;
1577 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1578 sizeof(struct diag_mode_set
)) {
1579 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1580 "2738 Received DIAG MODE request size:%d "
1581 "below the minimum size:%d\n",
1583 (int)(sizeof(struct fc_bsg_request
) +
1584 sizeof(struct diag_mode_set
)));
1589 rc
= lpfc_bsg_diag_mode_enter(phba
);
1593 /* bring the link to diagnostic mode */
1594 loopback_mode
= (struct diag_mode_set
*)
1595 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1596 link_flags
= loopback_mode
->type
;
1597 timeout
= loopback_mode
->timeout
* 100;
1599 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1602 goto loopback_mode_exit
;
1604 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1605 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1606 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1608 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1610 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0)) {
1611 /* wait for link down before proceeding */
1613 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1614 if (i
++ > timeout
) {
1616 goto loopback_mode_exit
;
1622 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1623 if (link_flags
== INTERNAL_LOOP_BACK
)
1624 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
1626 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
=
1627 FLAGS_TOPOLOGY_MODE_LOOP
;
1629 pmboxq
->u
.mb
.mbxCommand
= MBX_INIT_LINK
;
1630 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1632 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1635 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1638 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1639 /* wait for the link attention interrupt */
1643 while (phba
->link_state
!= LPFC_HBA_READY
) {
1644 if (i
++ > timeout
) {
1657 lpfc_bsg_diag_mode_exit(phba
);
1660 * Let SLI layer release mboxq if mbox command completed after timeout.
1662 if (mbxstatus
!= MBX_TIMEOUT
)
1663 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1666 /* make error code available to userspace */
1667 job
->reply
->result
= rc
;
1668 /* complete the job back to userspace if no error */
1675 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1676 * @phba: Pointer to HBA context object.
1677 * @diag: Flag for set link to diag or nomral operation state.
1679 * This function is responsible for issuing a sli4 mailbox command for setting
1680 * link to either diag state or normal operation state.
1683 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba
*phba
, uint32_t diag
)
1685 LPFC_MBOXQ_t
*pmboxq
;
1686 struct lpfc_mbx_set_link_diag_state
*link_diag_state
;
1687 uint32_t req_len
, alloc_len
;
1688 int mbxstatus
= MBX_SUCCESS
, rc
;
1690 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1694 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
1695 sizeof(struct lpfc_sli4_cfg_mhdr
));
1696 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1697 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
1698 req_len
, LPFC_SLI4_MBX_EMBED
);
1699 if (alloc_len
!= req_len
) {
1701 goto link_diag_state_set_out
;
1703 link_diag_state
= &pmboxq
->u
.mqe
.un
.link_diag_state
;
1704 bf_set(lpfc_mbx_set_diag_state_link_num
, &link_diag_state
->u
.req
,
1705 phba
->sli4_hba
.link_state
.number
);
1706 bf_set(lpfc_mbx_set_diag_state_link_type
, &link_diag_state
->u
.req
,
1707 phba
->sli4_hba
.link_state
.type
);
1709 bf_set(lpfc_mbx_set_diag_state_diag
,
1710 &link_diag_state
->u
.req
, 1);
1712 bf_set(lpfc_mbx_set_diag_state_diag
,
1713 &link_diag_state
->u
.req
, 0);
1715 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1717 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0))
1722 link_diag_state_set_out
:
1723 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1724 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1730 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
1731 * @phba: Pointer to HBA context object.
1732 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1734 * This function is responsible for placing an sli4 port into diagnostic
1735 * loopback mode in order to perform a diagnostic loopback test.
1738 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1740 struct diag_mode_set
*loopback_mode
;
1741 uint32_t link_flags
, timeout
, req_len
, alloc_len
;
1742 struct lpfc_mbx_set_link_diag_loopback
*link_diag_loopback
;
1743 LPFC_MBOXQ_t
*pmboxq
= NULL
;
1744 int mbxstatus
= MBX_SUCCESS
, i
, rc
= 0;
1746 /* no data to return just the return code */
1747 job
->reply
->reply_payload_rcv_len
= 0;
1749 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1750 sizeof(struct diag_mode_set
)) {
1751 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1752 "3011 Received DIAG MODE request size:%d "
1753 "below the minimum size:%d\n",
1755 (int)(sizeof(struct fc_bsg_request
) +
1756 sizeof(struct diag_mode_set
)));
1761 rc
= lpfc_bsg_diag_mode_enter(phba
);
1765 /* bring the link to diagnostic mode */
1766 loopback_mode
= (struct diag_mode_set
*)
1767 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1768 link_flags
= loopback_mode
->type
;
1769 timeout
= loopback_mode
->timeout
* 100;
1771 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
1773 goto loopback_mode_exit
;
1775 /* wait for link down before proceeding */
1777 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1778 if (i
++ > timeout
) {
1780 goto loopback_mode_exit
;
1784 /* set up loopback mode */
1785 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1788 goto loopback_mode_exit
;
1790 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_loopback
) -
1791 sizeof(struct lpfc_sli4_cfg_mhdr
));
1792 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1793 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK
,
1794 req_len
, LPFC_SLI4_MBX_EMBED
);
1795 if (alloc_len
!= req_len
) {
1797 goto loopback_mode_exit
;
1799 link_diag_loopback
= &pmboxq
->u
.mqe
.un
.link_diag_loopback
;
1800 bf_set(lpfc_mbx_set_diag_state_link_num
,
1801 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.link_state
.number
);
1802 bf_set(lpfc_mbx_set_diag_state_link_type
,
1803 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.link_state
.type
);
1804 if (link_flags
== INTERNAL_LOOP_BACK
)
1805 bf_set(lpfc_mbx_set_diag_lpbk_type
,
1806 &link_diag_loopback
->u
.req
,
1807 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL
);
1809 bf_set(lpfc_mbx_set_diag_lpbk_type
,
1810 &link_diag_loopback
->u
.req
,
1811 LPFC_DIAG_LOOPBACK_TYPE_EXTERNAL
);
1813 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1814 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1817 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1818 /* wait for the link attention interrupt */
1821 while (phba
->link_state
!= LPFC_HBA_READY
) {
1822 if (i
++ > timeout
) {
1831 lpfc_bsg_diag_mode_exit(phba
);
1834 * Let SLI layer release mboxq if mbox command completed after timeout.
1836 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1837 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1840 /* make error code available to userspace */
1841 job
->reply
->result
= rc
;
1842 /* complete the job back to userspace if no error */
1849 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
1850 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1852 * This function is responsible for responding to check and dispatch bsg diag
1853 * command from the user to proper driver action routines.
1856 lpfc_bsg_diag_loopback_mode(struct fc_bsg_job
*job
)
1858 struct Scsi_Host
*shost
;
1859 struct lpfc_vport
*vport
;
1860 struct lpfc_hba
*phba
;
1866 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1873 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1874 rc
= lpfc_sli3_bsg_diag_loopback_mode(phba
, job
);
1875 else if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1876 LPFC_SLI_INTF_IF_TYPE_2
)
1877 rc
= lpfc_sli4_bsg_diag_loopback_mode(phba
, job
);
1886 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
1887 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
1889 * This function is responsible for responding to check and dispatch bsg diag
1890 * command from the user to proper driver action routines.
1893 lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job
*job
)
1895 struct Scsi_Host
*shost
;
1896 struct lpfc_vport
*vport
;
1897 struct lpfc_hba
*phba
;
1903 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1910 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1912 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
1913 LPFC_SLI_INTF_IF_TYPE_2
)
1916 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
1919 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
1925 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
1926 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
1928 * This function is to perform SLI4 diag link test request from the user
1932 lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job
*job
)
1934 struct Scsi_Host
*shost
;
1935 struct lpfc_vport
*vport
;
1936 struct lpfc_hba
*phba
;
1937 LPFC_MBOXQ_t
*pmboxq
;
1938 struct sli4_link_diag
*link_diag_test_cmd
;
1939 uint32_t req_len
, alloc_len
;
1941 struct lpfc_mbx_run_link_diag_test
*run_link_diag_test
;
1942 union lpfc_sli4_cfg_shdr
*shdr
;
1943 uint32_t shdr_status
, shdr_add_status
;
1944 struct diag_status
*diag_status_reply
;
1945 int mbxstatus
, rc
= 0;
1952 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1963 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
1967 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
1968 LPFC_SLI_INTF_IF_TYPE_2
) {
1973 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1974 sizeof(struct sli4_link_diag
)) {
1975 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1976 "3013 Received LINK DIAG TEST request "
1977 " size:%d below the minimum size:%d\n",
1979 (int)(sizeof(struct fc_bsg_request
) +
1980 sizeof(struct sli4_link_diag
)));
1985 rc
= lpfc_bsg_diag_mode_enter(phba
);
1989 link_diag_test_cmd
= (struct sli4_link_diag
*)
1990 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1991 timeout
= link_diag_test_cmd
->timeout
* 100;
1993 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
1998 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2001 goto link_diag_test_exit
;
2004 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
2005 sizeof(struct lpfc_sli4_cfg_mhdr
));
2006 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2007 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
2008 req_len
, LPFC_SLI4_MBX_EMBED
);
2009 if (alloc_len
!= req_len
) {
2011 goto link_diag_test_exit
;
2013 run_link_diag_test
= &pmboxq
->u
.mqe
.un
.link_diag_test
;
2014 bf_set(lpfc_mbx_run_diag_test_link_num
, &run_link_diag_test
->u
.req
,
2015 phba
->sli4_hba
.link_state
.number
);
2016 bf_set(lpfc_mbx_run_diag_test_link_type
, &run_link_diag_test
->u
.req
,
2017 phba
->sli4_hba
.link_state
.type
);
2018 bf_set(lpfc_mbx_run_diag_test_test_id
, &run_link_diag_test
->u
.req
,
2019 link_diag_test_cmd
->test_id
);
2020 bf_set(lpfc_mbx_run_diag_test_loops
, &run_link_diag_test
->u
.req
,
2021 link_diag_test_cmd
->loops
);
2022 bf_set(lpfc_mbx_run_diag_test_test_ver
, &run_link_diag_test
->u
.req
,
2023 link_diag_test_cmd
->test_version
);
2024 bf_set(lpfc_mbx_run_diag_test_err_act
, &run_link_diag_test
->u
.req
,
2025 link_diag_test_cmd
->error_action
);
2027 mbxstatus
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2029 shdr
= (union lpfc_sli4_cfg_shdr
*)
2030 &pmboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2031 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
2032 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
2033 if (shdr_status
|| shdr_add_status
|| mbxstatus
) {
2034 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2035 "3010 Run link diag test mailbox failed with "
2036 "mbx_status x%x status x%x, add_status x%x\n",
2037 mbxstatus
, shdr_status
, shdr_add_status
);
2040 diag_status_reply
= (struct diag_status
*)
2041 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
2043 if (job
->reply_len
<
2044 sizeof(struct fc_bsg_request
) + sizeof(struct diag_status
)) {
2045 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2046 "3012 Received Run link diag test reply "
2047 "below minimum size (%d): reply_len:%d\n",
2048 (int)(sizeof(struct fc_bsg_request
) +
2049 sizeof(struct diag_status
)),
2055 diag_status_reply
->mbox_status
= mbxstatus
;
2056 diag_status_reply
->shdr_status
= shdr_status
;
2057 diag_status_reply
->shdr_add_status
= shdr_add_status
;
2059 link_diag_test_exit
:
2060 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2063 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2065 lpfc_bsg_diag_mode_exit(phba
);
2068 /* make error code available to userspace */
2069 job
->reply
->result
= rc
;
2070 /* complete the job back to userspace if no error */
2077 * lpfcdiag_loop_self_reg - obtains a remote port login id
2078 * @phba: Pointer to HBA context object
2079 * @rpi: Pointer to a remote port login id
2081 * This function obtains a remote port login id so the diag loopback test
2082 * can send and receive its own unsolicited CT command.
2084 static int lpfcdiag_loop_self_reg(struct lpfc_hba
*phba
, uint16_t *rpi
)
2087 struct lpfc_dmabuf
*dmabuff
;
2090 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2094 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2095 *rpi
= lpfc_sli4_alloc_rpi(phba
);
2096 status
= lpfc_reg_rpi(phba
, 0, phba
->pport
->fc_myDID
,
2097 (uint8_t *)&phba
->pport
->fc_sparam
, mbox
, *rpi
);
2099 mempool_free(mbox
, phba
->mbox_mem_pool
);
2100 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2101 lpfc_sli4_free_rpi(phba
, *rpi
);
2105 dmabuff
= (struct lpfc_dmabuf
*) mbox
->context1
;
2106 mbox
->context1
= NULL
;
2107 mbox
->context2
= NULL
;
2108 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2110 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2111 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2113 if (status
!= MBX_TIMEOUT
)
2114 mempool_free(mbox
, phba
->mbox_mem_pool
);
2115 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2116 lpfc_sli4_free_rpi(phba
, *rpi
);
2120 *rpi
= mbox
->u
.mb
.un
.varWords
[0];
2122 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2124 mempool_free(mbox
, phba
->mbox_mem_pool
);
2129 * lpfcdiag_loop_self_unreg - unregs from the rpi
2130 * @phba: Pointer to HBA context object
2131 * @rpi: Remote port login id
2133 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2135 static int lpfcdiag_loop_self_unreg(struct lpfc_hba
*phba
, uint16_t rpi
)
2140 /* Allocate mboxq structure */
2141 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2145 lpfc_unreg_login(phba
, 0, rpi
, mbox
);
2146 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2148 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2149 if (status
!= MBX_TIMEOUT
)
2150 mempool_free(mbox
, phba
->mbox_mem_pool
);
2153 mempool_free(mbox
, phba
->mbox_mem_pool
);
2154 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2155 lpfc_sli4_free_rpi(phba
, rpi
);
2160 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2161 * @phba: Pointer to HBA context object
2162 * @rpi: Remote port login id
2163 * @txxri: Pointer to transmit exchange id
2164 * @rxxri: Pointer to response exchabge id
2166 * This function obtains the transmit and receive ids required to send
2167 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2168 * flags are used to the unsolicted response handler is able to process
2169 * the ct command sent on the same port.
2171 static int lpfcdiag_loop_get_xri(struct lpfc_hba
*phba
, uint16_t rpi
,
2172 uint16_t *txxri
, uint16_t * rxxri
)
2174 struct lpfc_bsg_event
*evt
;
2175 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2177 struct lpfc_dmabuf
*dmabuf
;
2178 struct ulp_bde64
*bpl
= NULL
;
2179 struct lpfc_sli_ct_request
*ctreq
= NULL
;
2183 unsigned long flags
;
2187 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2188 SLI_CT_ELX_LOOPBACK
);
2192 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2193 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2194 lpfc_bsg_event_ref(evt
);
2195 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2197 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2198 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2200 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2202 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, 0, &dmabuf
->phys
);
2204 INIT_LIST_HEAD(&dmabuf
->list
);
2205 bpl
= (struct ulp_bde64
*) dmabuf
->virt
;
2206 memset(bpl
, 0, sizeof(*bpl
));
2207 ctreq
= (struct lpfc_sli_ct_request
*)(bpl
+ 1);
2209 le32_to_cpu(putPaddrHigh(dmabuf
->phys
+
2212 le32_to_cpu(putPaddrLow(dmabuf
->phys
+
2214 bpl
->tus
.f
.bdeFlags
= 0;
2215 bpl
->tus
.f
.bdeSize
= ELX_LOOPBACK_HEADER_SZ
;
2216 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2220 if (cmdiocbq
== NULL
|| rspiocbq
== NULL
||
2221 dmabuf
== NULL
|| bpl
== NULL
|| ctreq
== NULL
||
2222 dmabuf
->virt
== NULL
) {
2224 goto err_get_xri_exit
;
2227 cmd
= &cmdiocbq
->iocb
;
2228 rsp
= &rspiocbq
->iocb
;
2230 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2232 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2233 ctreq
->RevisionId
.bits
.InId
= 0;
2234 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2235 ctreq
->FsSubType
= 0;
2236 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_XRI_SETUP
;
2237 ctreq
->CommandResponse
.bits
.Size
= 0;
2240 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(dmabuf
->phys
);
2241 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(dmabuf
->phys
);
2242 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2243 cmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(*bpl
);
2245 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= LA
;
2246 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2247 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2248 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2250 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CR
;
2251 cmd
->ulpBdeCount
= 1;
2253 cmd
->ulpClass
= CLASS3
;
2254 cmd
->ulpContext
= rpi
;
2256 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2257 cmdiocbq
->vport
= phba
->pport
;
2259 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2261 (phba
->fc_ratov
* 2)
2262 + LPFC_DRVR_TIMEOUT
);
2265 goto err_get_xri_exit
;
2267 *txxri
= rsp
->ulpContext
;
2270 evt
->wait_time_stamp
= jiffies
;
2271 time_left
= wait_event_interruptible_timeout(
2272 evt
->wq
, !list_empty(&evt
->events_to_see
),
2273 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
2274 if (list_empty(&evt
->events_to_see
))
2275 ret_val
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
2277 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2278 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2279 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2280 *rxxri
= (list_entry(evt
->events_to_get
.prev
,
2281 typeof(struct event_data
),
2287 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2288 lpfc_bsg_event_unref(evt
); /* release ref */
2289 lpfc_bsg_event_unref(evt
); /* delete */
2290 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2294 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2298 if (cmdiocbq
&& (iocb_stat
!= IOCB_TIMEDOUT
))
2299 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2301 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2306 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2307 * @phba: Pointer to HBA context object
2309 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and.
2310 * retruns the pointer to the buffer.
2312 static struct lpfc_dmabuf
*
2313 lpfc_bsg_dma_page_alloc(struct lpfc_hba
*phba
)
2315 struct lpfc_dmabuf
*dmabuf
;
2316 struct pci_dev
*pcidev
= phba
->pcidev
;
2318 /* allocate dma buffer struct */
2319 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2323 INIT_LIST_HEAD(&dmabuf
->list
);
2325 /* now, allocate dma buffer */
2326 dmabuf
->virt
= dma_alloc_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2327 &(dmabuf
->phys
), GFP_KERNEL
);
2329 if (!dmabuf
->virt
) {
2333 memset((uint8_t *)dmabuf
->virt
, 0, BSG_MBOX_SIZE
);
2339 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2340 * @phba: Pointer to HBA context object.
2341 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2343 * This routine just simply frees a dma buffer and its associated buffer
2344 * descriptor referred by @dmabuf.
2347 lpfc_bsg_dma_page_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*dmabuf
)
2349 struct pci_dev
*pcidev
= phba
->pcidev
;
2355 dma_free_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2356 dmabuf
->virt
, dmabuf
->phys
);
2362 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2363 * @phba: Pointer to HBA context object.
2364 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2366 * This routine just simply frees all dma buffers and their associated buffer
2367 * descriptors referred by @dmabuf_list.
2370 lpfc_bsg_dma_page_list_free(struct lpfc_hba
*phba
,
2371 struct list_head
*dmabuf_list
)
2373 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
2375 if (list_empty(dmabuf_list
))
2378 list_for_each_entry_safe(dmabuf
, next_dmabuf
, dmabuf_list
, list
) {
2379 list_del_init(&dmabuf
->list
);
2380 lpfc_bsg_dma_page_free(phba
, dmabuf
);
2386 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2387 * @phba: Pointer to HBA context object
2388 * @bpl: Pointer to 64 bit bde structure
2389 * @size: Number of bytes to process
2390 * @nocopydata: Flag to copy user data into the allocated buffer
2392 * This function allocates page size buffers and populates an lpfc_dmabufext.
2393 * If allowed the user data pointed to with indataptr is copied into the kernel
2394 * memory. The chained list of page size buffers is returned.
2396 static struct lpfc_dmabufext
*
2397 diag_cmd_data_alloc(struct lpfc_hba
*phba
,
2398 struct ulp_bde64
*bpl
, uint32_t size
,
2401 struct lpfc_dmabufext
*mlist
= NULL
;
2402 struct lpfc_dmabufext
*dmp
;
2403 int cnt
, offset
= 0, i
= 0;
2404 struct pci_dev
*pcidev
;
2406 pcidev
= phba
->pcidev
;
2409 /* We get chunks of 4K */
2410 if (size
> BUF_SZ_4K
)
2415 /* allocate struct lpfc_dmabufext buffer header */
2416 dmp
= kmalloc(sizeof(struct lpfc_dmabufext
), GFP_KERNEL
);
2420 INIT_LIST_HEAD(&dmp
->dma
.list
);
2422 /* Queue it to a linked list */
2424 list_add_tail(&dmp
->dma
.list
, &mlist
->dma
.list
);
2428 /* allocate buffer */
2429 dmp
->dma
.virt
= dma_alloc_coherent(&pcidev
->dev
,
2440 bpl
->tus
.f
.bdeFlags
= 0;
2441 pci_dma_sync_single_for_device(phba
->pcidev
,
2442 dmp
->dma
.phys
, LPFC_BPL_SIZE
, PCI_DMA_TODEVICE
);
2445 memset((uint8_t *)dmp
->dma
.virt
, 0, cnt
);
2446 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2449 /* build buffer ptr list for IOCB */
2450 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dmp
->dma
.phys
));
2451 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dmp
->dma
.phys
));
2452 bpl
->tus
.f
.bdeSize
= (ushort
) cnt
;
2453 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2464 diag_cmd_data_free(phba
, mlist
);
2469 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2470 * @phba: Pointer to HBA context object
2471 * @rxxri: Receive exchange id
2472 * @len: Number of data bytes
2474 * This function allocates and posts a data buffer of sufficient size to receive
2475 * an unsolicted CT command.
2477 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba
*phba
, uint16_t rxxri
,
2480 struct lpfc_sli
*psli
= &phba
->sli
;
2481 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2482 struct lpfc_iocbq
*cmdiocbq
;
2484 struct list_head head
, *curr
, *next
;
2485 struct lpfc_dmabuf
*rxbmp
;
2486 struct lpfc_dmabuf
*dmp
;
2487 struct lpfc_dmabuf
*mp
[2] = {NULL
, NULL
};
2488 struct ulp_bde64
*rxbpl
= NULL
;
2490 struct lpfc_dmabufext
*rxbuffer
= NULL
;
2495 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2496 rxbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2497 if (rxbmp
!= NULL
) {
2498 rxbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &rxbmp
->phys
);
2500 INIT_LIST_HEAD(&rxbmp
->list
);
2501 rxbpl
= (struct ulp_bde64
*) rxbmp
->virt
;
2502 rxbuffer
= diag_cmd_data_alloc(phba
, rxbpl
, len
, 0);
2506 if (!cmdiocbq
|| !rxbmp
|| !rxbpl
|| !rxbuffer
) {
2508 goto err_post_rxbufs_exit
;
2511 /* Queue buffers for the receive exchange */
2512 num_bde
= (uint32_t)rxbuffer
->flag
;
2513 dmp
= &rxbuffer
->dma
;
2515 cmd
= &cmdiocbq
->iocb
;
2518 INIT_LIST_HEAD(&head
);
2519 list_add_tail(&head
, &dmp
->list
);
2520 list_for_each_safe(curr
, next
, &head
) {
2521 mp
[i
] = list_entry(curr
, struct lpfc_dmabuf
, list
);
2524 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2525 mp
[i
]->buffer_tag
= lpfc_sli_get_buffer_tag(phba
);
2526 cmd
->un
.quexri64cx
.buff
.bde
.addrHigh
=
2527 putPaddrHigh(mp
[i
]->phys
);
2528 cmd
->un
.quexri64cx
.buff
.bde
.addrLow
=
2529 putPaddrLow(mp
[i
]->phys
);
2530 cmd
->un
.quexri64cx
.buff
.bde
.tus
.f
.bdeSize
=
2531 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2532 cmd
->un
.quexri64cx
.buff
.buffer_tag
= mp
[i
]->buffer_tag
;
2533 cmd
->ulpCommand
= CMD_QUE_XRI64_CX
;
2536 cmd
->ulpBdeCount
= 1;
2537 cmd
->unsli3
.que_xri64cx_ext_words
.ebde_count
= 0;
2540 cmd
->un
.cont64
[i
].addrHigh
= putPaddrHigh(mp
[i
]->phys
);
2541 cmd
->un
.cont64
[i
].addrLow
= putPaddrLow(mp
[i
]->phys
);
2542 cmd
->un
.cont64
[i
].tus
.f
.bdeSize
=
2543 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2544 cmd
->ulpBdeCount
= ++i
;
2546 if ((--num_bde
> 0) && (i
< 2))
2549 cmd
->ulpCommand
= CMD_QUE_XRI_BUF64_CX
;
2553 cmd
->ulpClass
= CLASS3
;
2554 cmd
->ulpContext
= rxxri
;
2556 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
2558 if (iocb_stat
== IOCB_ERROR
) {
2559 diag_cmd_data_free(phba
,
2560 (struct lpfc_dmabufext
*)mp
[0]);
2562 diag_cmd_data_free(phba
,
2563 (struct lpfc_dmabufext
*)mp
[1]);
2564 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2566 goto err_post_rxbufs_exit
;
2569 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[0]);
2571 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[1]);
2575 /* The iocb was freed by lpfc_sli_issue_iocb */
2576 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2578 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2580 goto err_post_rxbufs_exit
;
2583 cmd
= &cmdiocbq
->iocb
;
2588 err_post_rxbufs_exit
:
2592 lpfc_mbuf_free(phba
, rxbmp
->virt
, rxbmp
->phys
);
2597 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2602 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
2603 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2605 * This function receives a user data buffer to be transmitted and received on
2606 * the same port, the link must be up and in loopback mode prior
2608 * 1. A kernel buffer is allocated to copy the user data into.
2609 * 2. The port registers with "itself".
2610 * 3. The transmit and receive exchange ids are obtained.
2611 * 4. The receive exchange id is posted.
2612 * 5. A new els loopback event is created.
2613 * 6. The command and response iocbs are allocated.
2614 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2616 * This function is meant to be called n times while the port is in loopback
2617 * so it is the apps responsibility to issue a reset to take the port out
2621 lpfc_bsg_diag_loopback_run(struct fc_bsg_job
*job
)
2623 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2624 struct lpfc_hba
*phba
= vport
->phba
;
2625 struct diag_mode_test
*diag_mode
;
2626 struct lpfc_bsg_event
*evt
;
2627 struct event_data
*evdat
;
2628 struct lpfc_sli
*psli
= &phba
->sli
;
2631 size_t segment_len
= 0, segment_offset
= 0, current_offset
= 0;
2633 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2635 struct lpfc_sli_ct_request
*ctreq
;
2636 struct lpfc_dmabuf
*txbmp
;
2637 struct ulp_bde64
*txbpl
= NULL
;
2638 struct lpfc_dmabufext
*txbuffer
= NULL
;
2639 struct list_head head
;
2640 struct lpfc_dmabuf
*curr
;
2641 uint16_t txxri
, rxxri
;
2643 uint8_t *ptr
= NULL
, *rx_databuf
= NULL
;
2647 unsigned long flags
;
2648 void *dataout
= NULL
;
2651 /* in case no data is returned return just the return code */
2652 job
->reply
->reply_payload_rcv_len
= 0;
2654 if (job
->request_len
<
2655 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_test
)) {
2656 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2657 "2739 Received DIAG TEST request below minimum "
2660 goto loopback_test_exit
;
2663 if (job
->request_payload
.payload_len
!=
2664 job
->reply_payload
.payload_len
) {
2666 goto loopback_test_exit
;
2669 diag_mode
= (struct diag_mode_test
*)
2670 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2672 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
2673 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
2674 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
2676 goto loopback_test_exit
;
2679 if (!lpfc_is_link_up(phba
) || !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
2681 goto loopback_test_exit
;
2684 size
= job
->request_payload
.payload_len
;
2685 full_size
= size
+ ELX_LOOPBACK_HEADER_SZ
; /* plus the header */
2687 if ((size
== 0) || (size
> 80 * BUF_SZ_4K
)) {
2689 goto loopback_test_exit
;
2692 if (full_size
>= BUF_SZ_4K
) {
2694 * Allocate memory for ioctl data. If buffer is bigger than 64k,
2695 * then we allocate 64k and re-use that buffer over and over to
2696 * xfer the whole block. This is because Linux kernel has a
2697 * problem allocating more than 120k of kernel space memory. Saw
2698 * problem with GET_FCPTARGETMAPPING...
2700 if (size
<= (64 * 1024))
2701 total_mem
= full_size
;
2703 total_mem
= 64 * 1024;
2705 /* Allocate memory for ioctl data */
2706 total_mem
= BUF_SZ_4K
;
2708 dataout
= kmalloc(total_mem
, GFP_KERNEL
);
2709 if (dataout
== NULL
) {
2711 goto loopback_test_exit
;
2715 ptr
+= ELX_LOOPBACK_HEADER_SZ
;
2716 sg_copy_to_buffer(job
->request_payload
.sg_list
,
2717 job
->request_payload
.sg_cnt
,
2719 rc
= lpfcdiag_loop_self_reg(phba
, &rpi
);
2721 goto loopback_test_exit
;
2723 rc
= lpfcdiag_loop_get_xri(phba
, rpi
, &txxri
, &rxxri
);
2725 lpfcdiag_loop_self_unreg(phba
, rpi
);
2726 goto loopback_test_exit
;
2729 rc
= lpfcdiag_loop_post_rxbufs(phba
, rxxri
, full_size
);
2731 lpfcdiag_loop_self_unreg(phba
, rpi
);
2732 goto loopback_test_exit
;
2735 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2736 SLI_CT_ELX_LOOPBACK
);
2738 lpfcdiag_loop_self_unreg(phba
, rpi
);
2740 goto loopback_test_exit
;
2743 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2744 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2745 lpfc_bsg_event_ref(evt
);
2746 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2748 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2749 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2750 txbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2753 txbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &txbmp
->phys
);
2755 INIT_LIST_HEAD(&txbmp
->list
);
2756 txbpl
= (struct ulp_bde64
*) txbmp
->virt
;
2757 txbuffer
= diag_cmd_data_alloc(phba
,
2758 txbpl
, full_size
, 0);
2762 if (!cmdiocbq
|| !rspiocbq
|| !txbmp
|| !txbpl
|| !txbuffer
||
2765 goto err_loopback_test_exit
;
2768 cmd
= &cmdiocbq
->iocb
;
2769 rsp
= &rspiocbq
->iocb
;
2771 INIT_LIST_HEAD(&head
);
2772 list_add_tail(&head
, &txbuffer
->dma
.list
);
2773 list_for_each_entry(curr
, &head
, list
) {
2774 segment_len
= ((struct lpfc_dmabufext
*)curr
)->size
;
2775 if (current_offset
== 0) {
2777 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2778 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2779 ctreq
->RevisionId
.bits
.InId
= 0;
2780 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2781 ctreq
->FsSubType
= 0;
2782 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_DATA
;
2783 ctreq
->CommandResponse
.bits
.Size
= size
;
2784 segment_offset
= ELX_LOOPBACK_HEADER_SZ
;
2788 BUG_ON(segment_offset
>= segment_len
);
2789 memcpy(curr
->virt
+ segment_offset
,
2790 ptr
+ current_offset
,
2791 segment_len
- segment_offset
);
2793 current_offset
+= segment_len
- segment_offset
;
2794 BUG_ON(current_offset
> size
);
2798 /* Build the XMIT_SEQUENCE iocb */
2800 num_bde
= (uint32_t)txbuffer
->flag
;
2802 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(txbmp
->phys
);
2803 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(txbmp
->phys
);
2804 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2805 cmd
->un
.xseq64
.bdl
.bdeSize
= (num_bde
* sizeof(struct ulp_bde64
));
2807 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
2808 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2809 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2810 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2812 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
2813 cmd
->ulpBdeCount
= 1;
2815 cmd
->ulpClass
= CLASS3
;
2816 cmd
->ulpContext
= txxri
;
2818 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2819 cmdiocbq
->vport
= phba
->pport
;
2821 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2822 rspiocbq
, (phba
->fc_ratov
* 2) +
2825 if ((iocb_stat
!= IOCB_SUCCESS
) || (rsp
->ulpStatus
!= IOCB_SUCCESS
)) {
2827 goto err_loopback_test_exit
;
2831 time_left
= wait_event_interruptible_timeout(
2832 evt
->wq
, !list_empty(&evt
->events_to_see
),
2833 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
2835 if (list_empty(&evt
->events_to_see
))
2836 rc
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
2838 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2839 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2840 evdat
= list_entry(evt
->events_to_get
.prev
,
2841 typeof(*evdat
), node
);
2842 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2843 rx_databuf
= evdat
->data
;
2844 if (evdat
->len
!= full_size
) {
2845 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2846 "1603 Loopback test did not receive expected "
2847 "data length. actual length 0x%x expected "
2849 evdat
->len
, full_size
);
2851 } else if (rx_databuf
== NULL
)
2855 /* skip over elx loopback header */
2856 rx_databuf
+= ELX_LOOPBACK_HEADER_SZ
;
2857 job
->reply
->reply_payload_rcv_len
=
2858 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
2859 job
->reply_payload
.sg_cnt
,
2861 job
->reply
->reply_payload_rcv_len
= size
;
2865 err_loopback_test_exit
:
2866 lpfcdiag_loop_self_unreg(phba
, rpi
);
2868 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2869 lpfc_bsg_event_unref(evt
); /* release ref */
2870 lpfc_bsg_event_unref(evt
); /* delete */
2871 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2873 if (cmdiocbq
!= NULL
)
2874 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2876 if (rspiocbq
!= NULL
)
2877 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2879 if (txbmp
!= NULL
) {
2880 if (txbpl
!= NULL
) {
2881 if (txbuffer
!= NULL
)
2882 diag_cmd_data_free(phba
, txbuffer
);
2883 lpfc_mbuf_free(phba
, txbmp
->virt
, txbmp
->phys
);
2890 /* make error code available to userspace */
2891 job
->reply
->result
= rc
;
2892 job
->dd_data
= NULL
;
2893 /* complete the job back to userspace if no error */
2900 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
2901 * @job: GET_DFC_REV fc_bsg_job
2904 lpfc_bsg_get_dfc_rev(struct fc_bsg_job
*job
)
2906 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2907 struct lpfc_hba
*phba
= vport
->phba
;
2908 struct get_mgmt_rev
*event_req
;
2909 struct get_mgmt_rev_reply
*event_reply
;
2912 if (job
->request_len
<
2913 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev
)) {
2914 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2915 "2740 Received GET_DFC_REV request below "
2921 event_req
= (struct get_mgmt_rev
*)
2922 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2924 event_reply
= (struct get_mgmt_rev_reply
*)
2925 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
2927 if (job
->reply_len
<
2928 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev_reply
)) {
2929 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2930 "2741 Received GET_DFC_REV reply below "
2936 event_reply
->info
.a_Major
= MANAGEMENT_MAJOR_REV
;
2937 event_reply
->info
.a_Minor
= MANAGEMENT_MINOR_REV
;
2939 job
->reply
->result
= rc
;
2946 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
2947 * @phba: Pointer to HBA context object.
2948 * @pmboxq: Pointer to mailbox command.
2950 * This is completion handler function for mailbox commands issued from
2951 * lpfc_bsg_issue_mbox function. This function is called by the
2952 * mailbox event handler function with no lock held. This function
2953 * will wake up thread waiting on the wait queue pointed by context1
2957 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2959 struct bsg_job_data
*dd_data
;
2960 struct fc_bsg_job
*job
;
2962 unsigned long flags
;
2963 uint8_t *pmb
, *pmb_buf
;
2965 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2966 dd_data
= pmboxq
->context1
;
2967 /* job already timed out? */
2969 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2974 * The outgoing buffer is readily referred from the dma buffer,
2975 * just need to get header part from mailboxq structure.
2977 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
2978 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
2979 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
2981 job
= dd_data
->context_un
.mbox
.set_job
;
2983 size
= job
->reply_payload
.payload_len
;
2984 job
->reply
->reply_payload_rcv_len
=
2985 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
2986 job
->reply_payload
.sg_cnt
,
2988 /* need to hold the lock until we set job->dd_data to NULL
2989 * to hold off the timeout handler returning to the mid-layer
2990 * while we are still processing the job.
2992 job
->dd_data
= NULL
;
2993 dd_data
->context_un
.mbox
.set_job
= NULL
;
2994 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2996 dd_data
->context_un
.mbox
.set_job
= NULL
;
2997 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3000 mempool_free(dd_data
->context_un
.mbox
.pmboxq
, phba
->mbox_mem_pool
);
3001 lpfc_bsg_dma_page_free(phba
, dd_data
->context_un
.mbox
.dmabuffers
);
3005 job
->reply
->result
= 0;
3012 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3013 * @phba: Pointer to HBA context object.
3014 * @mb: Pointer to a mailbox object.
3015 * @vport: Pointer to a vport object.
3017 * Some commands require the port to be offline, some may not be called from
3020 static int lpfc_bsg_check_cmd_access(struct lpfc_hba
*phba
,
3021 MAILBOX_t
*mb
, struct lpfc_vport
*vport
)
3023 /* return negative error values for bsg job */
3024 switch (mb
->mbxCommand
) {
3028 case MBX_CONFIG_LINK
:
3029 case MBX_CONFIG_RING
:
3030 case MBX_RESET_RING
:
3031 case MBX_UNREG_LOGIN
:
3033 case MBX_DUMP_CONTEXT
:
3037 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
3038 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3039 "2743 Command 0x%x is illegal in on-line "
3045 case MBX_WRITE_VPARMS
:
3048 case MBX_READ_CONFIG
:
3049 case MBX_READ_RCONFIG
:
3050 case MBX_READ_STATUS
:
3053 case MBX_READ_LNK_STAT
:
3054 case MBX_DUMP_MEMORY
:
3056 case MBX_UPDATE_CFG
:
3057 case MBX_KILL_BOARD
:
3059 case MBX_LOAD_EXP_ROM
:
3061 case MBX_DEL_LD_ENTRY
:
3064 case MBX_SLI4_CONFIG
:
3065 case MBX_READ_EVENT_LOG
:
3066 case MBX_READ_EVENT_LOG_STATUS
:
3067 case MBX_WRITE_EVENT_LOG
:
3068 case MBX_PORT_CAPABILITIES
:
3069 case MBX_PORT_IOV_CONTROL
:
3070 case MBX_RUN_BIU_DIAG64
:
3072 case MBX_SET_VARIABLE
:
3073 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3074 "1226 mbox: set_variable 0x%x, 0x%x\n",
3076 mb
->un
.varWords
[1]);
3077 if ((mb
->un
.varWords
[0] == SETVAR_MLOMNT
)
3078 && (mb
->un
.varWords
[1] == 1)) {
3079 phba
->wait_4_mlo_maint_flg
= 1;
3080 } else if (mb
->un
.varWords
[0] == SETVAR_MLORST
) {
3081 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
3082 phba
->fc_topology
= LPFC_TOPOLOGY_PT_PT
;
3085 case MBX_READ_SPARM64
:
3086 case MBX_READ_TOPOLOGY
:
3088 case MBX_REG_LOGIN64
:
3089 case MBX_CONFIG_PORT
:
3090 case MBX_RUN_BIU_DIAG
:
3092 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3093 "2742 Unknown Command 0x%x\n",
3102 * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
3103 * @phba: Pointer to HBA context object.
3105 * This is routine clean up and reset BSG handling of multi-buffer mbox
3109 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba
*phba
)
3111 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
)
3114 /* free all memory, including dma buffers */
3115 lpfc_bsg_dma_page_list_free(phba
,
3116 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3117 lpfc_bsg_dma_page_free(phba
, phba
->mbox_ext_buf_ctx
.mbx_dmabuf
);
3118 /* multi-buffer write mailbox command pass-through complete */
3119 memset((char *)&phba
->mbox_ext_buf_ctx
, 0,
3120 sizeof(struct lpfc_mbox_ext_buf_ctx
));
3121 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3127 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3128 * @phba: Pointer to HBA context object.
3129 * @pmboxq: Pointer to mailbox command.
3131 * This is routine handles BSG job for mailbox commands completions with
3132 * multiple external buffers.
3134 static struct fc_bsg_job
*
3135 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3137 struct bsg_job_data
*dd_data
;
3138 struct fc_bsg_job
*job
;
3139 uint8_t *pmb
, *pmb_buf
;
3140 unsigned long flags
;
3144 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3145 dd_data
= pmboxq
->context1
;
3146 /* has the job already timed out? */
3148 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3154 * The outgoing buffer is readily referred from the dma buffer,
3155 * just need to get header part from mailboxq structure.
3157 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3158 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3159 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3161 job
= dd_data
->context_un
.mbox
.set_job
;
3163 size
= job
->reply_payload
.payload_len
;
3164 job
->reply
->reply_payload_rcv_len
=
3165 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3166 job
->reply_payload
.sg_cnt
,
3168 /* result for successful */
3169 job
->reply
->result
= 0;
3170 job
->dd_data
= NULL
;
3171 /* need to hold the lock util we set job->dd_data to NULL
3172 * to hold off the timeout handler from midlayer to take
3175 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3176 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3177 "2937 SLI_CONFIG ext-buffer maibox command "
3178 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3179 phba
->mbox_ext_buf_ctx
.nembType
,
3180 phba
->mbox_ext_buf_ctx
.mboxType
, size
);
3181 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
,
3182 phba
->mbox_ext_buf_ctx
.nembType
,
3183 phba
->mbox_ext_buf_ctx
.mboxType
,
3184 dma_ebuf
, sta_pos_addr
,
3185 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
, 0);
3187 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3191 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3192 "2938 SLI_CONFIG ext-buffer maibox "
3193 "command (x%x/x%x) failure, rc:x%x\n",
3194 phba
->mbox_ext_buf_ctx
.nembType
,
3195 phba
->mbox_ext_buf_ctx
.mboxType
, rc
);
3197 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_DONE
;
3204 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3205 * @phba: Pointer to HBA context object.
3206 * @pmboxq: Pointer to mailbox command.
3208 * This is completion handler function for mailbox read commands with multiple
3212 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3214 struct fc_bsg_job
*job
;
3216 /* handle the BSG job with mailbox command */
3217 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3218 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3220 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3221 "2939 SLI_CONFIG ext-buffer rd maibox command "
3222 "complete, ctxState:x%x, mbxStatus:x%x\n",
3223 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3225 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3227 if (pmboxq
->u
.mb
.mbxStatus
|| phba
->mbox_ext_buf_ctx
.numBuf
== 1)
3228 lpfc_bsg_mbox_ext_session_reset(phba
);
3230 /* free base driver mailbox structure memory */
3231 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3233 /* complete the bsg job if we have it */
3241 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3242 * @phba: Pointer to HBA context object.
3243 * @pmboxq: Pointer to mailbox command.
3245 * This is completion handler function for mailbox write commands with multiple
3249 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3251 struct fc_bsg_job
*job
;
3253 /* handle the BSG job with the mailbox command */
3254 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3255 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3257 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3258 "2940 SLI_CONFIG ext-buffer wr maibox command "
3259 "complete, ctxState:x%x, mbxStatus:x%x\n",
3260 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3262 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3264 /* free all memory, including dma buffers */
3265 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3266 lpfc_bsg_mbox_ext_session_reset(phba
);
3268 /* complete the bsg job if we have it */
3276 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba
*phba
, enum nemb_type nemb_tp
,
3277 uint32_t index
, struct lpfc_dmabuf
*mbx_dmabuf
,
3278 struct lpfc_dmabuf
*ext_dmabuf
)
3280 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3282 /* pointer to the start of mailbox command */
3283 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)mbx_dmabuf
->virt
;
3285 if (nemb_tp
== nemb_mse
) {
3287 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3289 putPaddrHigh(mbx_dmabuf
->phys
+
3291 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3293 putPaddrLow(mbx_dmabuf
->phys
+
3295 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3296 "2943 SLI_CONFIG(mse)[%d], "
3297 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3299 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3301 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3303 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3306 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3308 putPaddrHigh(ext_dmabuf
->phys
);
3309 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3311 putPaddrLow(ext_dmabuf
->phys
);
3312 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3313 "2944 SLI_CONFIG(mse)[%d], "
3314 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3316 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3318 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3320 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3325 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3327 putPaddrHigh(mbx_dmabuf
->phys
+
3329 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3331 putPaddrLow(mbx_dmabuf
->phys
+
3333 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3334 "3007 SLI_CONFIG(hbd)[%d], "
3335 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3337 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3339 sli_config_emb1_subsys
.hbd
[index
]),
3340 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3342 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3346 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3348 putPaddrHigh(ext_dmabuf
->phys
);
3349 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3351 putPaddrLow(ext_dmabuf
->phys
);
3352 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3353 "3008 SLI_CONFIG(hbd)[%d], "
3354 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3356 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3358 sli_config_emb1_subsys
.hbd
[index
]),
3359 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3361 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3369 * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
3370 * @phba: Pointer to HBA context object.
3371 * @mb: Pointer to a BSG mailbox object.
3372 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3373 * @dmabuff: Pointer to a DMA buffer descriptor.
3375 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3376 * non-embedded external bufffers.
3379 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3380 enum nemb_type nemb_tp
,
3381 struct lpfc_dmabuf
*dmabuf
)
3383 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3384 struct dfc_mbox_req
*mbox_req
;
3385 struct lpfc_dmabuf
*curr_dmabuf
, *next_dmabuf
;
3386 uint32_t ext_buf_cnt
, ext_buf_index
;
3387 struct lpfc_dmabuf
*ext_dmabuf
= NULL
;
3388 struct bsg_job_data
*dd_data
= NULL
;
3389 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3395 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3397 /* pointer to the start of mailbox command */
3398 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3400 if (nemb_tp
== nemb_mse
) {
3401 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3402 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3403 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3404 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3405 "2945 Handled SLI_CONFIG(mse) rd, "
3406 "ext_buf_cnt(%d) out of range(%d)\n",
3408 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3412 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3413 "2941 Handled SLI_CONFIG(mse) rd, "
3414 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3416 /* sanity check on interface type for support */
3417 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3418 LPFC_SLI_INTF_IF_TYPE_2
) {
3422 /* nemb_tp == nemb_hbd */
3423 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3424 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3425 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3426 "2946 Handled SLI_CONFIG(hbd) rd, "
3427 "ext_buf_cnt(%d) out of range(%d)\n",
3429 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3433 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3434 "2942 Handled SLI_CONFIG(hbd) rd, "
3435 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3438 /* before dma descriptor setup */
3439 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3440 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3442 /* reject non-embedded mailbox command with none external buffer */
3443 if (ext_buf_cnt
== 0) {
3446 } else if (ext_buf_cnt
> 1) {
3447 /* additional external read buffers */
3448 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3449 ext_dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
3454 list_add_tail(&ext_dmabuf
->list
,
3455 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3459 /* bsg tracking structure */
3460 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3466 /* mailbox command structure for base driver */
3467 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3472 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3474 /* for the first external buffer */
3475 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3477 /* for the rest of external buffer descriptors if any */
3478 if (ext_buf_cnt
> 1) {
3480 list_for_each_entry_safe(curr_dmabuf
, next_dmabuf
,
3481 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
, list
) {
3482 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
,
3483 ext_buf_index
, dmabuf
,
3489 /* after dma descriptor setup */
3490 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3491 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3493 /* construct base driver mbox command */
3494 pmb
= &pmboxq
->u
.mb
;
3495 pmbx
= (uint8_t *)dmabuf
->virt
;
3496 memcpy(pmb
, pmbx
, sizeof(*pmb
));
3497 pmb
->mbxOwner
= OWN_HOST
;
3498 pmboxq
->vport
= phba
->pport
;
3500 /* multi-buffer handling context */
3501 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3502 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_rd
;
3503 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3504 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3505 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3506 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3508 /* callback for multi-buffer read mailbox command */
3509 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_read_mbox_ext_cmpl
;
3511 /* context fields to callback function */
3512 pmboxq
->context1
= dd_data
;
3513 dd_data
->type
= TYPE_MBOX
;
3514 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3515 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
3516 dd_data
->context_un
.mbox
.set_job
= job
;
3517 job
->dd_data
= dd_data
;
3520 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3522 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3523 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3524 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3525 "2947 Issued SLI_CONFIG ext-buffer "
3526 "maibox command, rc:x%x\n", rc
);
3527 return SLI_CONFIG_HANDLED
;
3529 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3530 "2948 Failed to issue SLI_CONFIG ext-buffer "
3531 "maibox command, rc:x%x\n", rc
);
3536 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3537 lpfc_bsg_dma_page_list_free(phba
,
3538 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3540 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
3545 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
3546 * @phba: Pointer to HBA context object.
3547 * @mb: Pointer to a BSG mailbox object.
3548 * @dmabuff: Pointer to a DMA buffer descriptor.
3550 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
3551 * non-embedded external bufffers.
3554 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3555 enum nemb_type nemb_tp
,
3556 struct lpfc_dmabuf
*dmabuf
)
3558 struct dfc_mbox_req
*mbox_req
;
3559 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3560 uint32_t ext_buf_cnt
;
3561 struct bsg_job_data
*dd_data
= NULL
;
3562 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3565 int rc
= SLI_CONFIG_NOT_HANDLED
, i
;
3568 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3570 /* pointer to the start of mailbox command */
3571 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3573 if (nemb_tp
== nemb_mse
) {
3574 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3575 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3576 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3577 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3578 "2953 Handled SLI_CONFIG(mse) wr, "
3579 "ext_buf_cnt(%d) out of range(%d)\n",
3581 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3584 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3585 "2949 Handled SLI_CONFIG(mse) wr, "
3586 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3588 /* sanity check on interface type for support */
3589 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3590 LPFC_SLI_INTF_IF_TYPE_2
)
3592 /* nemb_tp == nemb_hbd */
3593 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3594 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3595 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3596 "2954 Handled SLI_CONFIG(hbd) wr, "
3597 "ext_buf_cnt(%d) out of range(%d)\n",
3599 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3602 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3603 "2950 Handled SLI_CONFIG(hbd) wr, "
3604 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3607 /* before dma buffer descriptor setup */
3608 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3609 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3611 if (ext_buf_cnt
== 0)
3614 /* for the first external buffer */
3615 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3617 /* after dma descriptor setup */
3618 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3619 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3621 /* log for looking forward */
3622 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3623 if (nemb_tp
== nemb_mse
)
3624 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3625 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
3626 i
, sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3629 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3630 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
3631 i
, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3632 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3636 /* multi-buffer handling context */
3637 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3638 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_wr
;
3639 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3640 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3641 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3642 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3644 if (ext_buf_cnt
== 1) {
3645 /* bsg tracking structure */
3646 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3652 /* mailbox command structure for base driver */
3653 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3658 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3659 pmb
= &pmboxq
->u
.mb
;
3660 mbx
= (uint8_t *)dmabuf
->virt
;
3661 memcpy(pmb
, mbx
, sizeof(*pmb
));
3662 pmb
->mbxOwner
= OWN_HOST
;
3663 pmboxq
->vport
= phba
->pport
;
3665 /* callback for multi-buffer read mailbox command */
3666 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
3668 /* context fields to callback function */
3669 pmboxq
->context1
= dd_data
;
3670 dd_data
->type
= TYPE_MBOX
;
3671 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3672 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)mbx
;
3673 dd_data
->context_un
.mbox
.set_job
= job
;
3674 job
->dd_data
= dd_data
;
3677 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3679 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3680 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3681 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3682 "2955 Issued SLI_CONFIG ext-buffer "
3683 "maibox command, rc:x%x\n", rc
);
3684 return SLI_CONFIG_HANDLED
;
3686 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3687 "2956 Failed to issue SLI_CONFIG ext-buffer "
3688 "maibox command, rc:x%x\n", rc
);
3692 /* wait for additoinal external buffers */
3693 job
->reply
->result
= 0;
3695 return SLI_CONFIG_HANDLED
;
3699 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3706 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
3707 * @phba: Pointer to HBA context object.
3708 * @mb: Pointer to a BSG mailbox object.
3709 * @dmabuff: Pointer to a DMA buffer descriptor.
3711 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
3712 * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
3713 * with embedded sussystem 0x1 and opcodes with external HBDs.
3716 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3717 struct lpfc_dmabuf
*dmabuf
)
3719 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3722 int rc
= SLI_CONFIG_NOT_HANDLED
;
3725 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_HOST
;
3727 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3729 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3730 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3731 subsys
= bsg_bf_get(lpfc_emb0_subcmnd_subsys
,
3732 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3733 opcode
= bsg_bf_get(lpfc_emb0_subcmnd_opcode
,
3734 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3735 if (subsys
== SLI_CONFIG_SUBSYS_FCOE
) {
3737 case FCOE_OPCODE_READ_FCF
:
3738 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3739 "2957 Handled SLI_CONFIG "
3740 "subsys_fcoe, opcode:x%x\n",
3742 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3745 case FCOE_OPCODE_ADD_FCF
:
3746 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3747 "2958 Handled SLI_CONFIG "
3748 "subsys_fcoe, opcode:x%x\n",
3750 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
3754 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3755 "2959 Not handled SLI_CONFIG "
3756 "subsys_fcoe, opcode:x%x\n",
3758 rc
= SLI_CONFIG_NOT_HANDLED
;
3762 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3763 "2977 Handled SLI_CONFIG "
3764 "subsys:x%d, opcode:x%x\n",
3766 rc
= SLI_CONFIG_NOT_HANDLED
;
3769 subsys
= bsg_bf_get(lpfc_emb1_subcmnd_subsys
,
3770 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
3771 opcode
= bsg_bf_get(lpfc_emb1_subcmnd_opcode
,
3772 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
3773 if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
3775 case COMN_OPCODE_READ_OBJECT
:
3776 case COMN_OPCODE_READ_OBJECT_LIST
:
3777 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3778 "2960 Handled SLI_CONFIG "
3779 "subsys_comn, opcode:x%x\n",
3781 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3784 case COMN_OPCODE_WRITE_OBJECT
:
3785 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3786 "2961 Handled SLI_CONFIG "
3787 "subsys_comn, opcode:x%x\n",
3789 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
3793 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3794 "2962 Not handled SLI_CONFIG "
3795 "subsys_comn, opcode:x%x\n",
3797 rc
= SLI_CONFIG_NOT_HANDLED
;
3801 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3802 "2978 Handled SLI_CONFIG "
3803 "subsys:x%d, opcode:x%x\n",
3805 rc
= SLI_CONFIG_NOT_HANDLED
;
3812 * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
3813 * @phba: Pointer to HBA context object.
3815 * This routine is for requesting to abort a pass-through mailbox command with
3816 * multiple external buffers due to error condition.
3819 lpfc_bsg_mbox_ext_abort(struct lpfc_hba
*phba
)
3821 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
3822 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
3824 lpfc_bsg_mbox_ext_session_reset(phba
);
3829 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
3830 * @phba: Pointer to HBA context object.
3831 * @dmabuf: Pointer to a DMA buffer descriptor.
3833 * This routine extracts the next mailbox read external buffer back to
3834 * user space through BSG.
3837 lpfc_bsg_read_ebuf_get(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
3839 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3840 struct lpfc_dmabuf
*dmabuf
;
3845 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
3846 phba
->mbox_ext_buf_ctx
.seqNum
++;
3848 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
3849 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
3851 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
3852 size
= bsg_bf_get(lpfc_mbox_sli_config_mse_len
,
3853 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[index
]);
3854 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3855 "2963 SLI_CONFIG (mse) ext-buffer rd get "
3856 "buffer[%d], size:%d\n", index
, size
);
3858 size
= bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3859 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd
[index
]);
3860 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3861 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
3862 "buffer[%d], size:%d\n", index
, size
);
3864 if (list_empty(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
))
3866 dmabuf
= list_first_entry(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
,
3867 struct lpfc_dmabuf
, list
);
3868 list_del_init(&dmabuf
->list
);
3870 /* after dma buffer descriptor setup */
3871 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
3872 mbox_rd
, dma_ebuf
, sta_pos_addr
,
3875 pbuf
= (uint8_t *)dmabuf
->virt
;
3876 job
->reply
->reply_payload_rcv_len
=
3877 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3878 job
->reply_payload
.sg_cnt
,
3881 lpfc_bsg_dma_page_free(phba
, dmabuf
);
3883 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
3884 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3885 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
3886 "command session done\n");
3887 lpfc_bsg_mbox_ext_session_reset(phba
);
3890 job
->reply
->result
= 0;
3893 return SLI_CONFIG_HANDLED
;
3897 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
3898 * @phba: Pointer to HBA context object.
3899 * @dmabuf: Pointer to a DMA buffer descriptor.
3901 * This routine sets up the next mailbox read external buffer obtained
3902 * from user space through BSG.
3905 lpfc_bsg_write_ebuf_set(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3906 struct lpfc_dmabuf
*dmabuf
)
3908 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3909 struct bsg_job_data
*dd_data
= NULL
;
3910 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3912 enum nemb_type nemb_tp
;
3918 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
3919 phba
->mbox_ext_buf_ctx
.seqNum
++;
3920 nemb_tp
= phba
->mbox_ext_buf_ctx
.nembType
;
3922 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
3923 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
3925 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3931 pbuf
= (uint8_t *)dmabuf
->virt
;
3932 size
= job
->request_payload
.payload_len
;
3933 sg_copy_to_buffer(job
->request_payload
.sg_list
,
3934 job
->request_payload
.sg_cnt
,
3937 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
3938 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3939 "2966 SLI_CONFIG (mse) ext-buffer wr set "
3940 "buffer[%d], size:%d\n",
3941 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
3944 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3945 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
3946 "buffer[%d], size:%d\n",
3947 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
3951 /* set up external buffer descriptor and add to external buffer list */
3952 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, index
,
3953 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
,
3955 list_add_tail(&dmabuf
->list
, &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3957 /* after write dma buffer */
3958 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
3959 mbox_wr
, dma_ebuf
, sta_pos_addr
,
3962 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
3963 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3964 "2968 SLI_CONFIG ext-buffer wr all %d "
3965 "ebuffers received\n",
3966 phba
->mbox_ext_buf_ctx
.numBuf
);
3967 /* mailbox command structure for base driver */
3968 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3973 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3974 pbuf
= (uint8_t *)phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
3975 pmb
= &pmboxq
->u
.mb
;
3976 memcpy(pmb
, pbuf
, sizeof(*pmb
));
3977 pmb
->mbxOwner
= OWN_HOST
;
3978 pmboxq
->vport
= phba
->pport
;
3980 /* callback for multi-buffer write mailbox command */
3981 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
3983 /* context fields to callback function */
3984 pmboxq
->context1
= dd_data
;
3985 dd_data
->type
= TYPE_MBOX
;
3986 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3987 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pbuf
;
3988 dd_data
->context_un
.mbox
.set_job
= job
;
3989 job
->dd_data
= dd_data
;
3992 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3994 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3995 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3996 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3997 "2969 Issued SLI_CONFIG ext-buffer "
3998 "maibox command, rc:x%x\n", rc
);
3999 return SLI_CONFIG_HANDLED
;
4001 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4002 "2970 Failed to issue SLI_CONFIG ext-buffer "
4003 "maibox command, rc:x%x\n", rc
);
4008 /* wait for additoinal external buffers */
4009 job
->reply
->result
= 0;
4011 return SLI_CONFIG_HANDLED
;
4014 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4021 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4022 * @phba: Pointer to HBA context object.
4023 * @mb: Pointer to a BSG mailbox object.
4024 * @dmabuff: Pointer to a DMA buffer descriptor.
4026 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4027 * command with multiple non-embedded external buffers.
4030 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4031 struct lpfc_dmabuf
*dmabuf
)
4035 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4036 "2971 SLI_CONFIG buffer (type:x%x)\n",
4037 phba
->mbox_ext_buf_ctx
.mboxType
);
4039 if (phba
->mbox_ext_buf_ctx
.mboxType
== mbox_rd
) {
4040 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_DONE
) {
4041 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4042 "2972 SLI_CONFIG rd buffer state "
4044 phba
->mbox_ext_buf_ctx
.state
);
4045 lpfc_bsg_mbox_ext_abort(phba
);
4048 rc
= lpfc_bsg_read_ebuf_get(phba
, job
);
4049 if (rc
== SLI_CONFIG_HANDLED
)
4050 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4051 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4052 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_HOST
) {
4053 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4054 "2973 SLI_CONFIG wr buffer state "
4056 phba
->mbox_ext_buf_ctx
.state
);
4057 lpfc_bsg_mbox_ext_abort(phba
);
4060 rc
= lpfc_bsg_write_ebuf_set(phba
, job
, dmabuf
);
4066 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4067 * @phba: Pointer to HBA context object.
4068 * @mb: Pointer to a BSG mailbox object.
4069 * @dmabuff: Pointer to a DMA buffer descriptor.
4071 * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
4072 * (0x9B) mailbox commands and external buffers.
4075 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4076 struct lpfc_dmabuf
*dmabuf
)
4078 struct dfc_mbox_req
*mbox_req
;
4079 int rc
= SLI_CONFIG_NOT_HANDLED
;
4082 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4084 /* mbox command with/without single external buffer */
4085 if (mbox_req
->extMboxTag
== 0 && mbox_req
->extSeqNum
== 0)
4088 /* mbox command and first external buffer */
4089 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
) {
4090 if (mbox_req
->extSeqNum
== 1) {
4091 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4092 "2974 SLI_CONFIG mailbox: tag:%d, "
4093 "seq:%d\n", mbox_req
->extMboxTag
,
4094 mbox_req
->extSeqNum
);
4095 rc
= lpfc_bsg_handle_sli_cfg_mbox(phba
, job
, dmabuf
);
4098 goto sli_cfg_ext_error
;
4102 * handle additional external buffers
4105 /* check broken pipe conditions */
4106 if (mbox_req
->extMboxTag
!= phba
->mbox_ext_buf_ctx
.mbxTag
)
4107 goto sli_cfg_ext_error
;
4108 if (mbox_req
->extSeqNum
> phba
->mbox_ext_buf_ctx
.numBuf
)
4109 goto sli_cfg_ext_error
;
4110 if (mbox_req
->extSeqNum
!= phba
->mbox_ext_buf_ctx
.seqNum
+ 1)
4111 goto sli_cfg_ext_error
;
4113 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4114 "2975 SLI_CONFIG mailbox external buffer: "
4115 "extSta:x%x, tag:%d, seq:%d\n",
4116 phba
->mbox_ext_buf_ctx
.state
, mbox_req
->extMboxTag
,
4117 mbox_req
->extSeqNum
);
4118 rc
= lpfc_bsg_handle_sli_cfg_ebuf(phba
, job
, dmabuf
);
4122 /* all other cases, broken pipe */
4123 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4124 "2976 SLI_CONFIG mailbox broken pipe: "
4125 "ctxSta:x%x, ctxNumBuf:%d "
4126 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4127 phba
->mbox_ext_buf_ctx
.state
,
4128 phba
->mbox_ext_buf_ctx
.numBuf
,
4129 phba
->mbox_ext_buf_ctx
.mbxTag
,
4130 phba
->mbox_ext_buf_ctx
.seqNum
,
4131 mbox_req
->extMboxTag
, mbox_req
->extSeqNum
);
4133 lpfc_bsg_mbox_ext_session_reset(phba
);
4139 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4140 * @phba: Pointer to HBA context object.
4141 * @mb: Pointer to a mailbox object.
4142 * @vport: Pointer to a vport object.
4144 * Allocate a tracking object, mailbox command memory, get a mailbox
4145 * from the mailbox pool, copy the caller mailbox command.
4147 * If offline and the sli is active we need to poll for the command (port is
4148 * being reset) and com-plete the job, otherwise issue the mailbox command and
4149 * let our completion handler finish the command.
4152 lpfc_bsg_issue_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4153 struct lpfc_vport
*vport
)
4155 LPFC_MBOXQ_t
*pmboxq
= NULL
; /* internal mailbox queue */
4156 MAILBOX_t
*pmb
; /* shortcut to the pmboxq mailbox */
4157 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4158 uint8_t *pmbx
= NULL
;
4159 struct bsg_job_data
*dd_data
= NULL
; /* bsg data tracking structure */
4160 struct lpfc_dmabuf
*dmabuf
= NULL
;
4161 struct dfc_mbox_req
*mbox_req
;
4162 struct READ_EVENT_LOG_VAR
*rdEventLog
;
4163 uint32_t transmit_length
, receive_length
, mode
;
4164 struct lpfc_mbx_sli4_config
*sli4_config
;
4165 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
4166 struct mbox_header
*header
;
4167 struct ulp_bde64
*bde
;
4168 uint8_t *ext
= NULL
;
4174 /* in case no data is transferred */
4175 job
->reply
->reply_payload_rcv_len
= 0;
4177 /* sanity check to protect driver */
4178 if (job
->reply_payload
.payload_len
> BSG_MBOX_SIZE
||
4179 job
->request_payload
.payload_len
> BSG_MBOX_SIZE
) {
4185 * Don't allow mailbox commands to be sent when blocked or when in
4186 * the middle of discovery
4188 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4194 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4196 /* check if requested extended data lengths are valid */
4197 if ((mbox_req
->inExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t)) ||
4198 (mbox_req
->outExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t))) {
4203 dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
4204 if (!dmabuf
|| !dmabuf
->virt
) {
4209 /* Get the mailbox command or external buffer from BSG */
4210 pmbx
= (uint8_t *)dmabuf
->virt
;
4211 size
= job
->request_payload
.payload_len
;
4212 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4213 job
->request_payload
.sg_cnt
, pmbx
, size
);
4215 /* Handle possible SLI_CONFIG with non-embedded payloads */
4216 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4217 rc
= lpfc_bsg_handle_sli_cfg_ext(phba
, job
, dmabuf
);
4218 if (rc
== SLI_CONFIG_HANDLED
)
4222 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4225 rc
= lpfc_bsg_check_cmd_access(phba
, (MAILBOX_t
*)pmbx
, vport
);
4227 goto job_done
; /* must be negative */
4229 /* allocate our bsg tracking structure */
4230 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4232 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4233 "2727 Failed allocation of dd_data\n");
4238 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4243 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4245 pmb
= &pmboxq
->u
.mb
;
4246 memcpy(pmb
, pmbx
, sizeof(*pmb
));
4247 pmb
->mbxOwner
= OWN_HOST
;
4248 pmboxq
->vport
= vport
;
4250 /* If HBA encountered an error attention, allow only DUMP
4251 * or RESTART mailbox commands until the HBA is restarted.
4253 if (phba
->pport
->stopped
&&
4254 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4255 pmb
->mbxCommand
!= MBX_RESTART
&&
4256 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4257 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4258 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4259 "2797 mbox: Issued mailbox cmd "
4260 "0x%x while in stopped state.\n",
4263 /* extended mailbox commands will need an extended buffer */
4264 if (mbox_req
->inExtWLen
|| mbox_req
->outExtWLen
) {
4265 /* any data for the device? */
4266 if (mbox_req
->inExtWLen
) {
4268 ext
= from
+ sizeof(MAILBOX_t
);
4270 pmboxq
->context2
= ext
;
4271 pmboxq
->in_ext_byte_len
=
4272 mbox_req
->inExtWLen
* sizeof(uint32_t);
4273 pmboxq
->out_ext_byte_len
=
4274 mbox_req
->outExtWLen
* sizeof(uint32_t);
4275 pmboxq
->mbox_offset_word
= mbox_req
->mbOffset
;
4278 /* biu diag will need a kernel buffer to transfer the data
4279 * allocate our own buffer and setup the mailbox command to
4282 if (pmb
->mbxCommand
== MBX_RUN_BIU_DIAG64
) {
4283 transmit_length
= pmb
->un
.varWords
[1];
4284 receive_length
= pmb
->un
.varWords
[4];
4285 /* transmit length cannot be greater than receive length or
4286 * mailbox extension size
4288 if ((transmit_length
> receive_length
) ||
4289 (transmit_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4293 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrHigh
=
4294 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4295 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrLow
=
4296 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4298 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrHigh
=
4299 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4300 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4301 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrLow
=
4302 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4303 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4304 } else if (pmb
->mbxCommand
== MBX_READ_EVENT_LOG
) {
4305 rdEventLog
= &pmb
->un
.varRdEventLog
;
4306 receive_length
= rdEventLog
->rcv_bde64
.tus
.f
.bdeSize
;
4307 mode
= bf_get(lpfc_event_log
, rdEventLog
);
4309 /* receive length cannot be greater than mailbox
4312 if (receive_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4317 /* mode zero uses a bde like biu diags command */
4319 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4320 + sizeof(MAILBOX_t
));
4321 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4322 + sizeof(MAILBOX_t
));
4324 } else if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4325 if (pmb
->mbxCommand
== MBX_DUMP_MEMORY
) {
4326 /* rebuild the command for sli4 using our own buffers
4327 * like we do for biu diags
4329 receive_length
= pmb
->un
.varWords
[2];
4330 /* receive length cannot be greater than mailbox
4333 if (receive_length
== 0) {
4337 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4338 + sizeof(MAILBOX_t
));
4339 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4340 + sizeof(MAILBOX_t
));
4341 } else if ((pmb
->mbxCommand
== MBX_UPDATE_CFG
) &&
4342 pmb
->un
.varUpdateCfg
.co
) {
4343 bde
= (struct ulp_bde64
*)&pmb
->un
.varWords
[4];
4345 /* bde size cannot be greater than mailbox ext size */
4346 if (bde
->tus
.f
.bdeSize
>
4347 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4351 bde
->addrHigh
= putPaddrHigh(dmabuf
->phys
4352 + sizeof(MAILBOX_t
));
4353 bde
->addrLow
= putPaddrLow(dmabuf
->phys
4354 + sizeof(MAILBOX_t
));
4355 } else if (pmb
->mbxCommand
== MBX_SLI4_CONFIG
) {
4356 /* Handling non-embedded SLI_CONFIG mailbox command */
4357 sli4_config
= &pmboxq
->u
.mqe
.un
.sli4_config
;
4358 if (!bf_get(lpfc_mbox_hdr_emb
,
4359 &sli4_config
->header
.cfg_mhdr
)) {
4360 /* rebuild the command for sli4 using our
4361 * own buffers like we do for biu diags
4363 header
= (struct mbox_header
*)
4364 &pmb
->un
.varWords
[0];
4365 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
4366 &pmb
->un
.varWords
[0];
4367 receive_length
= nembed_sge
->sge
[0].length
;
4369 /* receive length cannot be greater than
4370 * mailbox extension size
4372 if ((receive_length
== 0) ||
4374 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4379 nembed_sge
->sge
[0].pa_hi
=
4380 putPaddrHigh(dmabuf
->phys
4381 + sizeof(MAILBOX_t
));
4382 nembed_sge
->sge
[0].pa_lo
=
4383 putPaddrLow(dmabuf
->phys
4384 + sizeof(MAILBOX_t
));
4389 dd_data
->context_un
.mbox
.dmabuffers
= dmabuf
;
4391 /* setup wake call as IOCB callback */
4392 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_mbox_cmpl
;
4394 /* setup context field to pass wait_queue pointer to wake function */
4395 pmboxq
->context1
= dd_data
;
4396 dd_data
->type
= TYPE_MBOX
;
4397 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4398 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
4399 dd_data
->context_un
.mbox
.set_job
= job
;
4400 dd_data
->context_un
.mbox
.ext
= ext
;
4401 dd_data
->context_un
.mbox
.mbOffset
= mbox_req
->mbOffset
;
4402 dd_data
->context_un
.mbox
.inExtWLen
= mbox_req
->inExtWLen
;
4403 dd_data
->context_un
.mbox
.outExtWLen
= mbox_req
->outExtWLen
;
4404 job
->dd_data
= dd_data
;
4406 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4407 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4408 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4409 if (rc
!= MBX_SUCCESS
) {
4410 rc
= (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4414 /* job finished, copy the data */
4415 memcpy(pmbx
, pmb
, sizeof(*pmb
));
4416 job
->reply
->reply_payload_rcv_len
=
4417 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4418 job
->reply_payload
.sg_cnt
,
4420 /* not waiting mbox already done */
4425 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4426 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
))
4427 return 1; /* job started */
4430 /* common exit for error or job completed inline */
4432 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4433 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4441 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
4442 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
4445 lpfc_bsg_mbox_cmd(struct fc_bsg_job
*job
)
4447 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4448 struct lpfc_hba
*phba
= vport
->phba
;
4449 struct dfc_mbox_req
*mbox_req
;
4452 /* mix-and-match backward compatibility */
4453 job
->reply
->reply_payload_rcv_len
= 0;
4454 if (job
->request_len
<
4455 sizeof(struct fc_bsg_request
) + sizeof(struct dfc_mbox_req
)) {
4456 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4457 "2737 Mix-and-match backward compability "
4458 "between MBOX_REQ old size:%d and "
4459 "new request size:%d\n",
4460 (int)(job
->request_len
-
4461 sizeof(struct fc_bsg_request
)),
4462 (int)sizeof(struct dfc_mbox_req
));
4463 mbox_req
= (struct dfc_mbox_req
*)
4464 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4465 mbox_req
->extMboxTag
= 0;
4466 mbox_req
->extSeqNum
= 0;
4469 rc
= lpfc_bsg_issue_mbox(phba
, job
, vport
);
4473 job
->reply
->result
= 0;
4474 job
->dd_data
= NULL
;
4477 /* job submitted, will complete later*/
4478 rc
= 0; /* return zero, no error */
4480 /* some error occurred */
4481 job
->reply
->result
= rc
;
4482 job
->dd_data
= NULL
;
4489 * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
4490 * @phba: Pointer to HBA context object.
4491 * @cmdiocbq: Pointer to command iocb.
4492 * @rspiocbq: Pointer to response iocb.
4494 * This function is the completion handler for iocbs issued using
4495 * lpfc_menlo_cmd function. This function is called by the
4496 * ring event handler function without any lock held. This function
4497 * can be called from both worker thread context and interrupt
4498 * context. This function also can be called from another thread which
4499 * cleans up the SLI layer objects.
4500 * This function copies the contents of the response iocb to the
4501 * response iocb memory object provided by the caller of
4502 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4503 * sleeps for the iocb completion.
4506 lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba
*phba
,
4507 struct lpfc_iocbq
*cmdiocbq
,
4508 struct lpfc_iocbq
*rspiocbq
)
4510 struct bsg_job_data
*dd_data
;
4511 struct fc_bsg_job
*job
;
4513 struct lpfc_dmabuf
*bmp
;
4514 struct lpfc_bsg_menlo
*menlo
;
4515 unsigned long flags
;
4516 struct menlo_response
*menlo_resp
;
4519 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
4520 dd_data
= cmdiocbq
->context1
;
4522 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4526 menlo
= &dd_data
->context_un
.menlo
;
4527 job
= menlo
->set_job
;
4528 job
->dd_data
= NULL
; /* so timeout handler does not reply */
4530 spin_lock(&phba
->hbalock
);
4531 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
4532 if (cmdiocbq
->context2
&& rspiocbq
)
4533 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
4534 &rspiocbq
->iocb
, sizeof(IOCB_t
));
4535 spin_unlock(&phba
->hbalock
);
4538 rspiocbq
= menlo
->rspiocbq
;
4539 rsp
= &rspiocbq
->iocb
;
4541 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4542 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4543 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4544 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4546 /* always return the xri, this would be used in the case
4547 * of a menlo download to allow the data to be sent as a continuation
4550 menlo_resp
= (struct menlo_response
*)
4551 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4552 menlo_resp
->xri
= rsp
->ulpContext
;
4553 if (rsp
->ulpStatus
) {
4554 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
4555 switch (rsp
->un
.ulpWord
[4] & 0xff) {
4556 case IOERR_SEQUENCE_TIMEOUT
:
4559 case IOERR_INVALID_RPI
:
4569 job
->reply
->reply_payload_rcv_len
=
4570 rsp
->un
.genreq64
.bdl
.bdeSize
;
4572 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
4573 lpfc_sli_release_iocbq(phba
, rspiocbq
);
4574 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
4577 /* make error code available to userspace */
4578 job
->reply
->result
= rc
;
4579 /* complete the job back to userspace */
4581 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4586 * lpfc_menlo_cmd - send an ioctl for menlo hardware
4587 * @job: fc_bsg_job to handle
4589 * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
4590 * all the command completions will return the xri for the command.
4591 * For menlo data requests a gen request 64 CX is used to continue the exchange
4592 * supplied in the menlo request header xri field.
4595 lpfc_menlo_cmd(struct fc_bsg_job
*job
)
4597 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4598 struct lpfc_hba
*phba
= vport
->phba
;
4599 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
4602 struct menlo_command
*menlo_cmd
;
4603 struct menlo_response
*menlo_resp
;
4604 struct lpfc_dmabuf
*bmp
= NULL
;
4607 struct scatterlist
*sgel
= NULL
;
4610 struct bsg_job_data
*dd_data
;
4611 struct ulp_bde64
*bpl
= NULL
;
4613 /* in case no data is returned return just the return code */
4614 job
->reply
->reply_payload_rcv_len
= 0;
4616 if (job
->request_len
<
4617 sizeof(struct fc_bsg_request
) +
4618 sizeof(struct menlo_command
)) {
4619 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4620 "2784 Received MENLO_CMD request below "
4626 if (job
->reply_len
<
4627 sizeof(struct fc_bsg_request
) + sizeof(struct menlo_response
)) {
4628 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4629 "2785 Received MENLO_CMD reply below "
4635 if (!(phba
->menlo_flag
& HBA_MENLO_SUPPORT
)) {
4636 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4637 "2786 Adapter does not support menlo "
4643 menlo_cmd
= (struct menlo_command
*)
4644 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4646 menlo_resp
= (struct menlo_response
*)
4647 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4649 /* allocate our bsg tracking structure */
4650 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4652 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4653 "2787 Failed allocation of dd_data\n");
4658 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4664 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
4670 rspiocbq
= lpfc_sli_get_iocbq(phba
);
4676 rsp
= &rspiocbq
->iocb
;
4678 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
4684 INIT_LIST_HEAD(&bmp
->list
);
4685 bpl
= (struct ulp_bde64
*) bmp
->virt
;
4686 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4687 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4688 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
4689 busaddr
= sg_dma_address(sgel
);
4690 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
4691 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4692 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4693 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4694 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4698 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4699 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4700 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
4701 busaddr
= sg_dma_address(sgel
);
4702 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
4703 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4704 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4705 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4706 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4710 cmd
= &cmdiocbq
->iocb
;
4711 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
4712 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
4713 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
4714 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
4715 cmd
->un
.genreq64
.bdl
.bdeSize
=
4716 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
4717 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
4718 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
4719 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CMD
;
4720 cmd
->un
.genreq64
.w5
.hcsw
.Type
= MENLO_TRANSPORT_TYPE
; /* 0xfe */
4721 cmd
->ulpBdeCount
= 1;
4722 cmd
->ulpClass
= CLASS3
;
4723 cmd
->ulpOwner
= OWN_CHIP
;
4724 cmd
->ulpLe
= 1; /* Limited Edition */
4725 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
4726 cmdiocbq
->vport
= phba
->pport
;
4727 /* We want the firmware to timeout before we do */
4728 cmd
->ulpTimeout
= MENLO_TIMEOUT
- 5;
4729 cmdiocbq
->context3
= bmp
;
4730 cmdiocbq
->context2
= rspiocbq
;
4731 cmdiocbq
->iocb_cmpl
= lpfc_bsg_menlo_cmd_cmp
;
4732 cmdiocbq
->context1
= dd_data
;
4733 cmdiocbq
->context2
= rspiocbq
;
4734 if (menlo_cmd
->cmd
== LPFC_BSG_VENDOR_MENLO_CMD
) {
4735 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
4736 cmd
->ulpPU
= MENLO_PU
; /* 3 */
4737 cmd
->un
.ulpWord
[4] = MENLO_DID
; /* 0x0000FC0E */
4738 cmd
->ulpContext
= MENLO_CONTEXT
; /* 0 */
4740 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CX
;
4742 cmd
->un
.ulpWord
[4] = 0;
4743 cmd
->ulpContext
= menlo_cmd
->xri
;
4746 dd_data
->type
= TYPE_MENLO
;
4747 dd_data
->context_un
.menlo
.cmdiocbq
= cmdiocbq
;
4748 dd_data
->context_un
.menlo
.rspiocbq
= rspiocbq
;
4749 dd_data
->context_un
.menlo
.set_job
= job
;
4750 dd_data
->context_un
.menlo
.bmp
= bmp
;
4752 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
4754 if (rc
== IOCB_SUCCESS
)
4755 return 0; /* done for now */
4757 /* iocb failed so cleanup */
4758 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4759 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4760 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4761 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4763 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
4766 lpfc_sli_release_iocbq(phba
, rspiocbq
);
4768 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
4774 /* make error code available to userspace */
4775 job
->reply
->result
= rc
;
4776 job
->dd_data
= NULL
;
4781 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
4782 * @job: fc_bsg_job to handle
4785 lpfc_bsg_hst_vendor(struct fc_bsg_job
*job
)
4787 int command
= job
->request
->rqst_data
.h_vendor
.vendor_cmd
[0];
4791 case LPFC_BSG_VENDOR_SET_CT_EVENT
:
4792 rc
= lpfc_bsg_hba_set_event(job
);
4794 case LPFC_BSG_VENDOR_GET_CT_EVENT
:
4795 rc
= lpfc_bsg_hba_get_event(job
);
4797 case LPFC_BSG_VENDOR_SEND_MGMT_RESP
:
4798 rc
= lpfc_bsg_send_mgmt_rsp(job
);
4800 case LPFC_BSG_VENDOR_DIAG_MODE
:
4801 rc
= lpfc_bsg_diag_loopback_mode(job
);
4803 case LPFC_BSG_VENDOR_DIAG_MODE_END
:
4804 rc
= lpfc_sli4_bsg_diag_mode_end(job
);
4806 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK
:
4807 rc
= lpfc_bsg_diag_loopback_run(job
);
4809 case LPFC_BSG_VENDOR_LINK_DIAG_TEST
:
4810 rc
= lpfc_sli4_bsg_link_diag_test(job
);
4812 case LPFC_BSG_VENDOR_GET_MGMT_REV
:
4813 rc
= lpfc_bsg_get_dfc_rev(job
);
4815 case LPFC_BSG_VENDOR_MBOX
:
4816 rc
= lpfc_bsg_mbox_cmd(job
);
4818 case LPFC_BSG_VENDOR_MENLO_CMD
:
4819 case LPFC_BSG_VENDOR_MENLO_DATA
:
4820 rc
= lpfc_menlo_cmd(job
);
4824 job
->reply
->reply_payload_rcv_len
= 0;
4825 /* make error code available to userspace */
4826 job
->reply
->result
= rc
;
4834 * lpfc_bsg_request - handle a bsg request from the FC transport
4835 * @job: fc_bsg_job to handle
4838 lpfc_bsg_request(struct fc_bsg_job
*job
)
4843 msgcode
= job
->request
->msgcode
;
4845 case FC_BSG_HST_VENDOR
:
4846 rc
= lpfc_bsg_hst_vendor(job
);
4848 case FC_BSG_RPT_ELS
:
4849 rc
= lpfc_bsg_rport_els(job
);
4852 rc
= lpfc_bsg_send_mgmt_cmd(job
);
4856 job
->reply
->reply_payload_rcv_len
= 0;
4857 /* make error code available to userspace */
4858 job
->reply
->result
= rc
;
4866 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
4867 * @job: fc_bsg_job that has timed out
4869 * This function just aborts the job's IOCB. The aborted IOCB will return to
4870 * the waiting function which will handle passing the error back to userspace
4873 lpfc_bsg_timeout(struct fc_bsg_job
*job
)
4875 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4876 struct lpfc_hba
*phba
= vport
->phba
;
4877 struct lpfc_iocbq
*cmdiocb
;
4878 struct lpfc_bsg_event
*evt
;
4879 struct lpfc_bsg_iocb
*iocb
;
4880 struct lpfc_bsg_mbox
*mbox
;
4881 struct lpfc_bsg_menlo
*menlo
;
4882 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4883 struct bsg_job_data
*dd_data
;
4884 unsigned long flags
;
4886 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
4887 dd_data
= (struct bsg_job_data
*)job
->dd_data
;
4888 /* timeout and completion crossed paths if no dd_data */
4890 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4894 switch (dd_data
->type
) {
4896 iocb
= &dd_data
->context_un
.iocb
;
4897 cmdiocb
= iocb
->cmdiocbq
;
4898 /* hint to completion handler that the job timed out */
4899 job
->reply
->result
= -EAGAIN
;
4900 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4901 /* this will call our completion handler */
4902 spin_lock_irq(&phba
->hbalock
);
4903 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
4904 spin_unlock_irq(&phba
->hbalock
);
4907 evt
= dd_data
->context_un
.evt
;
4908 /* this event has no job anymore */
4909 evt
->set_job
= NULL
;
4910 job
->dd_data
= NULL
;
4911 job
->reply
->reply_payload_rcv_len
= 0;
4912 /* Return -EAGAIN which is our way of signallying the
4915 job
->reply
->result
= -EAGAIN
;
4916 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4920 mbox
= &dd_data
->context_un
.mbox
;
4921 /* this mbox has no job anymore */
4922 mbox
->set_job
= NULL
;
4923 job
->dd_data
= NULL
;
4924 job
->reply
->reply_payload_rcv_len
= 0;
4925 job
->reply
->result
= -EAGAIN
;
4926 /* the mbox completion handler can now be run */
4927 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4929 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
4930 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
4933 menlo
= &dd_data
->context_un
.menlo
;
4934 cmdiocb
= menlo
->cmdiocbq
;
4935 /* hint to completion handler that the job timed out */
4936 job
->reply
->result
= -EAGAIN
;
4937 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4938 /* this will call our completion handler */
4939 spin_lock_irq(&phba
->hbalock
);
4940 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
4941 spin_unlock_irq(&phba
->hbalock
);
4944 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4948 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
4949 * otherwise an error message will be displayed on the console
4950 * so always return success (zero)