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 if (phba
->sli_rev
== LPFC_SLI_REV4
)
593 cmdiocbq
->iocb
.ulpContext
= phba
->sli4_hba
.rpi_ids
[rpi
];
595 cmdiocbq
->iocb
.ulpContext
= rpi
;
596 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
597 cmdiocbq
->context1
= NULL
;
598 cmdiocbq
->context2
= NULL
;
600 cmdiocbq
->iocb_cmpl
= lpfc_bsg_rport_els_cmp
;
601 cmdiocbq
->context1
= dd_data
;
602 cmdiocbq
->context2
= rspiocbq
;
603 dd_data
->type
= TYPE_IOCB
;
604 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
605 dd_data
->context_un
.iocb
.rspiocbq
= rspiocbq
;
606 dd_data
->context_un
.iocb
.set_job
= job
;
607 dd_data
->context_un
.iocb
.bmp
= NULL
;
608 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
610 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
611 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
615 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
616 writel(creg_val
, phba
->HCregaddr
);
617 readl(phba
->HCregaddr
); /* flush */
619 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
621 if (rc
== IOCB_SUCCESS
)
622 return 0; /* done for now */
623 else if (rc
== IOCB_BUSY
)
629 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
630 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
631 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
632 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
634 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
636 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
639 lpfc_sli_release_iocbq(phba
, rspiocbq
);
645 /* make error code available to userspace */
646 job
->reply
->result
= rc
;
652 * lpfc_bsg_event_free - frees an allocated event structure
653 * @kref: Pointer to a kref.
655 * Called from kref_put. Back cast the kref into an event structure address.
656 * Free any events to get, delete associated nodes, free any events to see,
657 * free any data then free the event itself.
660 lpfc_bsg_event_free(struct kref
*kref
)
662 struct lpfc_bsg_event
*evt
= container_of(kref
, struct lpfc_bsg_event
,
664 struct event_data
*ed
;
666 list_del(&evt
->node
);
668 while (!list_empty(&evt
->events_to_get
)) {
669 ed
= list_entry(evt
->events_to_get
.next
, typeof(*ed
), node
);
675 while (!list_empty(&evt
->events_to_see
)) {
676 ed
= list_entry(evt
->events_to_see
.next
, typeof(*ed
), node
);
686 * lpfc_bsg_event_ref - increments the kref for an event
687 * @evt: Pointer to an event structure.
690 lpfc_bsg_event_ref(struct lpfc_bsg_event
*evt
)
692 kref_get(&evt
->kref
);
696 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
697 * @evt: Pointer to an event structure.
700 lpfc_bsg_event_unref(struct lpfc_bsg_event
*evt
)
702 kref_put(&evt
->kref
, lpfc_bsg_event_free
);
706 * lpfc_bsg_event_new - allocate and initialize a event structure
707 * @ev_mask: Mask of events.
708 * @ev_reg_id: Event reg id.
709 * @ev_req_id: Event request id.
711 static struct lpfc_bsg_event
*
712 lpfc_bsg_event_new(uint32_t ev_mask
, int ev_reg_id
, uint32_t ev_req_id
)
714 struct lpfc_bsg_event
*evt
= kzalloc(sizeof(*evt
), GFP_KERNEL
);
719 INIT_LIST_HEAD(&evt
->events_to_get
);
720 INIT_LIST_HEAD(&evt
->events_to_see
);
721 evt
->type_mask
= ev_mask
;
722 evt
->req_id
= ev_req_id
;
723 evt
->reg_id
= ev_reg_id
;
724 evt
->wait_time_stamp
= jiffies
;
725 init_waitqueue_head(&evt
->wq
);
726 kref_init(&evt
->kref
);
731 * diag_cmd_data_free - Frees an lpfc dma buffer extension
732 * @phba: Pointer to HBA context object.
733 * @mlist: Pointer to an lpfc dma buffer extension.
736 diag_cmd_data_free(struct lpfc_hba
*phba
, struct lpfc_dmabufext
*mlist
)
738 struct lpfc_dmabufext
*mlast
;
739 struct pci_dev
*pcidev
;
740 struct list_head head
, *curr
, *next
;
742 if ((!mlist
) || (!lpfc_is_link_up(phba
) &&
743 (phba
->link_flag
& LS_LOOPBACK_MODE
))) {
747 pcidev
= phba
->pcidev
;
748 list_add_tail(&head
, &mlist
->dma
.list
);
750 list_for_each_safe(curr
, next
, &head
) {
751 mlast
= list_entry(curr
, struct lpfc_dmabufext
, dma
.list
);
753 dma_free_coherent(&pcidev
->dev
,
763 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
768 * This function is called when an unsolicited CT command is received. It
769 * forwards the event to any processes registered to receive CT events.
772 lpfc_bsg_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
773 struct lpfc_iocbq
*piocbq
)
775 uint32_t evt_req_id
= 0;
778 struct lpfc_dmabuf
*dmabuf
= NULL
;
779 struct lpfc_bsg_event
*evt
;
780 struct event_data
*evt_dat
= NULL
;
781 struct lpfc_iocbq
*iocbq
;
783 struct list_head head
;
784 struct ulp_bde64
*bde
;
787 struct lpfc_dmabuf
*bdeBuf1
= piocbq
->context2
;
788 struct lpfc_dmabuf
*bdeBuf2
= piocbq
->context3
;
789 struct lpfc_hbq_entry
*hbqe
;
790 struct lpfc_sli_ct_request
*ct_req
;
791 struct fc_bsg_job
*job
= NULL
;
795 INIT_LIST_HEAD(&head
);
796 list_add_tail(&head
, &piocbq
->list
);
798 if (piocbq
->iocb
.ulpBdeCount
== 0 ||
799 piocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
== 0)
800 goto error_ct_unsol_exit
;
802 if (phba
->link_state
== LPFC_HBA_ERROR
||
803 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)))
804 goto error_ct_unsol_exit
;
806 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
809 dma_addr
= getPaddr(piocbq
->iocb
.un
.cont64
[0].addrHigh
,
810 piocbq
->iocb
.un
.cont64
[0].addrLow
);
811 dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
, dma_addr
);
814 goto error_ct_unsol_exit
;
815 ct_req
= (struct lpfc_sli_ct_request
*)dmabuf
->virt
;
816 evt_req_id
= ct_req
->FsType
;
817 cmd
= ct_req
->CommandResponse
.bits
.CmdRsp
;
818 len
= ct_req
->CommandResponse
.bits
.Size
;
819 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
820 lpfc_sli_ringpostbuf_put(phba
, pring
, dmabuf
);
822 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
823 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
824 if (!(evt
->type_mask
& FC_REG_CT_EVENT
) ||
825 evt
->req_id
!= evt_req_id
)
828 lpfc_bsg_event_ref(evt
);
829 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
830 evt_dat
= kzalloc(sizeof(*evt_dat
), GFP_KERNEL
);
831 if (evt_dat
== NULL
) {
832 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
833 lpfc_bsg_event_unref(evt
);
834 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
835 "2614 Memory allocation failed for "
840 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
841 /* take accumulated byte count from the last iocbq */
842 iocbq
= list_entry(head
.prev
, typeof(*iocbq
), list
);
843 evt_dat
->len
= iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
;
845 list_for_each_entry(iocbq
, &head
, list
) {
846 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++)
848 iocbq
->iocb
.un
.cont64
[i
].tus
.f
.bdeSize
;
852 evt_dat
->data
= kzalloc(evt_dat
->len
, GFP_KERNEL
);
853 if (evt_dat
->data
== NULL
) {
854 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
855 "2615 Memory allocation failed for "
856 "CT event data, size %d\n",
859 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
860 lpfc_bsg_event_unref(evt
);
861 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
862 goto error_ct_unsol_exit
;
865 list_for_each_entry(iocbq
, &head
, list
) {
867 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
868 bdeBuf1
= iocbq
->context2
;
869 bdeBuf2
= iocbq
->context3
;
871 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++) {
872 if (phba
->sli3_options
&
873 LPFC_SLI3_HBQ_ENABLED
) {
875 hbqe
= (struct lpfc_hbq_entry
*)
876 &iocbq
->iocb
.un
.ulpWord
[0];
877 size
= hbqe
->bde
.tus
.f
.bdeSize
;
880 hbqe
= (struct lpfc_hbq_entry
*)
883 size
= hbqe
->bde
.tus
.f
.bdeSize
;
886 if ((offset
+ size
) > evt_dat
->len
)
887 size
= evt_dat
->len
- offset
;
889 size
= iocbq
->iocb
.un
.cont64
[i
].
891 bde
= &iocbq
->iocb
.un
.cont64
[i
];
892 dma_addr
= getPaddr(bde
->addrHigh
,
894 dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
898 lpfc_printf_log(phba
, KERN_ERR
,
899 LOG_LIBDFC
, "2616 No dmabuf "
900 "found for iocbq 0x%p\n",
902 kfree(evt_dat
->data
);
904 spin_lock_irqsave(&phba
->ct_ev_lock
,
906 lpfc_bsg_event_unref(evt
);
907 spin_unlock_irqrestore(
908 &phba
->ct_ev_lock
, flags
);
909 goto error_ct_unsol_exit
;
911 memcpy((char *)(evt_dat
->data
) + offset
,
914 if (evt_req_id
!= SLI_CT_ELX_LOOPBACK
&&
915 !(phba
->sli3_options
&
916 LPFC_SLI3_HBQ_ENABLED
)) {
917 lpfc_sli_ringpostbuf_put(phba
, pring
,
921 case ELX_LOOPBACK_DATA
:
924 diag_cmd_data_free(phba
,
925 (struct lpfc_dmabufext
928 case ELX_LOOPBACK_XRI_SETUP
:
929 if ((phba
->sli_rev
==
931 (phba
->sli3_options
&
932 LPFC_SLI3_HBQ_ENABLED
934 lpfc_in_buf_free(phba
,
937 lpfc_post_buffer(phba
,
943 if (!(phba
->sli3_options
&
944 LPFC_SLI3_HBQ_ENABLED
))
945 lpfc_post_buffer(phba
,
954 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
955 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
956 evt_dat
->immed_dat
= phba
->ctx_idx
;
957 phba
->ctx_idx
= (phba
->ctx_idx
+ 1) % 64;
958 /* Provide warning for over-run of the ct_ctx array */
959 if (phba
->ct_ctx
[evt_dat
->immed_dat
].flags
&
961 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
962 "2717 CT context array entry "
963 "[%d] over-run: oxid:x%x, "
964 "sid:x%x\n", phba
->ctx_idx
,
966 evt_dat
->immed_dat
].oxid
,
968 evt_dat
->immed_dat
].SID
);
969 phba
->ct_ctx
[evt_dat
->immed_dat
].rxid
=
970 piocbq
->iocb
.ulpContext
;
971 phba
->ct_ctx
[evt_dat
->immed_dat
].oxid
=
972 piocbq
->iocb
.unsli3
.rcvsli3
.ox_id
;
973 phba
->ct_ctx
[evt_dat
->immed_dat
].SID
=
974 piocbq
->iocb
.un
.rcvels
.remoteID
;
975 phba
->ct_ctx
[evt_dat
->immed_dat
].flags
= UNSOL_VALID
;
977 evt_dat
->immed_dat
= piocbq
->iocb
.ulpContext
;
979 evt_dat
->type
= FC_REG_CT_EVENT
;
980 list_add(&evt_dat
->node
, &evt
->events_to_see
);
981 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
) {
982 wake_up_interruptible(&evt
->wq
);
983 lpfc_bsg_event_unref(evt
);
987 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
988 lpfc_bsg_event_unref(evt
);
993 job
->reply
->reply_payload_rcv_len
= size
;
994 /* make error code available to userspace */
995 job
->reply
->result
= 0;
997 /* complete the job back to userspace */
998 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1000 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1003 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1005 error_ct_unsol_exit
:
1006 if (!list_empty(&head
))
1008 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
1009 (evt_req_id
== SLI_CT_ELX_LOOPBACK
))
1015 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1016 * @job: SET_EVENT fc_bsg_job
1019 lpfc_bsg_hba_set_event(struct fc_bsg_job
*job
)
1021 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1022 struct lpfc_hba
*phba
= vport
->phba
;
1023 struct set_ct_event
*event_req
;
1024 struct lpfc_bsg_event
*evt
;
1026 struct bsg_job_data
*dd_data
= NULL
;
1028 unsigned long flags
;
1030 if (job
->request_len
<
1031 sizeof(struct fc_bsg_request
) + sizeof(struct set_ct_event
)) {
1032 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1033 "2612 Received SET_CT_EVENT below minimum "
1039 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1040 if (dd_data
== NULL
) {
1041 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1042 "2734 Failed allocation of dd_data\n");
1047 event_req
= (struct set_ct_event
*)
1048 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1049 ev_mask
= ((uint32_t)(unsigned long)event_req
->type_mask
&
1051 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1052 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1053 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1054 lpfc_bsg_event_ref(evt
);
1055 evt
->wait_time_stamp
= jiffies
;
1059 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1061 if (&evt
->node
== &phba
->ct_ev_waiters
) {
1062 /* no event waiting struct yet - first call */
1063 evt
= lpfc_bsg_event_new(ev_mask
, event_req
->ev_reg_id
,
1064 event_req
->ev_req_id
);
1066 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1067 "2617 Failed allocation of event "
1073 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1074 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1075 lpfc_bsg_event_ref(evt
);
1076 evt
->wait_time_stamp
= jiffies
;
1077 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1080 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1082 dd_data
->type
= TYPE_EVT
;
1083 dd_data
->context_un
.evt
= evt
;
1084 evt
->set_job
= job
; /* for unsolicited command */
1085 job
->dd_data
= dd_data
; /* for fc transport timeout callback*/
1086 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1087 return 0; /* call job done later */
1090 if (dd_data
!= NULL
)
1093 job
->dd_data
= NULL
;
1098 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1099 * @job: GET_EVENT fc_bsg_job
1102 lpfc_bsg_hba_get_event(struct fc_bsg_job
*job
)
1104 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1105 struct lpfc_hba
*phba
= vport
->phba
;
1106 struct get_ct_event
*event_req
;
1107 struct get_ct_event_reply
*event_reply
;
1108 struct lpfc_bsg_event
*evt
;
1109 struct event_data
*evt_dat
= NULL
;
1110 unsigned long flags
;
1113 if (job
->request_len
<
1114 sizeof(struct fc_bsg_request
) + sizeof(struct get_ct_event
)) {
1115 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1116 "2613 Received GET_CT_EVENT request below "
1122 event_req
= (struct get_ct_event
*)
1123 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1125 event_reply
= (struct get_ct_event_reply
*)
1126 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
1127 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1128 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1129 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1130 if (list_empty(&evt
->events_to_get
))
1132 lpfc_bsg_event_ref(evt
);
1133 evt
->wait_time_stamp
= jiffies
;
1134 evt_dat
= list_entry(evt
->events_to_get
.prev
,
1135 struct event_data
, node
);
1136 list_del(&evt_dat
->node
);
1140 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1142 /* The app may continue to ask for event data until it gets
1143 * an error indicating that there isn't anymore
1145 if (evt_dat
== NULL
) {
1146 job
->reply
->reply_payload_rcv_len
= 0;
1151 if (evt_dat
->len
> job
->request_payload
.payload_len
) {
1152 evt_dat
->len
= job
->request_payload
.payload_len
;
1153 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1154 "2618 Truncated event data at %d "
1156 job
->request_payload
.payload_len
);
1159 event_reply
->type
= evt_dat
->type
;
1160 event_reply
->immed_data
= evt_dat
->immed_dat
;
1161 if (evt_dat
->len
> 0)
1162 job
->reply
->reply_payload_rcv_len
=
1163 sg_copy_from_buffer(job
->request_payload
.sg_list
,
1164 job
->request_payload
.sg_cnt
,
1165 evt_dat
->data
, evt_dat
->len
);
1167 job
->reply
->reply_payload_rcv_len
= 0;
1170 kfree(evt_dat
->data
);
1174 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1175 lpfc_bsg_event_unref(evt
);
1176 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1177 job
->dd_data
= NULL
;
1178 job
->reply
->result
= 0;
1183 job
->dd_data
= NULL
;
1184 job
->reply
->result
= rc
;
1189 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1190 * @phba: Pointer to HBA context object.
1191 * @cmdiocbq: Pointer to command iocb.
1192 * @rspiocbq: Pointer to response iocb.
1194 * This function is the completion handler for iocbs issued using
1195 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1196 * ring event handler function without any lock held. This function
1197 * can be called from both worker thread context and interrupt
1198 * context. This function also can be called from other thread which
1199 * cleans up the SLI layer objects.
1200 * This function copy the contents of the response iocb to the
1201 * response iocb memory object provided by the caller of
1202 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1203 * sleeps for the iocb completion.
1206 lpfc_issue_ct_rsp_cmp(struct lpfc_hba
*phba
,
1207 struct lpfc_iocbq
*cmdiocbq
,
1208 struct lpfc_iocbq
*rspiocbq
)
1210 struct bsg_job_data
*dd_data
;
1211 struct fc_bsg_job
*job
;
1213 struct lpfc_dmabuf
*bmp
;
1214 struct lpfc_nodelist
*ndlp
;
1215 unsigned long flags
;
1218 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1219 dd_data
= cmdiocbq
->context2
;
1220 /* normal completion and timeout crossed paths, already done */
1222 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1226 job
= dd_data
->context_un
.iocb
.set_job
;
1227 bmp
= dd_data
->context_un
.iocb
.bmp
;
1228 rsp
= &rspiocbq
->iocb
;
1229 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
1231 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1232 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1234 if (rsp
->ulpStatus
) {
1235 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1236 switch (rsp
->un
.ulpWord
[4] & 0xff) {
1237 case IOERR_SEQUENCE_TIMEOUT
:
1240 case IOERR_INVALID_RPI
:
1250 job
->reply
->reply_payload_rcv_len
=
1251 rsp
->un
.genreq64
.bdl
.bdeSize
;
1253 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1254 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1258 /* make error code available to userspace */
1259 job
->reply
->result
= rc
;
1260 job
->dd_data
= NULL
;
1261 /* complete the job back to userspace */
1263 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1268 * lpfc_issue_ct_rsp - issue a ct response
1269 * @phba: Pointer to HBA context object.
1270 * @job: Pointer to the job object.
1271 * @tag: tag index value into the ports context exchange array.
1272 * @bmp: Pointer to a dma buffer descriptor.
1273 * @num_entry: Number of enties in the bde.
1276 lpfc_issue_ct_rsp(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
, uint32_t tag
,
1277 struct lpfc_dmabuf
*bmp
, int num_entry
)
1280 struct lpfc_iocbq
*ctiocb
= NULL
;
1282 struct lpfc_nodelist
*ndlp
= NULL
;
1283 struct bsg_job_data
*dd_data
;
1286 /* allocate our bsg tracking structure */
1287 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1289 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1290 "2736 Failed allocation of dd_data\n");
1295 /* Allocate buffer for command iocb */
1296 ctiocb
= lpfc_sli_get_iocbq(phba
);
1302 icmd
= &ctiocb
->iocb
;
1303 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
1304 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
1305 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
1306 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1307 icmd
->un
.xseq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
1308 icmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
1309 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1310 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_SOL_CTL
;
1311 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1313 /* Fill in rest of iocb */
1314 icmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
1315 icmd
->ulpBdeCount
= 1;
1317 icmd
->ulpClass
= CLASS3
;
1318 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1319 /* Do not issue unsol response if oxid not marked as valid */
1320 if (!(phba
->ct_ctx
[tag
].flags
& UNSOL_VALID
)) {
1322 goto issue_ct_rsp_exit
;
1324 icmd
->ulpContext
= phba
->ct_ctx
[tag
].rxid
;
1325 icmd
->unsli3
.rcvsli3
.ox_id
= phba
->ct_ctx
[tag
].oxid
;
1326 ndlp
= lpfc_findnode_did(phba
->pport
, phba
->ct_ctx
[tag
].SID
);
1328 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1329 "2721 ndlp null for oxid %x SID %x\n",
1331 phba
->ct_ctx
[tag
].SID
);
1333 goto issue_ct_rsp_exit
;
1336 /* Check if the ndlp is active */
1337 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1339 goto issue_ct_rsp_exit
;
1342 /* get a refernece count so the ndlp doesn't go away while
1345 if (!lpfc_nlp_get(ndlp
)) {
1347 goto issue_ct_rsp_exit
;
1350 icmd
->un
.ulpWord
[3] =
1351 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
1353 /* The exchange is done, mark the entry as invalid */
1354 phba
->ct_ctx
[tag
].flags
&= ~UNSOL_VALID
;
1356 icmd
->ulpContext
= (ushort
) tag
;
1358 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
1360 /* Xmit CT response on exchange <xid> */
1361 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1362 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1363 icmd
->ulpContext
, icmd
->ulpIoTag
, tag
, phba
->link_state
);
1365 ctiocb
->iocb_cmpl
= NULL
;
1366 ctiocb
->iocb_flag
|= LPFC_IO_LIBDFC
;
1367 ctiocb
->vport
= phba
->pport
;
1368 ctiocb
->context3
= bmp
;
1370 ctiocb
->iocb_cmpl
= lpfc_issue_ct_rsp_cmp
;
1371 ctiocb
->context2
= dd_data
;
1372 ctiocb
->context1
= ndlp
;
1373 dd_data
->type
= TYPE_IOCB
;
1374 dd_data
->context_un
.iocb
.cmdiocbq
= ctiocb
;
1375 dd_data
->context_un
.iocb
.rspiocbq
= NULL
;
1376 dd_data
->context_un
.iocb
.set_job
= job
;
1377 dd_data
->context_un
.iocb
.bmp
= bmp
;
1378 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
1380 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1381 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1383 goto issue_ct_rsp_exit
;
1385 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1386 writel(creg_val
, phba
->HCregaddr
);
1387 readl(phba
->HCregaddr
); /* flush */
1390 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
1392 if (rc
== IOCB_SUCCESS
)
1393 return 0; /* done for now */
1396 lpfc_sli_release_iocbq(phba
, ctiocb
);
1404 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1405 * @job: SEND_MGMT_RESP fc_bsg_job
1408 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job
*job
)
1410 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1411 struct lpfc_hba
*phba
= vport
->phba
;
1412 struct send_mgmt_resp
*mgmt_resp
= (struct send_mgmt_resp
*)
1413 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1414 struct ulp_bde64
*bpl
;
1415 struct lpfc_dmabuf
*bmp
= NULL
;
1416 struct scatterlist
*sgel
= NULL
;
1420 uint32_t tag
= mgmt_resp
->tag
;
1421 unsigned long reqbfrcnt
=
1422 (unsigned long)job
->request_payload
.payload_len
;
1425 /* in case no data is transferred */
1426 job
->reply
->reply_payload_rcv_len
= 0;
1428 if (!reqbfrcnt
|| (reqbfrcnt
> (80 * BUF_SZ_4K
))) {
1430 goto send_mgmt_rsp_exit
;
1433 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1436 goto send_mgmt_rsp_exit
;
1439 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
1442 goto send_mgmt_rsp_free_bmp
;
1445 INIT_LIST_HEAD(&bmp
->list
);
1446 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1447 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1448 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1449 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
1450 busaddr
= sg_dma_address(sgel
);
1451 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1452 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1453 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
1454 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
1455 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
1459 rc
= lpfc_issue_ct_rsp(phba
, job
, tag
, bmp
, request_nseg
);
1461 if (rc
== IOCB_SUCCESS
)
1462 return 0; /* done for now */
1464 /* TBD need to handle a timeout */
1465 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1466 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1468 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1470 send_mgmt_rsp_free_bmp
:
1473 /* make error code available to userspace */
1474 job
->reply
->result
= rc
;
1475 job
->dd_data
= NULL
;
1480 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1481 * @phba: Pointer to HBA context object.
1483 * This function is responsible for preparing driver for diag loopback
1487 lpfc_bsg_diag_mode_enter(struct lpfc_hba
*phba
)
1489 struct lpfc_vport
**vports
;
1490 struct Scsi_Host
*shost
;
1491 struct lpfc_sli
*psli
;
1492 struct lpfc_sli_ring
*pring
;
1499 pring
= &psli
->ring
[LPFC_FCP_RING
];
1503 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1504 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
1505 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
1508 vports
= lpfc_create_vport_work_array(phba
);
1510 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1511 shost
= lpfc_shost_from_vport(vports
[i
]);
1512 scsi_block_requests(shost
);
1514 lpfc_destroy_vport_work_array(phba
, vports
);
1516 shost
= lpfc_shost_from_vport(phba
->pport
);
1517 scsi_block_requests(shost
);
1520 while (pring
->txcmplq_cnt
) {
1521 if (i
++ > 500) /* wait up to 5 seconds */
1529 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1530 * @phba: Pointer to HBA context object.
1532 * This function is responsible for driver exit processing of setting up
1533 * diag loopback mode on device.
1536 lpfc_bsg_diag_mode_exit(struct lpfc_hba
*phba
)
1538 struct Scsi_Host
*shost
;
1539 struct lpfc_vport
**vports
;
1542 vports
= lpfc_create_vport_work_array(phba
);
1544 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1545 shost
= lpfc_shost_from_vport(vports
[i
]);
1546 scsi_unblock_requests(shost
);
1548 lpfc_destroy_vport_work_array(phba
, vports
);
1550 shost
= lpfc_shost_from_vport(phba
->pport
);
1551 scsi_unblock_requests(shost
);
1557 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1558 * @phba: Pointer to HBA context object.
1559 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1561 * This function is responsible for placing an sli3 port into diagnostic
1562 * loopback mode in order to perform a diagnostic loopback test.
1563 * All new scsi requests are blocked, a small delay is used to allow the
1564 * scsi requests to complete then the link is brought down. If the link is
1565 * is placed in loopback mode then scsi requests are again allowed
1566 * so the scsi mid-layer doesn't give up on the port.
1567 * All of this is done in-line.
1570 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1572 struct diag_mode_set
*loopback_mode
;
1573 uint32_t link_flags
;
1575 LPFC_MBOXQ_t
*pmboxq
= NULL
;
1576 int mbxstatus
= MBX_SUCCESS
;
1580 /* no data to return just the return code */
1581 job
->reply
->reply_payload_rcv_len
= 0;
1583 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1584 sizeof(struct diag_mode_set
)) {
1585 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1586 "2738 Received DIAG MODE request size:%d "
1587 "below the minimum size:%d\n",
1589 (int)(sizeof(struct fc_bsg_request
) +
1590 sizeof(struct diag_mode_set
)));
1595 rc
= lpfc_bsg_diag_mode_enter(phba
);
1599 /* bring the link to diagnostic mode */
1600 loopback_mode
= (struct diag_mode_set
*)
1601 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1602 link_flags
= loopback_mode
->type
;
1603 timeout
= loopback_mode
->timeout
* 100;
1605 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1608 goto loopback_mode_exit
;
1610 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1611 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1612 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1614 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1616 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0)) {
1617 /* wait for link down before proceeding */
1619 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1620 if (i
++ > timeout
) {
1622 goto loopback_mode_exit
;
1627 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1628 if (link_flags
== INTERNAL_LOOP_BACK
)
1629 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
1631 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
=
1632 FLAGS_TOPOLOGY_MODE_LOOP
;
1634 pmboxq
->u
.mb
.mbxCommand
= MBX_INIT_LINK
;
1635 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1637 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1640 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1643 spin_lock_irq(&phba
->hbalock
);
1644 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1645 spin_unlock_irq(&phba
->hbalock
);
1646 /* wait for the link attention interrupt */
1650 while (phba
->link_state
!= LPFC_HBA_READY
) {
1651 if (i
++ > timeout
) {
1664 lpfc_bsg_diag_mode_exit(phba
);
1667 * Let SLI layer release mboxq if mbox command completed after timeout.
1669 if (pmboxq
&& mbxstatus
!= MBX_TIMEOUT
)
1670 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1673 /* make error code available to userspace */
1674 job
->reply
->result
= rc
;
1675 /* complete the job back to userspace if no error */
1682 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1683 * @phba: Pointer to HBA context object.
1684 * @diag: Flag for set link to diag or nomral operation state.
1686 * This function is responsible for issuing a sli4 mailbox command for setting
1687 * link to either diag state or normal operation state.
1690 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba
*phba
, uint32_t diag
)
1692 LPFC_MBOXQ_t
*pmboxq
;
1693 struct lpfc_mbx_set_link_diag_state
*link_diag_state
;
1694 uint32_t req_len
, alloc_len
;
1695 int mbxstatus
= MBX_SUCCESS
, rc
;
1697 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1701 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
1702 sizeof(struct lpfc_sli4_cfg_mhdr
));
1703 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1704 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
1705 req_len
, LPFC_SLI4_MBX_EMBED
);
1706 if (alloc_len
!= req_len
) {
1708 goto link_diag_state_set_out
;
1710 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1711 "3128 Set link to diagnostic state:x%x (x%x/x%x)\n",
1712 diag
, phba
->sli4_hba
.lnk_info
.lnk_tp
,
1713 phba
->sli4_hba
.lnk_info
.lnk_no
);
1715 link_diag_state
= &pmboxq
->u
.mqe
.un
.link_diag_state
;
1716 bf_set(lpfc_mbx_set_diag_state_link_num
, &link_diag_state
->u
.req
,
1717 phba
->sli4_hba
.lnk_info
.lnk_no
);
1718 bf_set(lpfc_mbx_set_diag_state_link_type
, &link_diag_state
->u
.req
,
1719 phba
->sli4_hba
.lnk_info
.lnk_tp
);
1721 bf_set(lpfc_mbx_set_diag_state_diag
,
1722 &link_diag_state
->u
.req
, 1);
1724 bf_set(lpfc_mbx_set_diag_state_diag
,
1725 &link_diag_state
->u
.req
, 0);
1727 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1729 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0))
1734 link_diag_state_set_out
:
1735 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1736 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1742 * lpfc_sli4_bsg_set_internal_loopback - set sli4 internal loopback diagnostic
1743 * @phba: Pointer to HBA context object.
1745 * This function is responsible for issuing a sli4 mailbox command for setting
1746 * up internal loopback diagnostic.
1749 lpfc_sli4_bsg_set_internal_loopback(struct lpfc_hba
*phba
)
1751 LPFC_MBOXQ_t
*pmboxq
;
1752 uint32_t req_len
, alloc_len
;
1753 struct lpfc_mbx_set_link_diag_loopback
*link_diag_loopback
;
1754 int mbxstatus
= MBX_SUCCESS
, rc
= 0;
1756 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1759 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_loopback
) -
1760 sizeof(struct lpfc_sli4_cfg_mhdr
));
1761 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1762 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK
,
1763 req_len
, LPFC_SLI4_MBX_EMBED
);
1764 if (alloc_len
!= req_len
) {
1765 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1768 link_diag_loopback
= &pmboxq
->u
.mqe
.un
.link_diag_loopback
;
1769 bf_set(lpfc_mbx_set_diag_state_link_num
,
1770 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_no
);
1771 bf_set(lpfc_mbx_set_diag_state_link_type
,
1772 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_tp
);
1773 bf_set(lpfc_mbx_set_diag_lpbk_type
, &link_diag_loopback
->u
.req
,
1774 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL
);
1776 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1777 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
)) {
1778 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1779 "3127 Failed setup loopback mode mailbox "
1780 "command, rc:x%x, status:x%x\n", mbxstatus
,
1781 pmboxq
->u
.mb
.mbxStatus
);
1784 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1785 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1790 * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic
1791 * @phba: Pointer to HBA context object.
1793 * This function set up SLI4 FC port registrations for diagnostic run, which
1794 * includes all the rpis, vfi, and also vpi.
1797 lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba
*phba
)
1801 if (phba
->pport
->fc_flag
& FC_VFI_REGISTERED
) {
1802 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1803 "3136 Port still had vfi registered: "
1804 "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
1805 phba
->pport
->fc_myDID
, phba
->fcf
.fcfi
,
1806 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
],
1807 phba
->vpi_ids
[phba
->pport
->vpi
]);
1810 rc
= lpfc_issue_reg_vfi(phba
->pport
);
1815 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
1816 * @phba: Pointer to HBA context object.
1817 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1819 * This function is responsible for placing an sli4 port into diagnostic
1820 * loopback mode in order to perform a diagnostic loopback test.
1823 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1825 struct diag_mode_set
*loopback_mode
;
1826 uint32_t link_flags
, timeout
;
1829 /* no data to return just the return code */
1830 job
->reply
->reply_payload_rcv_len
= 0;
1832 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1833 sizeof(struct diag_mode_set
)) {
1834 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1835 "3011 Received DIAG MODE request size:%d "
1836 "below the minimum size:%d\n",
1838 (int)(sizeof(struct fc_bsg_request
) +
1839 sizeof(struct diag_mode_set
)));
1844 rc
= lpfc_bsg_diag_mode_enter(phba
);
1848 /* indicate we are in loobpack diagnostic mode */
1849 spin_lock_irq(&phba
->hbalock
);
1850 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1851 spin_unlock_irq(&phba
->hbalock
);
1853 /* reset port to start frome scratch */
1854 rc
= lpfc_selective_reset(phba
);
1858 /* bring the link to diagnostic mode */
1859 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1860 "3129 Bring link to diagnostic state.\n");
1861 loopback_mode
= (struct diag_mode_set
*)
1862 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1863 link_flags
= loopback_mode
->type
;
1864 timeout
= loopback_mode
->timeout
* 100;
1866 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
1868 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1869 "3130 Failed to bring link to diagnostic "
1870 "state, rc:x%x\n", rc
);
1871 goto loopback_mode_exit
;
1874 /* wait for link down before proceeding */
1876 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1877 if (i
++ > timeout
) {
1879 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1880 "3131 Timeout waiting for link to "
1881 "diagnostic mode, timeout:%d ms\n",
1883 goto loopback_mode_exit
;
1888 /* set up loopback mode */
1889 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1890 "3132 Set up loopback mode:x%x\n", link_flags
);
1892 if (link_flags
== INTERNAL_LOOP_BACK
)
1893 rc
= lpfc_sli4_bsg_set_internal_loopback(phba
);
1894 else if (link_flags
== EXTERNAL_LOOP_BACK
)
1895 rc
= lpfc_hba_init_link_fc_topology(phba
,
1896 FLAGS_TOPOLOGY_MODE_PT_PT
,
1900 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
1901 "3141 Loopback mode:x%x not supported\n",
1903 goto loopback_mode_exit
;
1907 /* wait for the link attention interrupt */
1910 while (phba
->link_state
< LPFC_LINK_UP
) {
1911 if (i
++ > timeout
) {
1913 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1914 "3137 Timeout waiting for link up "
1915 "in loopback mode, timeout:%d ms\n",
1923 /* port resource registration setup for loopback diagnostic */
1925 /* set up a none zero myDID for loopback test */
1926 phba
->pport
->fc_myDID
= 1;
1927 rc
= lpfc_sli4_diag_fcport_reg_setup(phba
);
1929 goto loopback_mode_exit
;
1932 /* wait for the port ready */
1935 while (phba
->link_state
!= LPFC_HBA_READY
) {
1936 if (i
++ > timeout
) {
1938 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1939 "3133 Timeout waiting for port "
1940 "loopback mode ready, timeout:%d ms\n",
1949 /* clear loopback diagnostic mode */
1951 spin_lock_irq(&phba
->hbalock
);
1952 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
1953 spin_unlock_irq(&phba
->hbalock
);
1955 lpfc_bsg_diag_mode_exit(phba
);
1958 /* make error code available to userspace */
1959 job
->reply
->result
= rc
;
1960 /* complete the job back to userspace if no error */
1967 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
1968 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1970 * This function is responsible for responding to check and dispatch bsg diag
1971 * command from the user to proper driver action routines.
1974 lpfc_bsg_diag_loopback_mode(struct fc_bsg_job
*job
)
1976 struct Scsi_Host
*shost
;
1977 struct lpfc_vport
*vport
;
1978 struct lpfc_hba
*phba
;
1984 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1991 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1992 rc
= lpfc_sli3_bsg_diag_loopback_mode(phba
, job
);
1993 else if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1994 LPFC_SLI_INTF_IF_TYPE_2
)
1995 rc
= lpfc_sli4_bsg_diag_loopback_mode(phba
, job
);
2003 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
2004 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
2006 * This function is responsible for responding to check and dispatch bsg diag
2007 * command from the user to proper driver action routines.
2010 lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job
*job
)
2012 struct Scsi_Host
*shost
;
2013 struct lpfc_vport
*vport
;
2014 struct lpfc_hba
*phba
;
2015 struct diag_mode_set
*loopback_mode_end_cmd
;
2022 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2029 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2031 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2032 LPFC_SLI_INTF_IF_TYPE_2
)
2035 /* clear loopback diagnostic mode */
2036 spin_lock_irq(&phba
->hbalock
);
2037 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
2038 spin_unlock_irq(&phba
->hbalock
);
2039 loopback_mode_end_cmd
= (struct diag_mode_set
*)
2040 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2041 timeout
= loopback_mode_end_cmd
->timeout
* 100;
2043 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2045 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2046 "3139 Failed to bring link to diagnostic "
2047 "state, rc:x%x\n", rc
);
2048 goto loopback_mode_end_exit
;
2051 /* wait for link down before proceeding */
2053 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
2054 if (i
++ > timeout
) {
2056 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2057 "3140 Timeout waiting for link to "
2058 "diagnostic mode_end, timeout:%d ms\n",
2060 /* there is nothing much we can do here */
2066 /* reset port resource registrations */
2067 rc
= lpfc_selective_reset(phba
);
2068 phba
->pport
->fc_myDID
= 0;
2070 loopback_mode_end_exit
:
2071 /* make return code available to userspace */
2072 job
->reply
->result
= rc
;
2073 /* complete the job back to userspace if no error */
2080 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
2081 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
2083 * This function is to perform SLI4 diag link test request from the user
2087 lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job
*job
)
2089 struct Scsi_Host
*shost
;
2090 struct lpfc_vport
*vport
;
2091 struct lpfc_hba
*phba
;
2092 LPFC_MBOXQ_t
*pmboxq
;
2093 struct sli4_link_diag
*link_diag_test_cmd
;
2094 uint32_t req_len
, alloc_len
;
2096 struct lpfc_mbx_run_link_diag_test
*run_link_diag_test
;
2097 union lpfc_sli4_cfg_shdr
*shdr
;
2098 uint32_t shdr_status
, shdr_add_status
;
2099 struct diag_status
*diag_status_reply
;
2100 int mbxstatus
, rc
= 0;
2107 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2118 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2122 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2123 LPFC_SLI_INTF_IF_TYPE_2
) {
2128 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
2129 sizeof(struct sli4_link_diag
)) {
2130 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2131 "3013 Received LINK DIAG TEST request "
2132 " size:%d below the minimum size:%d\n",
2134 (int)(sizeof(struct fc_bsg_request
) +
2135 sizeof(struct sli4_link_diag
)));
2140 rc
= lpfc_bsg_diag_mode_enter(phba
);
2144 link_diag_test_cmd
= (struct sli4_link_diag
*)
2145 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2146 timeout
= link_diag_test_cmd
->timeout
* 100;
2148 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
2153 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2156 goto link_diag_test_exit
;
2159 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
2160 sizeof(struct lpfc_sli4_cfg_mhdr
));
2161 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2162 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
2163 req_len
, LPFC_SLI4_MBX_EMBED
);
2164 if (alloc_len
!= req_len
) {
2166 goto link_diag_test_exit
;
2168 run_link_diag_test
= &pmboxq
->u
.mqe
.un
.link_diag_test
;
2169 bf_set(lpfc_mbx_run_diag_test_link_num
, &run_link_diag_test
->u
.req
,
2170 phba
->sli4_hba
.lnk_info
.lnk_no
);
2171 bf_set(lpfc_mbx_run_diag_test_link_type
, &run_link_diag_test
->u
.req
,
2172 phba
->sli4_hba
.lnk_info
.lnk_tp
);
2173 bf_set(lpfc_mbx_run_diag_test_test_id
, &run_link_diag_test
->u
.req
,
2174 link_diag_test_cmd
->test_id
);
2175 bf_set(lpfc_mbx_run_diag_test_loops
, &run_link_diag_test
->u
.req
,
2176 link_diag_test_cmd
->loops
);
2177 bf_set(lpfc_mbx_run_diag_test_test_ver
, &run_link_diag_test
->u
.req
,
2178 link_diag_test_cmd
->test_version
);
2179 bf_set(lpfc_mbx_run_diag_test_err_act
, &run_link_diag_test
->u
.req
,
2180 link_diag_test_cmd
->error_action
);
2182 mbxstatus
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2184 shdr
= (union lpfc_sli4_cfg_shdr
*)
2185 &pmboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2186 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
2187 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
2188 if (shdr_status
|| shdr_add_status
|| mbxstatus
) {
2189 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2190 "3010 Run link diag test mailbox failed with "
2191 "mbx_status x%x status x%x, add_status x%x\n",
2192 mbxstatus
, shdr_status
, shdr_add_status
);
2195 diag_status_reply
= (struct diag_status
*)
2196 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
2198 if (job
->reply_len
<
2199 sizeof(struct fc_bsg_request
) + sizeof(struct diag_status
)) {
2200 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2201 "3012 Received Run link diag test reply "
2202 "below minimum size (%d): reply_len:%d\n",
2203 (int)(sizeof(struct fc_bsg_request
) +
2204 sizeof(struct diag_status
)),
2210 diag_status_reply
->mbox_status
= mbxstatus
;
2211 diag_status_reply
->shdr_status
= shdr_status
;
2212 diag_status_reply
->shdr_add_status
= shdr_add_status
;
2214 link_diag_test_exit
:
2215 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2218 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2220 lpfc_bsg_diag_mode_exit(phba
);
2223 /* make error code available to userspace */
2224 job
->reply
->result
= rc
;
2225 /* complete the job back to userspace if no error */
2232 * lpfcdiag_loop_self_reg - obtains a remote port login id
2233 * @phba: Pointer to HBA context object
2234 * @rpi: Pointer to a remote port login id
2236 * This function obtains a remote port login id so the diag loopback test
2237 * can send and receive its own unsolicited CT command.
2239 static int lpfcdiag_loop_self_reg(struct lpfc_hba
*phba
, uint16_t *rpi
)
2242 struct lpfc_dmabuf
*dmabuff
;
2245 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2249 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2250 status
= lpfc_reg_rpi(phba
, 0, phba
->pport
->fc_myDID
,
2251 (uint8_t *)&phba
->pport
->fc_sparam
,
2254 *rpi
= lpfc_sli4_alloc_rpi(phba
);
2255 status
= lpfc_reg_rpi(phba
, phba
->pport
->vpi
,
2256 phba
->pport
->fc_myDID
,
2257 (uint8_t *)&phba
->pport
->fc_sparam
,
2262 mempool_free(mbox
, phba
->mbox_mem_pool
);
2263 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2264 lpfc_sli4_free_rpi(phba
, *rpi
);
2268 dmabuff
= (struct lpfc_dmabuf
*) mbox
->context1
;
2269 mbox
->context1
= NULL
;
2270 mbox
->context2
= NULL
;
2271 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2273 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2274 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2276 if (status
!= MBX_TIMEOUT
)
2277 mempool_free(mbox
, phba
->mbox_mem_pool
);
2278 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2279 lpfc_sli4_free_rpi(phba
, *rpi
);
2283 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2284 *rpi
= mbox
->u
.mb
.un
.varWords
[0];
2286 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2288 mempool_free(mbox
, phba
->mbox_mem_pool
);
2293 * lpfcdiag_loop_self_unreg - unregs from the rpi
2294 * @phba: Pointer to HBA context object
2295 * @rpi: Remote port login id
2297 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2299 static int lpfcdiag_loop_self_unreg(struct lpfc_hba
*phba
, uint16_t rpi
)
2304 /* Allocate mboxq structure */
2305 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2309 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2310 lpfc_unreg_login(phba
, 0, rpi
, mbox
);
2312 lpfc_unreg_login(phba
, phba
->pport
->vpi
,
2313 phba
->sli4_hba
.rpi_ids
[rpi
], mbox
);
2315 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2317 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2318 if (status
!= MBX_TIMEOUT
)
2319 mempool_free(mbox
, phba
->mbox_mem_pool
);
2322 mempool_free(mbox
, phba
->mbox_mem_pool
);
2323 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2324 lpfc_sli4_free_rpi(phba
, rpi
);
2329 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2330 * @phba: Pointer to HBA context object
2331 * @rpi: Remote port login id
2332 * @txxri: Pointer to transmit exchange id
2333 * @rxxri: Pointer to response exchabge id
2335 * This function obtains the transmit and receive ids required to send
2336 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2337 * flags are used to the unsolicted response handler is able to process
2338 * the ct command sent on the same port.
2340 static int lpfcdiag_loop_get_xri(struct lpfc_hba
*phba
, uint16_t rpi
,
2341 uint16_t *txxri
, uint16_t * rxxri
)
2343 struct lpfc_bsg_event
*evt
;
2344 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2346 struct lpfc_dmabuf
*dmabuf
;
2347 struct ulp_bde64
*bpl
= NULL
;
2348 struct lpfc_sli_ct_request
*ctreq
= NULL
;
2352 unsigned long flags
;
2356 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2357 SLI_CT_ELX_LOOPBACK
);
2361 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2362 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2363 lpfc_bsg_event_ref(evt
);
2364 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2366 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2367 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2369 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2371 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, 0, &dmabuf
->phys
);
2373 INIT_LIST_HEAD(&dmabuf
->list
);
2374 bpl
= (struct ulp_bde64
*) dmabuf
->virt
;
2375 memset(bpl
, 0, sizeof(*bpl
));
2376 ctreq
= (struct lpfc_sli_ct_request
*)(bpl
+ 1);
2378 le32_to_cpu(putPaddrHigh(dmabuf
->phys
+
2381 le32_to_cpu(putPaddrLow(dmabuf
->phys
+
2383 bpl
->tus
.f
.bdeFlags
= 0;
2384 bpl
->tus
.f
.bdeSize
= ELX_LOOPBACK_HEADER_SZ
;
2385 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2389 if (cmdiocbq
== NULL
|| rspiocbq
== NULL
||
2390 dmabuf
== NULL
|| bpl
== NULL
|| ctreq
== NULL
||
2391 dmabuf
->virt
== NULL
) {
2393 goto err_get_xri_exit
;
2396 cmd
= &cmdiocbq
->iocb
;
2397 rsp
= &rspiocbq
->iocb
;
2399 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2401 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2402 ctreq
->RevisionId
.bits
.InId
= 0;
2403 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2404 ctreq
->FsSubType
= 0;
2405 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_XRI_SETUP
;
2406 ctreq
->CommandResponse
.bits
.Size
= 0;
2409 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(dmabuf
->phys
);
2410 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(dmabuf
->phys
);
2411 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2412 cmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(*bpl
);
2414 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= LA
;
2415 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2416 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2417 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2419 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CR
;
2420 cmd
->ulpBdeCount
= 1;
2422 cmd
->ulpClass
= CLASS3
;
2423 cmd
->ulpContext
= rpi
;
2425 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2426 cmdiocbq
->vport
= phba
->pport
;
2428 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2430 (phba
->fc_ratov
* 2)
2431 + LPFC_DRVR_TIMEOUT
);
2434 goto err_get_xri_exit
;
2436 *txxri
= rsp
->ulpContext
;
2439 evt
->wait_time_stamp
= jiffies
;
2440 time_left
= wait_event_interruptible_timeout(
2441 evt
->wq
, !list_empty(&evt
->events_to_see
),
2442 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
2443 if (list_empty(&evt
->events_to_see
))
2444 ret_val
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
2446 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2447 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2448 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2449 *rxxri
= (list_entry(evt
->events_to_get
.prev
,
2450 typeof(struct event_data
),
2456 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2457 lpfc_bsg_event_unref(evt
); /* release ref */
2458 lpfc_bsg_event_unref(evt
); /* delete */
2459 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2463 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2467 if (cmdiocbq
&& (iocb_stat
!= IOCB_TIMEDOUT
))
2468 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2470 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2475 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2476 * @phba: Pointer to HBA context object
2478 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and.
2479 * retruns the pointer to the buffer.
2481 static struct lpfc_dmabuf
*
2482 lpfc_bsg_dma_page_alloc(struct lpfc_hba
*phba
)
2484 struct lpfc_dmabuf
*dmabuf
;
2485 struct pci_dev
*pcidev
= phba
->pcidev
;
2487 /* allocate dma buffer struct */
2488 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2492 INIT_LIST_HEAD(&dmabuf
->list
);
2494 /* now, allocate dma buffer */
2495 dmabuf
->virt
= dma_alloc_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2496 &(dmabuf
->phys
), GFP_KERNEL
);
2498 if (!dmabuf
->virt
) {
2502 memset((uint8_t *)dmabuf
->virt
, 0, BSG_MBOX_SIZE
);
2508 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2509 * @phba: Pointer to HBA context object.
2510 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2512 * This routine just simply frees a dma buffer and its associated buffer
2513 * descriptor referred by @dmabuf.
2516 lpfc_bsg_dma_page_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*dmabuf
)
2518 struct pci_dev
*pcidev
= phba
->pcidev
;
2524 dma_free_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2525 dmabuf
->virt
, dmabuf
->phys
);
2531 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2532 * @phba: Pointer to HBA context object.
2533 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2535 * This routine just simply frees all dma buffers and their associated buffer
2536 * descriptors referred by @dmabuf_list.
2539 lpfc_bsg_dma_page_list_free(struct lpfc_hba
*phba
,
2540 struct list_head
*dmabuf_list
)
2542 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
2544 if (list_empty(dmabuf_list
))
2547 list_for_each_entry_safe(dmabuf
, next_dmabuf
, dmabuf_list
, list
) {
2548 list_del_init(&dmabuf
->list
);
2549 lpfc_bsg_dma_page_free(phba
, dmabuf
);
2555 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2556 * @phba: Pointer to HBA context object
2557 * @bpl: Pointer to 64 bit bde structure
2558 * @size: Number of bytes to process
2559 * @nocopydata: Flag to copy user data into the allocated buffer
2561 * This function allocates page size buffers and populates an lpfc_dmabufext.
2562 * If allowed the user data pointed to with indataptr is copied into the kernel
2563 * memory. The chained list of page size buffers is returned.
2565 static struct lpfc_dmabufext
*
2566 diag_cmd_data_alloc(struct lpfc_hba
*phba
,
2567 struct ulp_bde64
*bpl
, uint32_t size
,
2570 struct lpfc_dmabufext
*mlist
= NULL
;
2571 struct lpfc_dmabufext
*dmp
;
2572 int cnt
, offset
= 0, i
= 0;
2573 struct pci_dev
*pcidev
;
2575 pcidev
= phba
->pcidev
;
2578 /* We get chunks of 4K */
2579 if (size
> BUF_SZ_4K
)
2584 /* allocate struct lpfc_dmabufext buffer header */
2585 dmp
= kmalloc(sizeof(struct lpfc_dmabufext
), GFP_KERNEL
);
2589 INIT_LIST_HEAD(&dmp
->dma
.list
);
2591 /* Queue it to a linked list */
2593 list_add_tail(&dmp
->dma
.list
, &mlist
->dma
.list
);
2597 /* allocate buffer */
2598 dmp
->dma
.virt
= dma_alloc_coherent(&pcidev
->dev
,
2609 bpl
->tus
.f
.bdeFlags
= 0;
2610 pci_dma_sync_single_for_device(phba
->pcidev
,
2611 dmp
->dma
.phys
, LPFC_BPL_SIZE
, PCI_DMA_TODEVICE
);
2614 memset((uint8_t *)dmp
->dma
.virt
, 0, cnt
);
2615 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2618 /* build buffer ptr list for IOCB */
2619 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dmp
->dma
.phys
));
2620 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dmp
->dma
.phys
));
2621 bpl
->tus
.f
.bdeSize
= (ushort
) cnt
;
2622 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2633 diag_cmd_data_free(phba
, mlist
);
2638 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2639 * @phba: Pointer to HBA context object
2640 * @rxxri: Receive exchange id
2641 * @len: Number of data bytes
2643 * This function allocates and posts a data buffer of sufficient size to receive
2644 * an unsolicted CT command.
2646 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba
*phba
, uint16_t rxxri
,
2649 struct lpfc_sli
*psli
= &phba
->sli
;
2650 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2651 struct lpfc_iocbq
*cmdiocbq
;
2653 struct list_head head
, *curr
, *next
;
2654 struct lpfc_dmabuf
*rxbmp
;
2655 struct lpfc_dmabuf
*dmp
;
2656 struct lpfc_dmabuf
*mp
[2] = {NULL
, NULL
};
2657 struct ulp_bde64
*rxbpl
= NULL
;
2659 struct lpfc_dmabufext
*rxbuffer
= NULL
;
2664 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2665 rxbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2666 if (rxbmp
!= NULL
) {
2667 rxbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &rxbmp
->phys
);
2669 INIT_LIST_HEAD(&rxbmp
->list
);
2670 rxbpl
= (struct ulp_bde64
*) rxbmp
->virt
;
2671 rxbuffer
= diag_cmd_data_alloc(phba
, rxbpl
, len
, 0);
2675 if (!cmdiocbq
|| !rxbmp
|| !rxbpl
|| !rxbuffer
) {
2677 goto err_post_rxbufs_exit
;
2680 /* Queue buffers for the receive exchange */
2681 num_bde
= (uint32_t)rxbuffer
->flag
;
2682 dmp
= &rxbuffer
->dma
;
2684 cmd
= &cmdiocbq
->iocb
;
2687 INIT_LIST_HEAD(&head
);
2688 list_add_tail(&head
, &dmp
->list
);
2689 list_for_each_safe(curr
, next
, &head
) {
2690 mp
[i
] = list_entry(curr
, struct lpfc_dmabuf
, list
);
2693 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2694 mp
[i
]->buffer_tag
= lpfc_sli_get_buffer_tag(phba
);
2695 cmd
->un
.quexri64cx
.buff
.bde
.addrHigh
=
2696 putPaddrHigh(mp
[i
]->phys
);
2697 cmd
->un
.quexri64cx
.buff
.bde
.addrLow
=
2698 putPaddrLow(mp
[i
]->phys
);
2699 cmd
->un
.quexri64cx
.buff
.bde
.tus
.f
.bdeSize
=
2700 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2701 cmd
->un
.quexri64cx
.buff
.buffer_tag
= mp
[i
]->buffer_tag
;
2702 cmd
->ulpCommand
= CMD_QUE_XRI64_CX
;
2705 cmd
->ulpBdeCount
= 1;
2706 cmd
->unsli3
.que_xri64cx_ext_words
.ebde_count
= 0;
2709 cmd
->un
.cont64
[i
].addrHigh
= putPaddrHigh(mp
[i
]->phys
);
2710 cmd
->un
.cont64
[i
].addrLow
= putPaddrLow(mp
[i
]->phys
);
2711 cmd
->un
.cont64
[i
].tus
.f
.bdeSize
=
2712 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2713 cmd
->ulpBdeCount
= ++i
;
2715 if ((--num_bde
> 0) && (i
< 2))
2718 cmd
->ulpCommand
= CMD_QUE_XRI_BUF64_CX
;
2722 cmd
->ulpClass
= CLASS3
;
2723 cmd
->ulpContext
= rxxri
;
2725 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
2727 if (iocb_stat
== IOCB_ERROR
) {
2728 diag_cmd_data_free(phba
,
2729 (struct lpfc_dmabufext
*)mp
[0]);
2731 diag_cmd_data_free(phba
,
2732 (struct lpfc_dmabufext
*)mp
[1]);
2733 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2735 goto err_post_rxbufs_exit
;
2738 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[0]);
2740 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[1]);
2744 /* The iocb was freed by lpfc_sli_issue_iocb */
2745 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2747 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2749 goto err_post_rxbufs_exit
;
2752 cmd
= &cmdiocbq
->iocb
;
2757 err_post_rxbufs_exit
:
2761 lpfc_mbuf_free(phba
, rxbmp
->virt
, rxbmp
->phys
);
2766 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2771 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
2772 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2774 * This function receives a user data buffer to be transmitted and received on
2775 * the same port, the link must be up and in loopback mode prior
2777 * 1. A kernel buffer is allocated to copy the user data into.
2778 * 2. The port registers with "itself".
2779 * 3. The transmit and receive exchange ids are obtained.
2780 * 4. The receive exchange id is posted.
2781 * 5. A new els loopback event is created.
2782 * 6. The command and response iocbs are allocated.
2783 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2785 * This function is meant to be called n times while the port is in loopback
2786 * so it is the apps responsibility to issue a reset to take the port out
2790 lpfc_bsg_diag_loopback_run(struct fc_bsg_job
*job
)
2792 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2793 struct lpfc_hba
*phba
= vport
->phba
;
2794 struct diag_mode_test
*diag_mode
;
2795 struct lpfc_bsg_event
*evt
;
2796 struct event_data
*evdat
;
2797 struct lpfc_sli
*psli
= &phba
->sli
;
2800 size_t segment_len
= 0, segment_offset
= 0, current_offset
= 0;
2802 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
= NULL
;
2803 IOCB_t
*cmd
, *rsp
= NULL
;
2804 struct lpfc_sli_ct_request
*ctreq
;
2805 struct lpfc_dmabuf
*txbmp
;
2806 struct ulp_bde64
*txbpl
= NULL
;
2807 struct lpfc_dmabufext
*txbuffer
= NULL
;
2808 struct list_head head
;
2809 struct lpfc_dmabuf
*curr
;
2810 uint16_t txxri
= 0, rxxri
;
2812 uint8_t *ptr
= NULL
, *rx_databuf
= NULL
;
2816 unsigned long flags
;
2817 void *dataout
= NULL
;
2820 /* in case no data is returned return just the return code */
2821 job
->reply
->reply_payload_rcv_len
= 0;
2823 if (job
->request_len
<
2824 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_test
)) {
2825 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2826 "2739 Received DIAG TEST request below minimum "
2829 goto loopback_test_exit
;
2832 if (job
->request_payload
.payload_len
!=
2833 job
->reply_payload
.payload_len
) {
2835 goto loopback_test_exit
;
2837 diag_mode
= (struct diag_mode_test
*)
2838 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2840 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
2841 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
2842 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
2844 goto loopback_test_exit
;
2847 if (!lpfc_is_link_up(phba
) || !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
2849 goto loopback_test_exit
;
2852 size
= job
->request_payload
.payload_len
;
2853 full_size
= size
+ ELX_LOOPBACK_HEADER_SZ
; /* plus the header */
2855 if ((size
== 0) || (size
> 80 * BUF_SZ_4K
)) {
2857 goto loopback_test_exit
;
2860 if (full_size
>= BUF_SZ_4K
) {
2862 * Allocate memory for ioctl data. If buffer is bigger than 64k,
2863 * then we allocate 64k and re-use that buffer over and over to
2864 * xfer the whole block. This is because Linux kernel has a
2865 * problem allocating more than 120k of kernel space memory. Saw
2866 * problem with GET_FCPTARGETMAPPING...
2868 if (size
<= (64 * 1024))
2869 total_mem
= full_size
;
2871 total_mem
= 64 * 1024;
2873 /* Allocate memory for ioctl data */
2874 total_mem
= BUF_SZ_4K
;
2876 dataout
= kmalloc(total_mem
, GFP_KERNEL
);
2877 if (dataout
== NULL
) {
2879 goto loopback_test_exit
;
2883 ptr
+= ELX_LOOPBACK_HEADER_SZ
;
2884 sg_copy_to_buffer(job
->request_payload
.sg_list
,
2885 job
->request_payload
.sg_cnt
,
2887 rc
= lpfcdiag_loop_self_reg(phba
, &rpi
);
2889 goto loopback_test_exit
;
2891 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2892 rc
= lpfcdiag_loop_get_xri(phba
, rpi
, &txxri
, &rxxri
);
2894 lpfcdiag_loop_self_unreg(phba
, rpi
);
2895 goto loopback_test_exit
;
2898 rc
= lpfcdiag_loop_post_rxbufs(phba
, rxxri
, full_size
);
2900 lpfcdiag_loop_self_unreg(phba
, rpi
);
2901 goto loopback_test_exit
;
2904 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2905 SLI_CT_ELX_LOOPBACK
);
2907 lpfcdiag_loop_self_unreg(phba
, rpi
);
2909 goto loopback_test_exit
;
2912 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2913 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2914 lpfc_bsg_event_ref(evt
);
2915 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2917 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2918 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2919 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2920 txbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2923 txbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &txbmp
->phys
);
2925 INIT_LIST_HEAD(&txbmp
->list
);
2926 txbpl
= (struct ulp_bde64
*) txbmp
->virt
;
2927 txbuffer
= diag_cmd_data_alloc(phba
,
2928 txbpl
, full_size
, 0);
2932 if (!cmdiocbq
|| !txbmp
|| !txbpl
|| !txbuffer
|| !txbmp
->virt
) {
2934 goto err_loopback_test_exit
;
2936 if ((phba
->sli_rev
< LPFC_SLI_REV4
) && !rspiocbq
) {
2938 goto err_loopback_test_exit
;
2941 cmd
= &cmdiocbq
->iocb
;
2942 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2943 rsp
= &rspiocbq
->iocb
;
2945 INIT_LIST_HEAD(&head
);
2946 list_add_tail(&head
, &txbuffer
->dma
.list
);
2947 list_for_each_entry(curr
, &head
, list
) {
2948 segment_len
= ((struct lpfc_dmabufext
*)curr
)->size
;
2949 if (current_offset
== 0) {
2951 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2952 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2953 ctreq
->RevisionId
.bits
.InId
= 0;
2954 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2955 ctreq
->FsSubType
= 0;
2956 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_DATA
;
2957 ctreq
->CommandResponse
.bits
.Size
= size
;
2958 segment_offset
= ELX_LOOPBACK_HEADER_SZ
;
2962 BUG_ON(segment_offset
>= segment_len
);
2963 memcpy(curr
->virt
+ segment_offset
,
2964 ptr
+ current_offset
,
2965 segment_len
- segment_offset
);
2967 current_offset
+= segment_len
- segment_offset
;
2968 BUG_ON(current_offset
> size
);
2972 /* Build the XMIT_SEQUENCE iocb */
2973 num_bde
= (uint32_t)txbuffer
->flag
;
2975 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(txbmp
->phys
);
2976 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(txbmp
->phys
);
2977 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2978 cmd
->un
.xseq64
.bdl
.bdeSize
= (num_bde
* sizeof(struct ulp_bde64
));
2980 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
2981 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2982 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2983 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2985 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
2986 cmd
->ulpBdeCount
= 1;
2988 cmd
->ulpClass
= CLASS3
;
2990 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2991 cmd
->ulpContext
= txxri
;
2993 cmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
2994 cmd
->un
.ulpWord
[3] = phba
->sli4_hba
.rpi_ids
[rpi
];
2995 cmdiocbq
->context3
= txbmp
;
2996 cmdiocbq
->sli4_xritag
= NO_XRI
;
2997 cmd
->unsli3
.rcvsli3
.ox_id
= 0xffff;
2999 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
3000 cmdiocbq
->vport
= phba
->pport
;
3001 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
3002 rspiocbq
, (phba
->fc_ratov
* 2) +
3005 if ((iocb_stat
!= IOCB_SUCCESS
) || ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3006 (rsp
->ulpStatus
!= IOCB_SUCCESS
))) {
3007 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3008 "3126 Failed loopback test issue iocb: "
3009 "iocb_stat:x%x\n", iocb_stat
);
3011 goto err_loopback_test_exit
;
3015 time_left
= wait_event_interruptible_timeout(
3016 evt
->wq
, !list_empty(&evt
->events_to_see
),
3017 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
3019 if (list_empty(&evt
->events_to_see
)) {
3020 rc
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
3021 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3022 "3125 Not receiving unsolicited event, "
3025 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3026 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
3027 evdat
= list_entry(evt
->events_to_get
.prev
,
3028 typeof(*evdat
), node
);
3029 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3030 rx_databuf
= evdat
->data
;
3031 if (evdat
->len
!= full_size
) {
3032 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3033 "1603 Loopback test did not receive expected "
3034 "data length. actual length 0x%x expected "
3036 evdat
->len
, full_size
);
3038 } else if (rx_databuf
== NULL
)
3042 /* skip over elx loopback header */
3043 rx_databuf
+= ELX_LOOPBACK_HEADER_SZ
;
3044 job
->reply
->reply_payload_rcv_len
=
3045 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3046 job
->reply_payload
.sg_cnt
,
3048 job
->reply
->reply_payload_rcv_len
= size
;
3052 err_loopback_test_exit
:
3053 lpfcdiag_loop_self_unreg(phba
, rpi
);
3055 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3056 lpfc_bsg_event_unref(evt
); /* release ref */
3057 lpfc_bsg_event_unref(evt
); /* delete */
3058 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3060 if (cmdiocbq
!= NULL
)
3061 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
3063 if (rspiocbq
!= NULL
)
3064 lpfc_sli_release_iocbq(phba
, rspiocbq
);
3066 if (txbmp
!= NULL
) {
3067 if (txbpl
!= NULL
) {
3068 if (txbuffer
!= NULL
)
3069 diag_cmd_data_free(phba
, txbuffer
);
3070 lpfc_mbuf_free(phba
, txbmp
->virt
, txbmp
->phys
);
3077 /* make error code available to userspace */
3078 job
->reply
->result
= rc
;
3079 job
->dd_data
= NULL
;
3080 /* complete the job back to userspace if no error */
3081 if (rc
== IOCB_SUCCESS
)
3087 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
3088 * @job: GET_DFC_REV fc_bsg_job
3091 lpfc_bsg_get_dfc_rev(struct fc_bsg_job
*job
)
3093 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
3094 struct lpfc_hba
*phba
= vport
->phba
;
3095 struct get_mgmt_rev
*event_req
;
3096 struct get_mgmt_rev_reply
*event_reply
;
3099 if (job
->request_len
<
3100 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev
)) {
3101 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3102 "2740 Received GET_DFC_REV request below "
3108 event_req
= (struct get_mgmt_rev
*)
3109 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3111 event_reply
= (struct get_mgmt_rev_reply
*)
3112 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
3114 if (job
->reply_len
<
3115 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev_reply
)) {
3116 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3117 "2741 Received GET_DFC_REV reply below "
3123 event_reply
->info
.a_Major
= MANAGEMENT_MAJOR_REV
;
3124 event_reply
->info
.a_Minor
= MANAGEMENT_MINOR_REV
;
3126 job
->reply
->result
= rc
;
3133 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
3134 * @phba: Pointer to HBA context object.
3135 * @pmboxq: Pointer to mailbox command.
3137 * This is completion handler function for mailbox commands issued from
3138 * lpfc_bsg_issue_mbox function. This function is called by the
3139 * mailbox event handler function with no lock held. This function
3140 * will wake up thread waiting on the wait queue pointed by context1
3144 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3146 struct bsg_job_data
*dd_data
;
3147 struct fc_bsg_job
*job
;
3149 unsigned long flags
;
3150 uint8_t *pmb
, *pmb_buf
;
3152 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3153 dd_data
= pmboxq
->context1
;
3154 /* job already timed out? */
3156 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3161 * The outgoing buffer is readily referred from the dma buffer,
3162 * just need to get header part from mailboxq structure.
3164 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3165 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3166 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3168 job
= dd_data
->context_un
.mbox
.set_job
;
3170 size
= job
->reply_payload
.payload_len
;
3171 job
->reply
->reply_payload_rcv_len
=
3172 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3173 job
->reply_payload
.sg_cnt
,
3175 /* need to hold the lock until we set job->dd_data to NULL
3176 * to hold off the timeout handler returning to the mid-layer
3177 * while we are still processing the job.
3179 job
->dd_data
= NULL
;
3180 dd_data
->context_un
.mbox
.set_job
= NULL
;
3181 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3183 dd_data
->context_un
.mbox
.set_job
= NULL
;
3184 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3187 mempool_free(dd_data
->context_un
.mbox
.pmboxq
, phba
->mbox_mem_pool
);
3188 lpfc_bsg_dma_page_free(phba
, dd_data
->context_un
.mbox
.dmabuffers
);
3192 job
->reply
->result
= 0;
3199 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3200 * @phba: Pointer to HBA context object.
3201 * @mb: Pointer to a mailbox object.
3202 * @vport: Pointer to a vport object.
3204 * Some commands require the port to be offline, some may not be called from
3207 static int lpfc_bsg_check_cmd_access(struct lpfc_hba
*phba
,
3208 MAILBOX_t
*mb
, struct lpfc_vport
*vport
)
3210 /* return negative error values for bsg job */
3211 switch (mb
->mbxCommand
) {
3215 case MBX_CONFIG_LINK
:
3216 case MBX_CONFIG_RING
:
3217 case MBX_RESET_RING
:
3218 case MBX_UNREG_LOGIN
:
3220 case MBX_DUMP_CONTEXT
:
3224 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
3225 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3226 "2743 Command 0x%x is illegal in on-line "
3232 case MBX_WRITE_VPARMS
:
3235 case MBX_READ_CONFIG
:
3236 case MBX_READ_RCONFIG
:
3237 case MBX_READ_STATUS
:
3240 case MBX_READ_LNK_STAT
:
3241 case MBX_DUMP_MEMORY
:
3243 case MBX_UPDATE_CFG
:
3244 case MBX_KILL_BOARD
:
3246 case MBX_LOAD_EXP_ROM
:
3248 case MBX_DEL_LD_ENTRY
:
3251 case MBX_SLI4_CONFIG
:
3252 case MBX_READ_EVENT_LOG
:
3253 case MBX_READ_EVENT_LOG_STATUS
:
3254 case MBX_WRITE_EVENT_LOG
:
3255 case MBX_PORT_CAPABILITIES
:
3256 case MBX_PORT_IOV_CONTROL
:
3257 case MBX_RUN_BIU_DIAG64
:
3259 case MBX_SET_VARIABLE
:
3260 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3261 "1226 mbox: set_variable 0x%x, 0x%x\n",
3263 mb
->un
.varWords
[1]);
3264 if ((mb
->un
.varWords
[0] == SETVAR_MLOMNT
)
3265 && (mb
->un
.varWords
[1] == 1)) {
3266 phba
->wait_4_mlo_maint_flg
= 1;
3267 } else if (mb
->un
.varWords
[0] == SETVAR_MLORST
) {
3268 spin_lock_irq(&phba
->hbalock
);
3269 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
3270 spin_unlock_irq(&phba
->hbalock
);
3271 phba
->fc_topology
= LPFC_TOPOLOGY_PT_PT
;
3274 case MBX_READ_SPARM64
:
3275 case MBX_READ_TOPOLOGY
:
3277 case MBX_REG_LOGIN64
:
3278 case MBX_CONFIG_PORT
:
3279 case MBX_RUN_BIU_DIAG
:
3281 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3282 "2742 Unknown Command 0x%x\n",
3291 * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
3292 * @phba: Pointer to HBA context object.
3294 * This is routine clean up and reset BSG handling of multi-buffer mbox
3298 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba
*phba
)
3300 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
)
3303 /* free all memory, including dma buffers */
3304 lpfc_bsg_dma_page_list_free(phba
,
3305 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3306 lpfc_bsg_dma_page_free(phba
, phba
->mbox_ext_buf_ctx
.mbx_dmabuf
);
3307 /* multi-buffer write mailbox command pass-through complete */
3308 memset((char *)&phba
->mbox_ext_buf_ctx
, 0,
3309 sizeof(struct lpfc_mbox_ext_buf_ctx
));
3310 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3316 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3317 * @phba: Pointer to HBA context object.
3318 * @pmboxq: Pointer to mailbox command.
3320 * This is routine handles BSG job for mailbox commands completions with
3321 * multiple external buffers.
3323 static struct fc_bsg_job
*
3324 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3326 struct bsg_job_data
*dd_data
;
3327 struct fc_bsg_job
*job
;
3328 uint8_t *pmb
, *pmb_buf
;
3329 unsigned long flags
;
3332 struct lpfc_dmabuf
*dmabuf
;
3333 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3336 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3337 dd_data
= pmboxq
->context1
;
3338 /* has the job already timed out? */
3340 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3346 * The outgoing buffer is readily referred from the dma buffer,
3347 * just need to get header part from mailboxq structure.
3349 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3350 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3351 /* Copy the byte swapped response mailbox back to the user */
3352 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3353 /* if there is any non-embedded extended data copy that too */
3354 dmabuf
= phba
->mbox_ext_buf_ctx
.mbx_dmabuf
;
3355 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3356 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3357 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3358 pmbx
= (uint8_t *)dmabuf
->virt
;
3359 /* byte swap the extended data following the mailbox command */
3360 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3361 &pmbx
[sizeof(MAILBOX_t
)],
3362 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[0].buf_len
);
3365 job
= dd_data
->context_un
.mbox
.set_job
;
3367 size
= job
->reply_payload
.payload_len
;
3368 job
->reply
->reply_payload_rcv_len
=
3369 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3370 job
->reply_payload
.sg_cnt
,
3372 /* result for successful */
3373 job
->reply
->result
= 0;
3374 job
->dd_data
= NULL
;
3375 /* need to hold the lock util we set job->dd_data to NULL
3376 * to hold off the timeout handler from midlayer to take
3379 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3380 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3381 "2937 SLI_CONFIG ext-buffer maibox command "
3382 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3383 phba
->mbox_ext_buf_ctx
.nembType
,
3384 phba
->mbox_ext_buf_ctx
.mboxType
, size
);
3385 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
,
3386 phba
->mbox_ext_buf_ctx
.nembType
,
3387 phba
->mbox_ext_buf_ctx
.mboxType
,
3388 dma_ebuf
, sta_pos_addr
,
3389 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
, 0);
3391 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3395 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3396 "2938 SLI_CONFIG ext-buffer maibox "
3397 "command (x%x/x%x) failure, rc:x%x\n",
3398 phba
->mbox_ext_buf_ctx
.nembType
,
3399 phba
->mbox_ext_buf_ctx
.mboxType
, rc
);
3401 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_DONE
;
3408 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3409 * @phba: Pointer to HBA context object.
3410 * @pmboxq: Pointer to mailbox command.
3412 * This is completion handler function for mailbox read commands with multiple
3416 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3418 struct fc_bsg_job
*job
;
3420 /* handle the BSG job with mailbox command */
3421 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3422 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3424 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3425 "2939 SLI_CONFIG ext-buffer rd maibox command "
3426 "complete, ctxState:x%x, mbxStatus:x%x\n",
3427 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3429 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3431 if (pmboxq
->u
.mb
.mbxStatus
|| phba
->mbox_ext_buf_ctx
.numBuf
== 1)
3432 lpfc_bsg_mbox_ext_session_reset(phba
);
3434 /* free base driver mailbox structure memory */
3435 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3437 /* complete the bsg job if we have it */
3445 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3446 * @phba: Pointer to HBA context object.
3447 * @pmboxq: Pointer to mailbox command.
3449 * This is completion handler function for mailbox write commands with multiple
3453 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3455 struct fc_bsg_job
*job
;
3457 /* handle the BSG job with the mailbox command */
3458 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3459 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3461 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3462 "2940 SLI_CONFIG ext-buffer wr maibox command "
3463 "complete, ctxState:x%x, mbxStatus:x%x\n",
3464 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3466 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3468 /* free all memory, including dma buffers */
3469 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3470 lpfc_bsg_mbox_ext_session_reset(phba
);
3472 /* complete the bsg job if we have it */
3480 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba
*phba
, enum nemb_type nemb_tp
,
3481 uint32_t index
, struct lpfc_dmabuf
*mbx_dmabuf
,
3482 struct lpfc_dmabuf
*ext_dmabuf
)
3484 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3486 /* pointer to the start of mailbox command */
3487 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)mbx_dmabuf
->virt
;
3489 if (nemb_tp
== nemb_mse
) {
3491 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3493 putPaddrHigh(mbx_dmabuf
->phys
+
3495 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3497 putPaddrLow(mbx_dmabuf
->phys
+
3499 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3500 "2943 SLI_CONFIG(mse)[%d], "
3501 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3503 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3505 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3507 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3510 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3512 putPaddrHigh(ext_dmabuf
->phys
);
3513 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3515 putPaddrLow(ext_dmabuf
->phys
);
3516 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3517 "2944 SLI_CONFIG(mse)[%d], "
3518 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3520 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3522 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3524 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3529 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3531 putPaddrHigh(mbx_dmabuf
->phys
+
3533 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3535 putPaddrLow(mbx_dmabuf
->phys
+
3537 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3538 "3007 SLI_CONFIG(hbd)[%d], "
3539 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3541 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3543 sli_config_emb1_subsys
.hbd
[index
]),
3544 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3546 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3550 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3552 putPaddrHigh(ext_dmabuf
->phys
);
3553 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3555 putPaddrLow(ext_dmabuf
->phys
);
3556 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3557 "3008 SLI_CONFIG(hbd)[%d], "
3558 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3560 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3562 sli_config_emb1_subsys
.hbd
[index
]),
3563 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3565 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3573 * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
3574 * @phba: Pointer to HBA context object.
3575 * @mb: Pointer to a BSG mailbox object.
3576 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3577 * @dmabuff: Pointer to a DMA buffer descriptor.
3579 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3580 * non-embedded external bufffers.
3583 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3584 enum nemb_type nemb_tp
,
3585 struct lpfc_dmabuf
*dmabuf
)
3587 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3588 struct dfc_mbox_req
*mbox_req
;
3589 struct lpfc_dmabuf
*curr_dmabuf
, *next_dmabuf
;
3590 uint32_t ext_buf_cnt
, ext_buf_index
;
3591 struct lpfc_dmabuf
*ext_dmabuf
= NULL
;
3592 struct bsg_job_data
*dd_data
= NULL
;
3593 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3599 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3601 /* pointer to the start of mailbox command */
3602 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3604 if (nemb_tp
== nemb_mse
) {
3605 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3606 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3607 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3608 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3609 "2945 Handled SLI_CONFIG(mse) rd, "
3610 "ext_buf_cnt(%d) out of range(%d)\n",
3612 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3616 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3617 "2941 Handled SLI_CONFIG(mse) rd, "
3618 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3620 /* sanity check on interface type for support */
3621 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3622 LPFC_SLI_INTF_IF_TYPE_2
) {
3626 /* nemb_tp == nemb_hbd */
3627 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3628 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3629 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3630 "2946 Handled SLI_CONFIG(hbd) rd, "
3631 "ext_buf_cnt(%d) out of range(%d)\n",
3633 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3637 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3638 "2942 Handled SLI_CONFIG(hbd) rd, "
3639 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3642 /* before dma descriptor setup */
3643 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3644 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3646 /* reject non-embedded mailbox command with none external buffer */
3647 if (ext_buf_cnt
== 0) {
3650 } else if (ext_buf_cnt
> 1) {
3651 /* additional external read buffers */
3652 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3653 ext_dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
3658 list_add_tail(&ext_dmabuf
->list
,
3659 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3663 /* bsg tracking structure */
3664 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3670 /* mailbox command structure for base driver */
3671 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3676 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3678 /* for the first external buffer */
3679 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3681 /* for the rest of external buffer descriptors if any */
3682 if (ext_buf_cnt
> 1) {
3684 list_for_each_entry_safe(curr_dmabuf
, next_dmabuf
,
3685 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
, list
) {
3686 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
,
3687 ext_buf_index
, dmabuf
,
3693 /* after dma descriptor setup */
3694 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3695 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3697 /* construct base driver mbox command */
3698 pmb
= &pmboxq
->u
.mb
;
3699 pmbx
= (uint8_t *)dmabuf
->virt
;
3700 memcpy(pmb
, pmbx
, sizeof(*pmb
));
3701 pmb
->mbxOwner
= OWN_HOST
;
3702 pmboxq
->vport
= phba
->pport
;
3704 /* multi-buffer handling context */
3705 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3706 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_rd
;
3707 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3708 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3709 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3710 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3712 /* callback for multi-buffer read mailbox command */
3713 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_read_mbox_ext_cmpl
;
3715 /* context fields to callback function */
3716 pmboxq
->context1
= dd_data
;
3717 dd_data
->type
= TYPE_MBOX
;
3718 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3719 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
3720 dd_data
->context_un
.mbox
.set_job
= job
;
3721 job
->dd_data
= dd_data
;
3724 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3727 * Non-embedded mailbox subcommand data gets byte swapped here because
3728 * the lower level driver code only does the first 64 mailbox words.
3730 if ((!bsg_bf_get(lpfc_mbox_hdr_emb
,
3731 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) &&
3732 (nemb_tp
== nemb_mse
))
3733 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3734 &pmbx
[sizeof(MAILBOX_t
)],
3735 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3738 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3739 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3740 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3741 "2947 Issued SLI_CONFIG ext-buffer "
3742 "maibox command, rc:x%x\n", rc
);
3743 return SLI_CONFIG_HANDLED
;
3745 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3746 "2948 Failed to issue SLI_CONFIG ext-buffer "
3747 "maibox command, rc:x%x\n", rc
);
3752 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3753 lpfc_bsg_dma_page_list_free(phba
,
3754 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3756 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
3761 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
3762 * @phba: Pointer to HBA context object.
3763 * @mb: Pointer to a BSG mailbox object.
3764 * @dmabuff: Pointer to a DMA buffer descriptor.
3766 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
3767 * non-embedded external bufffers.
3770 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3771 enum nemb_type nemb_tp
,
3772 struct lpfc_dmabuf
*dmabuf
)
3774 struct dfc_mbox_req
*mbox_req
;
3775 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3776 uint32_t ext_buf_cnt
;
3777 struct bsg_job_data
*dd_data
= NULL
;
3778 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3781 int rc
= SLI_CONFIG_NOT_HANDLED
, i
;
3784 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3786 /* pointer to the start of mailbox command */
3787 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3789 if (nemb_tp
== nemb_mse
) {
3790 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3791 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3792 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3793 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3794 "2953 Failed SLI_CONFIG(mse) wr, "
3795 "ext_buf_cnt(%d) out of range(%d)\n",
3797 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3800 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3801 "2949 Handled SLI_CONFIG(mse) wr, "
3802 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3804 /* sanity check on interface type for support */
3805 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3806 LPFC_SLI_INTF_IF_TYPE_2
)
3808 /* nemb_tp == nemb_hbd */
3809 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3810 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3811 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3812 "2954 Failed SLI_CONFIG(hbd) wr, "
3813 "ext_buf_cnt(%d) out of range(%d)\n",
3815 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3818 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3819 "2950 Handled SLI_CONFIG(hbd) wr, "
3820 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3823 /* before dma buffer descriptor setup */
3824 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3825 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3827 if (ext_buf_cnt
== 0)
3830 /* for the first external buffer */
3831 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3833 /* after dma descriptor setup */
3834 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3835 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3837 /* log for looking forward */
3838 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3839 if (nemb_tp
== nemb_mse
)
3840 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3841 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
3842 i
, sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3845 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3846 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
3847 i
, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3848 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3852 /* multi-buffer handling context */
3853 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3854 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_wr
;
3855 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3856 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3857 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3858 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3860 if (ext_buf_cnt
== 1) {
3861 /* bsg tracking structure */
3862 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3868 /* mailbox command structure for base driver */
3869 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3874 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3875 pmb
= &pmboxq
->u
.mb
;
3876 mbx
= (uint8_t *)dmabuf
->virt
;
3877 memcpy(pmb
, mbx
, sizeof(*pmb
));
3878 pmb
->mbxOwner
= OWN_HOST
;
3879 pmboxq
->vport
= phba
->pport
;
3881 /* callback for multi-buffer read mailbox command */
3882 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
3884 /* context fields to callback function */
3885 pmboxq
->context1
= dd_data
;
3886 dd_data
->type
= TYPE_MBOX
;
3887 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3888 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)mbx
;
3889 dd_data
->context_un
.mbox
.set_job
= job
;
3890 job
->dd_data
= dd_data
;
3893 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3895 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3896 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3897 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3898 "2955 Issued SLI_CONFIG ext-buffer "
3899 "maibox command, rc:x%x\n", rc
);
3900 return SLI_CONFIG_HANDLED
;
3902 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3903 "2956 Failed to issue SLI_CONFIG ext-buffer "
3904 "maibox command, rc:x%x\n", rc
);
3909 /* wait for additoinal external buffers */
3910 job
->reply
->result
= 0;
3912 return SLI_CONFIG_HANDLED
;
3916 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3923 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
3924 * @phba: Pointer to HBA context object.
3925 * @mb: Pointer to a BSG mailbox object.
3926 * @dmabuff: Pointer to a DMA buffer descriptor.
3928 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
3929 * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
3930 * with embedded sussystem 0x1 and opcodes with external HBDs.
3933 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3934 struct lpfc_dmabuf
*dmabuf
)
3936 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3939 int rc
= SLI_CONFIG_NOT_HANDLED
;
3941 /* state change on new multi-buffer pass-through mailbox command */
3942 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_HOST
;
3944 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3946 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3947 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3948 subsys
= bsg_bf_get(lpfc_emb0_subcmnd_subsys
,
3949 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3950 opcode
= bsg_bf_get(lpfc_emb0_subcmnd_opcode
,
3951 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3952 if (subsys
== SLI_CONFIG_SUBSYS_FCOE
) {
3954 case FCOE_OPCODE_READ_FCF
:
3955 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3956 "2957 Handled SLI_CONFIG "
3957 "subsys_fcoe, opcode:x%x\n",
3959 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3962 case FCOE_OPCODE_ADD_FCF
:
3963 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3964 "2958 Handled SLI_CONFIG "
3965 "subsys_fcoe, opcode:x%x\n",
3967 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
3971 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3972 "2959 Reject SLI_CONFIG "
3973 "subsys_fcoe, opcode:x%x\n",
3978 } else if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
3980 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES
:
3981 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3982 "3106 Handled SLI_CONFIG "
3983 "subsys_comn, opcode:x%x\n",
3985 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3989 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3990 "3107 Reject SLI_CONFIG "
3991 "subsys_comn, opcode:x%x\n",
3997 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3998 "2977 Reject SLI_CONFIG "
3999 "subsys:x%d, opcode:x%x\n",
4004 subsys
= bsg_bf_get(lpfc_emb1_subcmnd_subsys
,
4005 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4006 opcode
= bsg_bf_get(lpfc_emb1_subcmnd_opcode
,
4007 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4008 if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
4010 case COMN_OPCODE_READ_OBJECT
:
4011 case COMN_OPCODE_READ_OBJECT_LIST
:
4012 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4013 "2960 Handled SLI_CONFIG "
4014 "subsys_comn, opcode:x%x\n",
4016 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4019 case COMN_OPCODE_WRITE_OBJECT
:
4020 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4021 "2961 Handled SLI_CONFIG "
4022 "subsys_comn, opcode:x%x\n",
4024 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
4028 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4029 "2962 Not handled SLI_CONFIG "
4030 "subsys_comn, opcode:x%x\n",
4032 rc
= SLI_CONFIG_NOT_HANDLED
;
4036 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4037 "2978 Not handled SLI_CONFIG "
4038 "subsys:x%d, opcode:x%x\n",
4040 rc
= SLI_CONFIG_NOT_HANDLED
;
4044 /* state reset on not handled new multi-buffer mailbox command */
4045 if (rc
!= SLI_CONFIG_HANDLED
)
4046 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
4052 * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
4053 * @phba: Pointer to HBA context object.
4055 * This routine is for requesting to abort a pass-through mailbox command with
4056 * multiple external buffers due to error condition.
4059 lpfc_bsg_mbox_ext_abort(struct lpfc_hba
*phba
)
4061 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
4062 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
4064 lpfc_bsg_mbox_ext_session_reset(phba
);
4069 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
4070 * @phba: Pointer to HBA context object.
4071 * @dmabuf: Pointer to a DMA buffer descriptor.
4073 * This routine extracts the next mailbox read external buffer back to
4074 * user space through BSG.
4077 lpfc_bsg_read_ebuf_get(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
4079 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4080 struct lpfc_dmabuf
*dmabuf
;
4085 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4086 phba
->mbox_ext_buf_ctx
.seqNum
++;
4088 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4089 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4091 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4092 size
= bsg_bf_get(lpfc_mbox_sli_config_mse_len
,
4093 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[index
]);
4094 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4095 "2963 SLI_CONFIG (mse) ext-buffer rd get "
4096 "buffer[%d], size:%d\n", index
, size
);
4098 size
= bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
4099 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd
[index
]);
4100 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4101 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
4102 "buffer[%d], size:%d\n", index
, size
);
4104 if (list_empty(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
))
4106 dmabuf
= list_first_entry(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
,
4107 struct lpfc_dmabuf
, list
);
4108 list_del_init(&dmabuf
->list
);
4110 /* after dma buffer descriptor setup */
4111 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4112 mbox_rd
, dma_ebuf
, sta_pos_addr
,
4115 pbuf
= (uint8_t *)dmabuf
->virt
;
4116 job
->reply
->reply_payload_rcv_len
=
4117 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4118 job
->reply_payload
.sg_cnt
,
4121 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4123 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4124 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4125 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
4126 "command session done\n");
4127 lpfc_bsg_mbox_ext_session_reset(phba
);
4130 job
->reply
->result
= 0;
4133 return SLI_CONFIG_HANDLED
;
4137 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
4138 * @phba: Pointer to HBA context object.
4139 * @dmabuf: Pointer to a DMA buffer descriptor.
4141 * This routine sets up the next mailbox read external buffer obtained
4142 * from user space through BSG.
4145 lpfc_bsg_write_ebuf_set(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4146 struct lpfc_dmabuf
*dmabuf
)
4148 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4149 struct bsg_job_data
*dd_data
= NULL
;
4150 LPFC_MBOXQ_t
*pmboxq
= NULL
;
4152 enum nemb_type nemb_tp
;
4158 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4159 phba
->mbox_ext_buf_ctx
.seqNum
++;
4160 nemb_tp
= phba
->mbox_ext_buf_ctx
.nembType
;
4162 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4163 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4165 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4171 pbuf
= (uint8_t *)dmabuf
->virt
;
4172 size
= job
->request_payload
.payload_len
;
4173 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4174 job
->request_payload
.sg_cnt
,
4177 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4178 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4179 "2966 SLI_CONFIG (mse) ext-buffer wr set "
4180 "buffer[%d], size:%d\n",
4181 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4184 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4185 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
4186 "buffer[%d], size:%d\n",
4187 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4191 /* set up external buffer descriptor and add to external buffer list */
4192 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, index
,
4193 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
,
4195 list_add_tail(&dmabuf
->list
, &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4197 /* after write dma buffer */
4198 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4199 mbox_wr
, dma_ebuf
, sta_pos_addr
,
4202 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4203 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4204 "2968 SLI_CONFIG ext-buffer wr all %d "
4205 "ebuffers received\n",
4206 phba
->mbox_ext_buf_ctx
.numBuf
);
4207 /* mailbox command structure for base driver */
4208 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4213 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4214 pbuf
= (uint8_t *)phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4215 pmb
= &pmboxq
->u
.mb
;
4216 memcpy(pmb
, pbuf
, sizeof(*pmb
));
4217 pmb
->mbxOwner
= OWN_HOST
;
4218 pmboxq
->vport
= phba
->pport
;
4220 /* callback for multi-buffer write mailbox command */
4221 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
4223 /* context fields to callback function */
4224 pmboxq
->context1
= dd_data
;
4225 dd_data
->type
= TYPE_MBOX
;
4226 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4227 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pbuf
;
4228 dd_data
->context_un
.mbox
.set_job
= job
;
4229 job
->dd_data
= dd_data
;
4232 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4234 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4235 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4236 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4237 "2969 Issued SLI_CONFIG ext-buffer "
4238 "maibox command, rc:x%x\n", rc
);
4239 return SLI_CONFIG_HANDLED
;
4241 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4242 "2970 Failed to issue SLI_CONFIG ext-buffer "
4243 "maibox command, rc:x%x\n", rc
);
4248 /* wait for additoinal external buffers */
4249 job
->reply
->result
= 0;
4251 return SLI_CONFIG_HANDLED
;
4254 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4261 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4262 * @phba: Pointer to HBA context object.
4263 * @mb: Pointer to a BSG mailbox object.
4264 * @dmabuff: Pointer to a DMA buffer descriptor.
4266 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4267 * command with multiple non-embedded external buffers.
4270 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4271 struct lpfc_dmabuf
*dmabuf
)
4275 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4276 "2971 SLI_CONFIG buffer (type:x%x)\n",
4277 phba
->mbox_ext_buf_ctx
.mboxType
);
4279 if (phba
->mbox_ext_buf_ctx
.mboxType
== mbox_rd
) {
4280 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_DONE
) {
4281 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4282 "2972 SLI_CONFIG rd buffer state "
4284 phba
->mbox_ext_buf_ctx
.state
);
4285 lpfc_bsg_mbox_ext_abort(phba
);
4288 rc
= lpfc_bsg_read_ebuf_get(phba
, job
);
4289 if (rc
== SLI_CONFIG_HANDLED
)
4290 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4291 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4292 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_HOST
) {
4293 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4294 "2973 SLI_CONFIG wr buffer state "
4296 phba
->mbox_ext_buf_ctx
.state
);
4297 lpfc_bsg_mbox_ext_abort(phba
);
4300 rc
= lpfc_bsg_write_ebuf_set(phba
, job
, dmabuf
);
4306 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4307 * @phba: Pointer to HBA context object.
4308 * @mb: Pointer to a BSG mailbox object.
4309 * @dmabuff: Pointer to a DMA buffer descriptor.
4311 * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
4312 * (0x9B) mailbox commands and external buffers.
4315 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4316 struct lpfc_dmabuf
*dmabuf
)
4318 struct dfc_mbox_req
*mbox_req
;
4319 int rc
= SLI_CONFIG_NOT_HANDLED
;
4322 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4324 /* mbox command with/without single external buffer */
4325 if (mbox_req
->extMboxTag
== 0 && mbox_req
->extSeqNum
== 0)
4328 /* mbox command and first external buffer */
4329 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
) {
4330 if (mbox_req
->extSeqNum
== 1) {
4331 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4332 "2974 SLI_CONFIG mailbox: tag:%d, "
4333 "seq:%d\n", mbox_req
->extMboxTag
,
4334 mbox_req
->extSeqNum
);
4335 rc
= lpfc_bsg_handle_sli_cfg_mbox(phba
, job
, dmabuf
);
4338 goto sli_cfg_ext_error
;
4342 * handle additional external buffers
4345 /* check broken pipe conditions */
4346 if (mbox_req
->extMboxTag
!= phba
->mbox_ext_buf_ctx
.mbxTag
)
4347 goto sli_cfg_ext_error
;
4348 if (mbox_req
->extSeqNum
> phba
->mbox_ext_buf_ctx
.numBuf
)
4349 goto sli_cfg_ext_error
;
4350 if (mbox_req
->extSeqNum
!= phba
->mbox_ext_buf_ctx
.seqNum
+ 1)
4351 goto sli_cfg_ext_error
;
4353 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4354 "2975 SLI_CONFIG mailbox external buffer: "
4355 "extSta:x%x, tag:%d, seq:%d\n",
4356 phba
->mbox_ext_buf_ctx
.state
, mbox_req
->extMboxTag
,
4357 mbox_req
->extSeqNum
);
4358 rc
= lpfc_bsg_handle_sli_cfg_ebuf(phba
, job
, dmabuf
);
4362 /* all other cases, broken pipe */
4363 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4364 "2976 SLI_CONFIG mailbox broken pipe: "
4365 "ctxSta:x%x, ctxNumBuf:%d "
4366 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4367 phba
->mbox_ext_buf_ctx
.state
,
4368 phba
->mbox_ext_buf_ctx
.numBuf
,
4369 phba
->mbox_ext_buf_ctx
.mbxTag
,
4370 phba
->mbox_ext_buf_ctx
.seqNum
,
4371 mbox_req
->extMboxTag
, mbox_req
->extSeqNum
);
4373 lpfc_bsg_mbox_ext_session_reset(phba
);
4379 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4380 * @phba: Pointer to HBA context object.
4381 * @mb: Pointer to a mailbox object.
4382 * @vport: Pointer to a vport object.
4384 * Allocate a tracking object, mailbox command memory, get a mailbox
4385 * from the mailbox pool, copy the caller mailbox command.
4387 * If offline and the sli is active we need to poll for the command (port is
4388 * being reset) and com-plete the job, otherwise issue the mailbox command and
4389 * let our completion handler finish the command.
4392 lpfc_bsg_issue_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4393 struct lpfc_vport
*vport
)
4395 LPFC_MBOXQ_t
*pmboxq
= NULL
; /* internal mailbox queue */
4396 MAILBOX_t
*pmb
; /* shortcut to the pmboxq mailbox */
4397 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4398 uint8_t *pmbx
= NULL
;
4399 struct bsg_job_data
*dd_data
= NULL
; /* bsg data tracking structure */
4400 struct lpfc_dmabuf
*dmabuf
= NULL
;
4401 struct dfc_mbox_req
*mbox_req
;
4402 struct READ_EVENT_LOG_VAR
*rdEventLog
;
4403 uint32_t transmit_length
, receive_length
, mode
;
4404 struct lpfc_mbx_sli4_config
*sli4_config
;
4405 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
4406 struct mbox_header
*header
;
4407 struct ulp_bde64
*bde
;
4408 uint8_t *ext
= NULL
;
4414 /* in case no data is transferred */
4415 job
->reply
->reply_payload_rcv_len
= 0;
4417 /* sanity check to protect driver */
4418 if (job
->reply_payload
.payload_len
> BSG_MBOX_SIZE
||
4419 job
->request_payload
.payload_len
> BSG_MBOX_SIZE
) {
4425 * Don't allow mailbox commands to be sent when blocked or when in
4426 * the middle of discovery
4428 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4434 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4436 /* check if requested extended data lengths are valid */
4437 if ((mbox_req
->inExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t)) ||
4438 (mbox_req
->outExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t))) {
4443 dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
4444 if (!dmabuf
|| !dmabuf
->virt
) {
4449 /* Get the mailbox command or external buffer from BSG */
4450 pmbx
= (uint8_t *)dmabuf
->virt
;
4451 size
= job
->request_payload
.payload_len
;
4452 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4453 job
->request_payload
.sg_cnt
, pmbx
, size
);
4455 /* Handle possible SLI_CONFIG with non-embedded payloads */
4456 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4457 rc
= lpfc_bsg_handle_sli_cfg_ext(phba
, job
, dmabuf
);
4458 if (rc
== SLI_CONFIG_HANDLED
)
4462 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4465 rc
= lpfc_bsg_check_cmd_access(phba
, (MAILBOX_t
*)pmbx
, vport
);
4467 goto job_done
; /* must be negative */
4469 /* allocate our bsg tracking structure */
4470 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4472 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4473 "2727 Failed allocation of dd_data\n");
4478 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4483 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4485 pmb
= &pmboxq
->u
.mb
;
4486 memcpy(pmb
, pmbx
, sizeof(*pmb
));
4487 pmb
->mbxOwner
= OWN_HOST
;
4488 pmboxq
->vport
= vport
;
4490 /* If HBA encountered an error attention, allow only DUMP
4491 * or RESTART mailbox commands until the HBA is restarted.
4493 if (phba
->pport
->stopped
&&
4494 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4495 pmb
->mbxCommand
!= MBX_RESTART
&&
4496 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4497 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4498 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4499 "2797 mbox: Issued mailbox cmd "
4500 "0x%x while in stopped state.\n",
4503 /* extended mailbox commands will need an extended buffer */
4504 if (mbox_req
->inExtWLen
|| mbox_req
->outExtWLen
) {
4506 ext
= from
+ sizeof(MAILBOX_t
);
4507 pmboxq
->context2
= ext
;
4508 pmboxq
->in_ext_byte_len
=
4509 mbox_req
->inExtWLen
* sizeof(uint32_t);
4510 pmboxq
->out_ext_byte_len
=
4511 mbox_req
->outExtWLen
* sizeof(uint32_t);
4512 pmboxq
->mbox_offset_word
= mbox_req
->mbOffset
;
4515 /* biu diag will need a kernel buffer to transfer the data
4516 * allocate our own buffer and setup the mailbox command to
4519 if (pmb
->mbxCommand
== MBX_RUN_BIU_DIAG64
) {
4520 transmit_length
= pmb
->un
.varWords
[1];
4521 receive_length
= pmb
->un
.varWords
[4];
4522 /* transmit length cannot be greater than receive length or
4523 * mailbox extension size
4525 if ((transmit_length
> receive_length
) ||
4526 (transmit_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4530 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrHigh
=
4531 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4532 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrLow
=
4533 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4535 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrHigh
=
4536 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4537 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4538 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrLow
=
4539 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4540 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4541 } else if (pmb
->mbxCommand
== MBX_READ_EVENT_LOG
) {
4542 rdEventLog
= &pmb
->un
.varRdEventLog
;
4543 receive_length
= rdEventLog
->rcv_bde64
.tus
.f
.bdeSize
;
4544 mode
= bf_get(lpfc_event_log
, rdEventLog
);
4546 /* receive length cannot be greater than mailbox
4549 if (receive_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4554 /* mode zero uses a bde like biu diags command */
4556 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4557 + sizeof(MAILBOX_t
));
4558 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4559 + sizeof(MAILBOX_t
));
4561 } else if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4562 /* Let type 4 (well known data) through because the data is
4563 * returned in varwords[4-8]
4564 * otherwise check the recieve length and fetch the buffer addr
4566 if ((pmb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
4567 (pmb
->un
.varDmp
.type
!= DMP_WELL_KNOWN
)) {
4568 /* rebuild the command for sli4 using our own buffers
4569 * like we do for biu diags
4571 receive_length
= pmb
->un
.varWords
[2];
4572 /* receive length cannot be greater than mailbox
4575 if (receive_length
== 0) {
4579 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4580 + sizeof(MAILBOX_t
));
4581 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4582 + sizeof(MAILBOX_t
));
4583 } else if ((pmb
->mbxCommand
== MBX_UPDATE_CFG
) &&
4584 pmb
->un
.varUpdateCfg
.co
) {
4585 bde
= (struct ulp_bde64
*)&pmb
->un
.varWords
[4];
4587 /* bde size cannot be greater than mailbox ext size */
4588 if (bde
->tus
.f
.bdeSize
>
4589 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4593 bde
->addrHigh
= putPaddrHigh(dmabuf
->phys
4594 + sizeof(MAILBOX_t
));
4595 bde
->addrLow
= putPaddrLow(dmabuf
->phys
4596 + sizeof(MAILBOX_t
));
4597 } else if (pmb
->mbxCommand
== MBX_SLI4_CONFIG
) {
4598 /* Handling non-embedded SLI_CONFIG mailbox command */
4599 sli4_config
= &pmboxq
->u
.mqe
.un
.sli4_config
;
4600 if (!bf_get(lpfc_mbox_hdr_emb
,
4601 &sli4_config
->header
.cfg_mhdr
)) {
4602 /* rebuild the command for sli4 using our
4603 * own buffers like we do for biu diags
4605 header
= (struct mbox_header
*)
4606 &pmb
->un
.varWords
[0];
4607 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
4608 &pmb
->un
.varWords
[0];
4609 receive_length
= nembed_sge
->sge
[0].length
;
4611 /* receive length cannot be greater than
4612 * mailbox extension size
4614 if ((receive_length
== 0) ||
4616 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4621 nembed_sge
->sge
[0].pa_hi
=
4622 putPaddrHigh(dmabuf
->phys
4623 + sizeof(MAILBOX_t
));
4624 nembed_sge
->sge
[0].pa_lo
=
4625 putPaddrLow(dmabuf
->phys
4626 + sizeof(MAILBOX_t
));
4631 dd_data
->context_un
.mbox
.dmabuffers
= dmabuf
;
4633 /* setup wake call as IOCB callback */
4634 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_mbox_cmpl
;
4636 /* setup context field to pass wait_queue pointer to wake function */
4637 pmboxq
->context1
= dd_data
;
4638 dd_data
->type
= TYPE_MBOX
;
4639 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4640 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
4641 dd_data
->context_un
.mbox
.set_job
= job
;
4642 dd_data
->context_un
.mbox
.ext
= ext
;
4643 dd_data
->context_un
.mbox
.mbOffset
= mbox_req
->mbOffset
;
4644 dd_data
->context_un
.mbox
.inExtWLen
= mbox_req
->inExtWLen
;
4645 dd_data
->context_un
.mbox
.outExtWLen
= mbox_req
->outExtWLen
;
4646 job
->dd_data
= dd_data
;
4648 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4649 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4650 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4651 if (rc
!= MBX_SUCCESS
) {
4652 rc
= (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4656 /* job finished, copy the data */
4657 memcpy(pmbx
, pmb
, sizeof(*pmb
));
4658 job
->reply
->reply_payload_rcv_len
=
4659 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4660 job
->reply_payload
.sg_cnt
,
4662 /* not waiting mbox already done */
4667 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4668 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
))
4669 return 1; /* job started */
4672 /* common exit for error or job completed inline */
4674 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4675 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4683 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
4684 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
4687 lpfc_bsg_mbox_cmd(struct fc_bsg_job
*job
)
4689 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4690 struct lpfc_hba
*phba
= vport
->phba
;
4691 struct dfc_mbox_req
*mbox_req
;
4694 /* mix-and-match backward compatibility */
4695 job
->reply
->reply_payload_rcv_len
= 0;
4696 if (job
->request_len
<
4697 sizeof(struct fc_bsg_request
) + sizeof(struct dfc_mbox_req
)) {
4698 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4699 "2737 Mix-and-match backward compability "
4700 "between MBOX_REQ old size:%d and "
4701 "new request size:%d\n",
4702 (int)(job
->request_len
-
4703 sizeof(struct fc_bsg_request
)),
4704 (int)sizeof(struct dfc_mbox_req
));
4705 mbox_req
= (struct dfc_mbox_req
*)
4706 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4707 mbox_req
->extMboxTag
= 0;
4708 mbox_req
->extSeqNum
= 0;
4711 rc
= lpfc_bsg_issue_mbox(phba
, job
, vport
);
4715 job
->reply
->result
= 0;
4716 job
->dd_data
= NULL
;
4719 /* job submitted, will complete later*/
4720 rc
= 0; /* return zero, no error */
4722 /* some error occurred */
4723 job
->reply
->result
= rc
;
4724 job
->dd_data
= NULL
;
4731 * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
4732 * @phba: Pointer to HBA context object.
4733 * @cmdiocbq: Pointer to command iocb.
4734 * @rspiocbq: Pointer to response iocb.
4736 * This function is the completion handler for iocbs issued using
4737 * lpfc_menlo_cmd function. This function is called by the
4738 * ring event handler function without any lock held. This function
4739 * can be called from both worker thread context and interrupt
4740 * context. This function also can be called from another thread which
4741 * cleans up the SLI layer objects.
4742 * This function copies the contents of the response iocb to the
4743 * response iocb memory object provided by the caller of
4744 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4745 * sleeps for the iocb completion.
4748 lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba
*phba
,
4749 struct lpfc_iocbq
*cmdiocbq
,
4750 struct lpfc_iocbq
*rspiocbq
)
4752 struct bsg_job_data
*dd_data
;
4753 struct fc_bsg_job
*job
;
4755 struct lpfc_dmabuf
*bmp
;
4756 struct lpfc_bsg_menlo
*menlo
;
4757 unsigned long flags
;
4758 struct menlo_response
*menlo_resp
;
4761 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
4762 dd_data
= cmdiocbq
->context1
;
4764 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4768 menlo
= &dd_data
->context_un
.menlo
;
4769 job
= menlo
->set_job
;
4770 job
->dd_data
= NULL
; /* so timeout handler does not reply */
4772 spin_lock(&phba
->hbalock
);
4773 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
4774 if (cmdiocbq
->context2
&& rspiocbq
)
4775 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
4776 &rspiocbq
->iocb
, sizeof(IOCB_t
));
4777 spin_unlock(&phba
->hbalock
);
4780 rspiocbq
= menlo
->rspiocbq
;
4781 rsp
= &rspiocbq
->iocb
;
4783 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4784 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4785 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4786 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4788 /* always return the xri, this would be used in the case
4789 * of a menlo download to allow the data to be sent as a continuation
4792 menlo_resp
= (struct menlo_response
*)
4793 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4794 menlo_resp
->xri
= rsp
->ulpContext
;
4795 if (rsp
->ulpStatus
) {
4796 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
4797 switch (rsp
->un
.ulpWord
[4] & 0xff) {
4798 case IOERR_SEQUENCE_TIMEOUT
:
4801 case IOERR_INVALID_RPI
:
4811 job
->reply
->reply_payload_rcv_len
=
4812 rsp
->un
.genreq64
.bdl
.bdeSize
;
4814 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
4815 lpfc_sli_release_iocbq(phba
, rspiocbq
);
4816 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
4819 /* make error code available to userspace */
4820 job
->reply
->result
= rc
;
4821 /* complete the job back to userspace */
4823 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4828 * lpfc_menlo_cmd - send an ioctl for menlo hardware
4829 * @job: fc_bsg_job to handle
4831 * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
4832 * all the command completions will return the xri for the command.
4833 * For menlo data requests a gen request 64 CX is used to continue the exchange
4834 * supplied in the menlo request header xri field.
4837 lpfc_menlo_cmd(struct fc_bsg_job
*job
)
4839 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4840 struct lpfc_hba
*phba
= vport
->phba
;
4841 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
4844 struct menlo_command
*menlo_cmd
;
4845 struct menlo_response
*menlo_resp
;
4846 struct lpfc_dmabuf
*bmp
= NULL
;
4849 struct scatterlist
*sgel
= NULL
;
4852 struct bsg_job_data
*dd_data
;
4853 struct ulp_bde64
*bpl
= NULL
;
4855 /* in case no data is returned return just the return code */
4856 job
->reply
->reply_payload_rcv_len
= 0;
4858 if (job
->request_len
<
4859 sizeof(struct fc_bsg_request
) +
4860 sizeof(struct menlo_command
)) {
4861 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4862 "2784 Received MENLO_CMD request below "
4868 if (job
->reply_len
<
4869 sizeof(struct fc_bsg_request
) + sizeof(struct menlo_response
)) {
4870 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4871 "2785 Received MENLO_CMD reply below "
4877 if (!(phba
->menlo_flag
& HBA_MENLO_SUPPORT
)) {
4878 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4879 "2786 Adapter does not support menlo "
4885 menlo_cmd
= (struct menlo_command
*)
4886 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4888 menlo_resp
= (struct menlo_response
*)
4889 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4891 /* allocate our bsg tracking structure */
4892 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4894 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4895 "2787 Failed allocation of dd_data\n");
4900 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4906 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
4912 rspiocbq
= lpfc_sli_get_iocbq(phba
);
4918 rsp
= &rspiocbq
->iocb
;
4920 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
4926 INIT_LIST_HEAD(&bmp
->list
);
4927 bpl
= (struct ulp_bde64
*) bmp
->virt
;
4928 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4929 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4930 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
4931 busaddr
= sg_dma_address(sgel
);
4932 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
4933 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4934 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4935 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4936 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4940 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4941 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4942 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
4943 busaddr
= sg_dma_address(sgel
);
4944 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
4945 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4946 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4947 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4948 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4952 cmd
= &cmdiocbq
->iocb
;
4953 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
4954 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
4955 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
4956 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
4957 cmd
->un
.genreq64
.bdl
.bdeSize
=
4958 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
4959 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
4960 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
4961 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CMD
;
4962 cmd
->un
.genreq64
.w5
.hcsw
.Type
= MENLO_TRANSPORT_TYPE
; /* 0xfe */
4963 cmd
->ulpBdeCount
= 1;
4964 cmd
->ulpClass
= CLASS3
;
4965 cmd
->ulpOwner
= OWN_CHIP
;
4966 cmd
->ulpLe
= 1; /* Limited Edition */
4967 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
4968 cmdiocbq
->vport
= phba
->pport
;
4969 /* We want the firmware to timeout before we do */
4970 cmd
->ulpTimeout
= MENLO_TIMEOUT
- 5;
4971 cmdiocbq
->context3
= bmp
;
4972 cmdiocbq
->context2
= rspiocbq
;
4973 cmdiocbq
->iocb_cmpl
= lpfc_bsg_menlo_cmd_cmp
;
4974 cmdiocbq
->context1
= dd_data
;
4975 cmdiocbq
->context2
= rspiocbq
;
4976 if (menlo_cmd
->cmd
== LPFC_BSG_VENDOR_MENLO_CMD
) {
4977 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
4978 cmd
->ulpPU
= MENLO_PU
; /* 3 */
4979 cmd
->un
.ulpWord
[4] = MENLO_DID
; /* 0x0000FC0E */
4980 cmd
->ulpContext
= MENLO_CONTEXT
; /* 0 */
4982 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CX
;
4984 cmd
->un
.ulpWord
[4] = 0;
4985 cmd
->ulpContext
= menlo_cmd
->xri
;
4988 dd_data
->type
= TYPE_MENLO
;
4989 dd_data
->context_un
.menlo
.cmdiocbq
= cmdiocbq
;
4990 dd_data
->context_un
.menlo
.rspiocbq
= rspiocbq
;
4991 dd_data
->context_un
.menlo
.set_job
= job
;
4992 dd_data
->context_un
.menlo
.bmp
= bmp
;
4994 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
4996 if (rc
== IOCB_SUCCESS
)
4997 return 0; /* done for now */
4999 /* iocb failed so cleanup */
5000 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
5001 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
5002 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
5003 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
5005 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
5008 lpfc_sli_release_iocbq(phba
, rspiocbq
);
5010 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
5016 /* make error code available to userspace */
5017 job
->reply
->result
= rc
;
5018 job
->dd_data
= NULL
;
5023 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
5024 * @job: fc_bsg_job to handle
5027 lpfc_bsg_hst_vendor(struct fc_bsg_job
*job
)
5029 int command
= job
->request
->rqst_data
.h_vendor
.vendor_cmd
[0];
5033 case LPFC_BSG_VENDOR_SET_CT_EVENT
:
5034 rc
= lpfc_bsg_hba_set_event(job
);
5036 case LPFC_BSG_VENDOR_GET_CT_EVENT
:
5037 rc
= lpfc_bsg_hba_get_event(job
);
5039 case LPFC_BSG_VENDOR_SEND_MGMT_RESP
:
5040 rc
= lpfc_bsg_send_mgmt_rsp(job
);
5042 case LPFC_BSG_VENDOR_DIAG_MODE
:
5043 rc
= lpfc_bsg_diag_loopback_mode(job
);
5045 case LPFC_BSG_VENDOR_DIAG_MODE_END
:
5046 rc
= lpfc_sli4_bsg_diag_mode_end(job
);
5048 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK
:
5049 rc
= lpfc_bsg_diag_loopback_run(job
);
5051 case LPFC_BSG_VENDOR_LINK_DIAG_TEST
:
5052 rc
= lpfc_sli4_bsg_link_diag_test(job
);
5054 case LPFC_BSG_VENDOR_GET_MGMT_REV
:
5055 rc
= lpfc_bsg_get_dfc_rev(job
);
5057 case LPFC_BSG_VENDOR_MBOX
:
5058 rc
= lpfc_bsg_mbox_cmd(job
);
5060 case LPFC_BSG_VENDOR_MENLO_CMD
:
5061 case LPFC_BSG_VENDOR_MENLO_DATA
:
5062 rc
= lpfc_menlo_cmd(job
);
5066 job
->reply
->reply_payload_rcv_len
= 0;
5067 /* make error code available to userspace */
5068 job
->reply
->result
= rc
;
5076 * lpfc_bsg_request - handle a bsg request from the FC transport
5077 * @job: fc_bsg_job to handle
5080 lpfc_bsg_request(struct fc_bsg_job
*job
)
5085 msgcode
= job
->request
->msgcode
;
5087 case FC_BSG_HST_VENDOR
:
5088 rc
= lpfc_bsg_hst_vendor(job
);
5090 case FC_BSG_RPT_ELS
:
5091 rc
= lpfc_bsg_rport_els(job
);
5094 rc
= lpfc_bsg_send_mgmt_cmd(job
);
5098 job
->reply
->reply_payload_rcv_len
= 0;
5099 /* make error code available to userspace */
5100 job
->reply
->result
= rc
;
5108 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
5109 * @job: fc_bsg_job that has timed out
5111 * This function just aborts the job's IOCB. The aborted IOCB will return to
5112 * the waiting function which will handle passing the error back to userspace
5115 lpfc_bsg_timeout(struct fc_bsg_job
*job
)
5117 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
5118 struct lpfc_hba
*phba
= vport
->phba
;
5119 struct lpfc_iocbq
*cmdiocb
;
5120 struct lpfc_bsg_event
*evt
;
5121 struct lpfc_bsg_iocb
*iocb
;
5122 struct lpfc_bsg_mbox
*mbox
;
5123 struct lpfc_bsg_menlo
*menlo
;
5124 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5125 struct bsg_job_data
*dd_data
;
5126 unsigned long flags
;
5128 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
5129 dd_data
= (struct bsg_job_data
*)job
->dd_data
;
5130 /* timeout and completion crossed paths if no dd_data */
5132 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5136 switch (dd_data
->type
) {
5138 iocb
= &dd_data
->context_un
.iocb
;
5139 cmdiocb
= iocb
->cmdiocbq
;
5140 /* hint to completion handler that the job timed out */
5141 job
->reply
->result
= -EAGAIN
;
5142 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5143 /* this will call our completion handler */
5144 spin_lock_irq(&phba
->hbalock
);
5145 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5146 spin_unlock_irq(&phba
->hbalock
);
5149 evt
= dd_data
->context_un
.evt
;
5150 /* this event has no job anymore */
5151 evt
->set_job
= NULL
;
5152 job
->dd_data
= NULL
;
5153 job
->reply
->reply_payload_rcv_len
= 0;
5154 /* Return -EAGAIN which is our way of signallying the
5157 job
->reply
->result
= -EAGAIN
;
5158 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5162 mbox
= &dd_data
->context_un
.mbox
;
5163 /* this mbox has no job anymore */
5164 mbox
->set_job
= NULL
;
5165 job
->dd_data
= NULL
;
5166 job
->reply
->reply_payload_rcv_len
= 0;
5167 job
->reply
->result
= -EAGAIN
;
5168 /* the mbox completion handler can now be run */
5169 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5171 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
5172 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
5175 menlo
= &dd_data
->context_un
.menlo
;
5176 cmdiocb
= menlo
->cmdiocbq
;
5177 /* hint to completion handler that the job timed out */
5178 job
->reply
->result
= -EAGAIN
;
5179 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5180 /* this will call our completion handler */
5181 spin_lock_irq(&phba
->hbalock
);
5182 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5183 spin_unlock_irq(&phba
->hbalock
);
5186 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5190 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
5191 * otherwise an error message will be displayed on the console
5192 * so always return success (zero)