1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009-2012 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
->context_un
.ndlp
= ndlp
;
603 cmdiocbq
->context2
= rspiocbq
;
604 dd_data
->type
= TYPE_IOCB
;
605 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
606 dd_data
->context_un
.iocb
.rspiocbq
= rspiocbq
;
607 dd_data
->context_un
.iocb
.set_job
= job
;
608 dd_data
->context_un
.iocb
.bmp
= NULL
;
609 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
611 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
612 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
616 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
617 writel(creg_val
, phba
->HCregaddr
);
618 readl(phba
->HCregaddr
); /* flush */
620 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
622 if (rc
== IOCB_SUCCESS
)
623 return 0; /* done for now */
624 else if (rc
== IOCB_BUSY
)
630 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
631 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
632 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
633 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
635 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
637 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
640 lpfc_sli_release_iocbq(phba
, rspiocbq
);
646 /* make error code available to userspace */
647 job
->reply
->result
= rc
;
653 * lpfc_bsg_event_free - frees an allocated event structure
654 * @kref: Pointer to a kref.
656 * Called from kref_put. Back cast the kref into an event structure address.
657 * Free any events to get, delete associated nodes, free any events to see,
658 * free any data then free the event itself.
661 lpfc_bsg_event_free(struct kref
*kref
)
663 struct lpfc_bsg_event
*evt
= container_of(kref
, struct lpfc_bsg_event
,
665 struct event_data
*ed
;
667 list_del(&evt
->node
);
669 while (!list_empty(&evt
->events_to_get
)) {
670 ed
= list_entry(evt
->events_to_get
.next
, typeof(*ed
), node
);
676 while (!list_empty(&evt
->events_to_see
)) {
677 ed
= list_entry(evt
->events_to_see
.next
, typeof(*ed
), node
);
687 * lpfc_bsg_event_ref - increments the kref for an event
688 * @evt: Pointer to an event structure.
691 lpfc_bsg_event_ref(struct lpfc_bsg_event
*evt
)
693 kref_get(&evt
->kref
);
697 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
698 * @evt: Pointer to an event structure.
701 lpfc_bsg_event_unref(struct lpfc_bsg_event
*evt
)
703 kref_put(&evt
->kref
, lpfc_bsg_event_free
);
707 * lpfc_bsg_event_new - allocate and initialize a event structure
708 * @ev_mask: Mask of events.
709 * @ev_reg_id: Event reg id.
710 * @ev_req_id: Event request id.
712 static struct lpfc_bsg_event
*
713 lpfc_bsg_event_new(uint32_t ev_mask
, int ev_reg_id
, uint32_t ev_req_id
)
715 struct lpfc_bsg_event
*evt
= kzalloc(sizeof(*evt
), GFP_KERNEL
);
720 INIT_LIST_HEAD(&evt
->events_to_get
);
721 INIT_LIST_HEAD(&evt
->events_to_see
);
722 evt
->type_mask
= ev_mask
;
723 evt
->req_id
= ev_req_id
;
724 evt
->reg_id
= ev_reg_id
;
725 evt
->wait_time_stamp
= jiffies
;
726 init_waitqueue_head(&evt
->wq
);
727 kref_init(&evt
->kref
);
732 * diag_cmd_data_free - Frees an lpfc dma buffer extension
733 * @phba: Pointer to HBA context object.
734 * @mlist: Pointer to an lpfc dma buffer extension.
737 diag_cmd_data_free(struct lpfc_hba
*phba
, struct lpfc_dmabufext
*mlist
)
739 struct lpfc_dmabufext
*mlast
;
740 struct pci_dev
*pcidev
;
741 struct list_head head
, *curr
, *next
;
743 if ((!mlist
) || (!lpfc_is_link_up(phba
) &&
744 (phba
->link_flag
& LS_LOOPBACK_MODE
))) {
748 pcidev
= phba
->pcidev
;
749 list_add_tail(&head
, &mlist
->dma
.list
);
751 list_for_each_safe(curr
, next
, &head
) {
752 mlast
= list_entry(curr
, struct lpfc_dmabufext
, dma
.list
);
754 dma_free_coherent(&pcidev
->dev
,
764 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
769 * This function is called when an unsolicited CT command is received. It
770 * forwards the event to any processes registered to receive CT events.
773 lpfc_bsg_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
774 struct lpfc_iocbq
*piocbq
)
776 uint32_t evt_req_id
= 0;
779 struct lpfc_dmabuf
*dmabuf
= NULL
;
780 struct lpfc_bsg_event
*evt
;
781 struct event_data
*evt_dat
= NULL
;
782 struct lpfc_iocbq
*iocbq
;
784 struct list_head head
;
785 struct ulp_bde64
*bde
;
788 struct lpfc_dmabuf
*bdeBuf1
= piocbq
->context2
;
789 struct lpfc_dmabuf
*bdeBuf2
= piocbq
->context3
;
790 struct lpfc_hbq_entry
*hbqe
;
791 struct lpfc_sli_ct_request
*ct_req
;
792 struct fc_bsg_job
*job
= NULL
;
796 INIT_LIST_HEAD(&head
);
797 list_add_tail(&head
, &piocbq
->list
);
799 if (piocbq
->iocb
.ulpBdeCount
== 0 ||
800 piocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
== 0)
801 goto error_ct_unsol_exit
;
803 if (phba
->link_state
== LPFC_HBA_ERROR
||
804 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)))
805 goto error_ct_unsol_exit
;
807 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
810 dma_addr
= getPaddr(piocbq
->iocb
.un
.cont64
[0].addrHigh
,
811 piocbq
->iocb
.un
.cont64
[0].addrLow
);
812 dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
, dma_addr
);
815 goto error_ct_unsol_exit
;
816 ct_req
= (struct lpfc_sli_ct_request
*)dmabuf
->virt
;
817 evt_req_id
= ct_req
->FsType
;
818 cmd
= ct_req
->CommandResponse
.bits
.CmdRsp
;
819 len
= ct_req
->CommandResponse
.bits
.Size
;
820 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
821 lpfc_sli_ringpostbuf_put(phba
, pring
, dmabuf
);
823 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
824 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
825 if (!(evt
->type_mask
& FC_REG_CT_EVENT
) ||
826 evt
->req_id
!= evt_req_id
)
829 lpfc_bsg_event_ref(evt
);
830 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
831 evt_dat
= kzalloc(sizeof(*evt_dat
), GFP_KERNEL
);
832 if (evt_dat
== NULL
) {
833 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
834 lpfc_bsg_event_unref(evt
);
835 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
836 "2614 Memory allocation failed for "
841 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
842 /* take accumulated byte count from the last iocbq */
843 iocbq
= list_entry(head
.prev
, typeof(*iocbq
), list
);
844 evt_dat
->len
= iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
;
846 list_for_each_entry(iocbq
, &head
, list
) {
847 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++)
849 iocbq
->iocb
.un
.cont64
[i
].tus
.f
.bdeSize
;
853 evt_dat
->data
= kzalloc(evt_dat
->len
, GFP_KERNEL
);
854 if (evt_dat
->data
== NULL
) {
855 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
856 "2615 Memory allocation failed for "
857 "CT event data, size %d\n",
860 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
861 lpfc_bsg_event_unref(evt
);
862 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
863 goto error_ct_unsol_exit
;
866 list_for_each_entry(iocbq
, &head
, list
) {
868 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
869 bdeBuf1
= iocbq
->context2
;
870 bdeBuf2
= iocbq
->context3
;
872 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++) {
873 if (phba
->sli3_options
&
874 LPFC_SLI3_HBQ_ENABLED
) {
876 hbqe
= (struct lpfc_hbq_entry
*)
877 &iocbq
->iocb
.un
.ulpWord
[0];
878 size
= hbqe
->bde
.tus
.f
.bdeSize
;
881 hbqe
= (struct lpfc_hbq_entry
*)
884 size
= hbqe
->bde
.tus
.f
.bdeSize
;
887 if ((offset
+ size
) > evt_dat
->len
)
888 size
= evt_dat
->len
- offset
;
890 size
= iocbq
->iocb
.un
.cont64
[i
].
892 bde
= &iocbq
->iocb
.un
.cont64
[i
];
893 dma_addr
= getPaddr(bde
->addrHigh
,
895 dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
899 lpfc_printf_log(phba
, KERN_ERR
,
900 LOG_LIBDFC
, "2616 No dmabuf "
901 "found for iocbq 0x%p\n",
903 kfree(evt_dat
->data
);
905 spin_lock_irqsave(&phba
->ct_ev_lock
,
907 lpfc_bsg_event_unref(evt
);
908 spin_unlock_irqrestore(
909 &phba
->ct_ev_lock
, flags
);
910 goto error_ct_unsol_exit
;
912 memcpy((char *)(evt_dat
->data
) + offset
,
915 if (evt_req_id
!= SLI_CT_ELX_LOOPBACK
&&
916 !(phba
->sli3_options
&
917 LPFC_SLI3_HBQ_ENABLED
)) {
918 lpfc_sli_ringpostbuf_put(phba
, pring
,
922 case ELX_LOOPBACK_DATA
:
925 diag_cmd_data_free(phba
,
926 (struct lpfc_dmabufext
929 case ELX_LOOPBACK_XRI_SETUP
:
930 if ((phba
->sli_rev
==
932 (phba
->sli3_options
&
933 LPFC_SLI3_HBQ_ENABLED
935 lpfc_in_buf_free(phba
,
938 lpfc_post_buffer(phba
,
944 if (!(phba
->sli3_options
&
945 LPFC_SLI3_HBQ_ENABLED
))
946 lpfc_post_buffer(phba
,
955 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
956 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
957 evt_dat
->immed_dat
= phba
->ctx_idx
;
958 phba
->ctx_idx
= (phba
->ctx_idx
+ 1) % 64;
959 /* Provide warning for over-run of the ct_ctx array */
960 if (phba
->ct_ctx
[evt_dat
->immed_dat
].flags
&
962 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
963 "2717 CT context array entry "
964 "[%d] over-run: oxid:x%x, "
965 "sid:x%x\n", phba
->ctx_idx
,
967 evt_dat
->immed_dat
].oxid
,
969 evt_dat
->immed_dat
].SID
);
970 phba
->ct_ctx
[evt_dat
->immed_dat
].rxid
=
971 piocbq
->iocb
.ulpContext
;
972 phba
->ct_ctx
[evt_dat
->immed_dat
].oxid
=
973 piocbq
->iocb
.unsli3
.rcvsli3
.ox_id
;
974 phba
->ct_ctx
[evt_dat
->immed_dat
].SID
=
975 piocbq
->iocb
.un
.rcvels
.remoteID
;
976 phba
->ct_ctx
[evt_dat
->immed_dat
].flags
= UNSOL_VALID
;
978 evt_dat
->immed_dat
= piocbq
->iocb
.ulpContext
;
980 evt_dat
->type
= FC_REG_CT_EVENT
;
981 list_add(&evt_dat
->node
, &evt
->events_to_see
);
982 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
) {
983 wake_up_interruptible(&evt
->wq
);
984 lpfc_bsg_event_unref(evt
);
988 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
989 lpfc_bsg_event_unref(evt
);
994 job
->reply
->reply_payload_rcv_len
= size
;
995 /* make error code available to userspace */
996 job
->reply
->result
= 0;
998 /* complete the job back to userspace */
999 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1001 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1004 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1006 error_ct_unsol_exit
:
1007 if (!list_empty(&head
))
1009 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
1010 (evt_req_id
== SLI_CT_ELX_LOOPBACK
))
1016 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1017 * @job: SET_EVENT fc_bsg_job
1020 lpfc_bsg_hba_set_event(struct fc_bsg_job
*job
)
1022 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1023 struct lpfc_hba
*phba
= vport
->phba
;
1024 struct set_ct_event
*event_req
;
1025 struct lpfc_bsg_event
*evt
;
1027 struct bsg_job_data
*dd_data
= NULL
;
1029 unsigned long flags
;
1031 if (job
->request_len
<
1032 sizeof(struct fc_bsg_request
) + sizeof(struct set_ct_event
)) {
1033 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1034 "2612 Received SET_CT_EVENT below minimum "
1040 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1041 if (dd_data
== NULL
) {
1042 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1043 "2734 Failed allocation of dd_data\n");
1048 event_req
= (struct set_ct_event
*)
1049 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1050 ev_mask
= ((uint32_t)(unsigned long)event_req
->type_mask
&
1052 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1053 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1054 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1055 lpfc_bsg_event_ref(evt
);
1056 evt
->wait_time_stamp
= jiffies
;
1060 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1062 if (&evt
->node
== &phba
->ct_ev_waiters
) {
1063 /* no event waiting struct yet - first call */
1064 evt
= lpfc_bsg_event_new(ev_mask
, event_req
->ev_reg_id
,
1065 event_req
->ev_req_id
);
1067 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1068 "2617 Failed allocation of event "
1074 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1075 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1076 lpfc_bsg_event_ref(evt
);
1077 evt
->wait_time_stamp
= jiffies
;
1078 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1081 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1083 dd_data
->type
= TYPE_EVT
;
1084 dd_data
->context_un
.evt
= evt
;
1085 evt
->set_job
= job
; /* for unsolicited command */
1086 job
->dd_data
= dd_data
; /* for fc transport timeout callback*/
1087 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1088 return 0; /* call job done later */
1091 if (dd_data
!= NULL
)
1094 job
->dd_data
= NULL
;
1099 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1100 * @job: GET_EVENT fc_bsg_job
1103 lpfc_bsg_hba_get_event(struct fc_bsg_job
*job
)
1105 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1106 struct lpfc_hba
*phba
= vport
->phba
;
1107 struct get_ct_event
*event_req
;
1108 struct get_ct_event_reply
*event_reply
;
1109 struct lpfc_bsg_event
*evt
;
1110 struct event_data
*evt_dat
= NULL
;
1111 unsigned long flags
;
1114 if (job
->request_len
<
1115 sizeof(struct fc_bsg_request
) + sizeof(struct get_ct_event
)) {
1116 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1117 "2613 Received GET_CT_EVENT request below "
1123 event_req
= (struct get_ct_event
*)
1124 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1126 event_reply
= (struct get_ct_event_reply
*)
1127 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
1128 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1129 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1130 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1131 if (list_empty(&evt
->events_to_get
))
1133 lpfc_bsg_event_ref(evt
);
1134 evt
->wait_time_stamp
= jiffies
;
1135 evt_dat
= list_entry(evt
->events_to_get
.prev
,
1136 struct event_data
, node
);
1137 list_del(&evt_dat
->node
);
1141 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1143 /* The app may continue to ask for event data until it gets
1144 * an error indicating that there isn't anymore
1146 if (evt_dat
== NULL
) {
1147 job
->reply
->reply_payload_rcv_len
= 0;
1152 if (evt_dat
->len
> job
->request_payload
.payload_len
) {
1153 evt_dat
->len
= job
->request_payload
.payload_len
;
1154 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1155 "2618 Truncated event data at %d "
1157 job
->request_payload
.payload_len
);
1160 event_reply
->type
= evt_dat
->type
;
1161 event_reply
->immed_data
= evt_dat
->immed_dat
;
1162 if (evt_dat
->len
> 0)
1163 job
->reply
->reply_payload_rcv_len
=
1164 sg_copy_from_buffer(job
->request_payload
.sg_list
,
1165 job
->request_payload
.sg_cnt
,
1166 evt_dat
->data
, evt_dat
->len
);
1168 job
->reply
->reply_payload_rcv_len
= 0;
1171 kfree(evt_dat
->data
);
1175 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1176 lpfc_bsg_event_unref(evt
);
1177 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1178 job
->dd_data
= NULL
;
1179 job
->reply
->result
= 0;
1184 job
->dd_data
= NULL
;
1185 job
->reply
->result
= rc
;
1190 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1191 * @phba: Pointer to HBA context object.
1192 * @cmdiocbq: Pointer to command iocb.
1193 * @rspiocbq: Pointer to response iocb.
1195 * This function is the completion handler for iocbs issued using
1196 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1197 * ring event handler function without any lock held. This function
1198 * can be called from both worker thread context and interrupt
1199 * context. This function also can be called from other thread which
1200 * cleans up the SLI layer objects.
1201 * This function copy the contents of the response iocb to the
1202 * response iocb memory object provided by the caller of
1203 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1204 * sleeps for the iocb completion.
1207 lpfc_issue_ct_rsp_cmp(struct lpfc_hba
*phba
,
1208 struct lpfc_iocbq
*cmdiocbq
,
1209 struct lpfc_iocbq
*rspiocbq
)
1211 struct bsg_job_data
*dd_data
;
1212 struct fc_bsg_job
*job
;
1214 struct lpfc_dmabuf
*bmp
;
1215 struct lpfc_nodelist
*ndlp
;
1216 unsigned long flags
;
1219 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1220 dd_data
= cmdiocbq
->context2
;
1221 /* normal completion and timeout crossed paths, already done */
1223 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1227 job
= dd_data
->context_un
.iocb
.set_job
;
1228 bmp
= dd_data
->context_un
.iocb
.bmp
;
1229 rsp
= &rspiocbq
->iocb
;
1230 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
1232 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1233 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1235 if (rsp
->ulpStatus
) {
1236 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1237 switch (rsp
->un
.ulpWord
[4] & 0xff) {
1238 case IOERR_SEQUENCE_TIMEOUT
:
1241 case IOERR_INVALID_RPI
:
1251 job
->reply
->reply_payload_rcv_len
=
1252 rsp
->un
.genreq64
.bdl
.bdeSize
;
1254 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1255 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1259 /* make error code available to userspace */
1260 job
->reply
->result
= rc
;
1261 job
->dd_data
= NULL
;
1262 /* complete the job back to userspace */
1264 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1269 * lpfc_issue_ct_rsp - issue a ct response
1270 * @phba: Pointer to HBA context object.
1271 * @job: Pointer to the job object.
1272 * @tag: tag index value into the ports context exchange array.
1273 * @bmp: Pointer to a dma buffer descriptor.
1274 * @num_entry: Number of enties in the bde.
1277 lpfc_issue_ct_rsp(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
, uint32_t tag
,
1278 struct lpfc_dmabuf
*bmp
, int num_entry
)
1281 struct lpfc_iocbq
*ctiocb
= NULL
;
1283 struct lpfc_nodelist
*ndlp
= NULL
;
1284 struct bsg_job_data
*dd_data
;
1287 /* allocate our bsg tracking structure */
1288 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1290 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1291 "2736 Failed allocation of dd_data\n");
1296 /* Allocate buffer for command iocb */
1297 ctiocb
= lpfc_sli_get_iocbq(phba
);
1303 icmd
= &ctiocb
->iocb
;
1304 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
1305 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
1306 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
1307 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1308 icmd
->un
.xseq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
1309 icmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
1310 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1311 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_SOL_CTL
;
1312 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1314 /* Fill in rest of iocb */
1315 icmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
1316 icmd
->ulpBdeCount
= 1;
1318 icmd
->ulpClass
= CLASS3
;
1319 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1320 /* Do not issue unsol response if oxid not marked as valid */
1321 if (!(phba
->ct_ctx
[tag
].flags
& UNSOL_VALID
)) {
1323 goto issue_ct_rsp_exit
;
1325 icmd
->ulpContext
= phba
->ct_ctx
[tag
].rxid
;
1326 icmd
->unsli3
.rcvsli3
.ox_id
= phba
->ct_ctx
[tag
].oxid
;
1327 ndlp
= lpfc_findnode_did(phba
->pport
, phba
->ct_ctx
[tag
].SID
);
1329 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1330 "2721 ndlp null for oxid %x SID %x\n",
1332 phba
->ct_ctx
[tag
].SID
);
1334 goto issue_ct_rsp_exit
;
1337 /* Check if the ndlp is active */
1338 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1340 goto issue_ct_rsp_exit
;
1343 /* get a refernece count so the ndlp doesn't go away while
1346 if (!lpfc_nlp_get(ndlp
)) {
1348 goto issue_ct_rsp_exit
;
1351 icmd
->un
.ulpWord
[3] =
1352 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
1354 /* The exchange is done, mark the entry as invalid */
1355 phba
->ct_ctx
[tag
].flags
&= ~UNSOL_VALID
;
1357 icmd
->ulpContext
= (ushort
) tag
;
1359 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
1361 /* Xmit CT response on exchange <xid> */
1362 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1363 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1364 icmd
->ulpContext
, icmd
->ulpIoTag
, tag
, phba
->link_state
);
1366 ctiocb
->iocb_cmpl
= NULL
;
1367 ctiocb
->iocb_flag
|= LPFC_IO_LIBDFC
;
1368 ctiocb
->vport
= phba
->pport
;
1369 ctiocb
->context3
= bmp
;
1371 ctiocb
->iocb_cmpl
= lpfc_issue_ct_rsp_cmp
;
1372 ctiocb
->context2
= dd_data
;
1373 ctiocb
->context1
= ndlp
;
1374 dd_data
->type
= TYPE_IOCB
;
1375 dd_data
->context_un
.iocb
.cmdiocbq
= ctiocb
;
1376 dd_data
->context_un
.iocb
.rspiocbq
= NULL
;
1377 dd_data
->context_un
.iocb
.set_job
= job
;
1378 dd_data
->context_un
.iocb
.bmp
= bmp
;
1379 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
1381 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1382 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1384 goto issue_ct_rsp_exit
;
1386 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1387 writel(creg_val
, phba
->HCregaddr
);
1388 readl(phba
->HCregaddr
); /* flush */
1391 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
1393 if (rc
== IOCB_SUCCESS
)
1394 return 0; /* done for now */
1397 lpfc_sli_release_iocbq(phba
, ctiocb
);
1405 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1406 * @job: SEND_MGMT_RESP fc_bsg_job
1409 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job
*job
)
1411 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1412 struct lpfc_hba
*phba
= vport
->phba
;
1413 struct send_mgmt_resp
*mgmt_resp
= (struct send_mgmt_resp
*)
1414 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1415 struct ulp_bde64
*bpl
;
1416 struct lpfc_dmabuf
*bmp
= NULL
;
1417 struct scatterlist
*sgel
= NULL
;
1421 uint32_t tag
= mgmt_resp
->tag
;
1422 unsigned long reqbfrcnt
=
1423 (unsigned long)job
->request_payload
.payload_len
;
1426 /* in case no data is transferred */
1427 job
->reply
->reply_payload_rcv_len
= 0;
1429 if (!reqbfrcnt
|| (reqbfrcnt
> (80 * BUF_SZ_4K
))) {
1431 goto send_mgmt_rsp_exit
;
1434 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1437 goto send_mgmt_rsp_exit
;
1440 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
1443 goto send_mgmt_rsp_free_bmp
;
1446 INIT_LIST_HEAD(&bmp
->list
);
1447 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1448 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1449 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1450 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
1451 busaddr
= sg_dma_address(sgel
);
1452 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1453 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1454 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
1455 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
1456 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
1460 rc
= lpfc_issue_ct_rsp(phba
, job
, tag
, bmp
, request_nseg
);
1462 if (rc
== IOCB_SUCCESS
)
1463 return 0; /* done for now */
1465 /* TBD need to handle a timeout */
1466 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1467 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1469 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1471 send_mgmt_rsp_free_bmp
:
1474 /* make error code available to userspace */
1475 job
->reply
->result
= rc
;
1476 job
->dd_data
= NULL
;
1481 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1482 * @phba: Pointer to HBA context object.
1484 * This function is responsible for preparing driver for diag loopback
1488 lpfc_bsg_diag_mode_enter(struct lpfc_hba
*phba
)
1490 struct lpfc_vport
**vports
;
1491 struct Scsi_Host
*shost
;
1492 struct lpfc_sli
*psli
;
1493 struct lpfc_sli_ring
*pring
;
1500 pring
= &psli
->ring
[LPFC_FCP_RING
];
1504 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1505 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
1506 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
1509 vports
= lpfc_create_vport_work_array(phba
);
1511 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1512 shost
= lpfc_shost_from_vport(vports
[i
]);
1513 scsi_block_requests(shost
);
1515 lpfc_destroy_vport_work_array(phba
, vports
);
1517 shost
= lpfc_shost_from_vport(phba
->pport
);
1518 scsi_block_requests(shost
);
1521 while (pring
->txcmplq_cnt
) {
1522 if (i
++ > 500) /* wait up to 5 seconds */
1530 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1531 * @phba: Pointer to HBA context object.
1533 * This function is responsible for driver exit processing of setting up
1534 * diag loopback mode on device.
1537 lpfc_bsg_diag_mode_exit(struct lpfc_hba
*phba
)
1539 struct Scsi_Host
*shost
;
1540 struct lpfc_vport
**vports
;
1543 vports
= lpfc_create_vport_work_array(phba
);
1545 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1546 shost
= lpfc_shost_from_vport(vports
[i
]);
1547 scsi_unblock_requests(shost
);
1549 lpfc_destroy_vport_work_array(phba
, vports
);
1551 shost
= lpfc_shost_from_vport(phba
->pport
);
1552 scsi_unblock_requests(shost
);
1558 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1559 * @phba: Pointer to HBA context object.
1560 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1562 * This function is responsible for placing an sli3 port into diagnostic
1563 * loopback mode in order to perform a diagnostic loopback test.
1564 * All new scsi requests are blocked, a small delay is used to allow the
1565 * scsi requests to complete then the link is brought down. If the link is
1566 * is placed in loopback mode then scsi requests are again allowed
1567 * so the scsi mid-layer doesn't give up on the port.
1568 * All of this is done in-line.
1571 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1573 struct diag_mode_set
*loopback_mode
;
1574 uint32_t link_flags
;
1576 LPFC_MBOXQ_t
*pmboxq
= NULL
;
1577 int mbxstatus
= MBX_SUCCESS
;
1581 /* no data to return just the return code */
1582 job
->reply
->reply_payload_rcv_len
= 0;
1584 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1585 sizeof(struct diag_mode_set
)) {
1586 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1587 "2738 Received DIAG MODE request size:%d "
1588 "below the minimum size:%d\n",
1590 (int)(sizeof(struct fc_bsg_request
) +
1591 sizeof(struct diag_mode_set
)));
1596 rc
= lpfc_bsg_diag_mode_enter(phba
);
1600 /* bring the link to diagnostic mode */
1601 loopback_mode
= (struct diag_mode_set
*)
1602 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1603 link_flags
= loopback_mode
->type
;
1604 timeout
= loopback_mode
->timeout
* 100;
1606 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1609 goto loopback_mode_exit
;
1611 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1612 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1613 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1615 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1617 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0)) {
1618 /* wait for link down before proceeding */
1620 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1621 if (i
++ > timeout
) {
1623 goto loopback_mode_exit
;
1628 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1629 if (link_flags
== INTERNAL_LOOP_BACK
)
1630 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
1632 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
=
1633 FLAGS_TOPOLOGY_MODE_LOOP
;
1635 pmboxq
->u
.mb
.mbxCommand
= MBX_INIT_LINK
;
1636 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1638 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1641 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1644 spin_lock_irq(&phba
->hbalock
);
1645 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1646 spin_unlock_irq(&phba
->hbalock
);
1647 /* wait for the link attention interrupt */
1651 while (phba
->link_state
!= LPFC_HBA_READY
) {
1652 if (i
++ > timeout
) {
1665 lpfc_bsg_diag_mode_exit(phba
);
1668 * Let SLI layer release mboxq if mbox command completed after timeout.
1670 if (pmboxq
&& mbxstatus
!= MBX_TIMEOUT
)
1671 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1674 /* make error code available to userspace */
1675 job
->reply
->result
= rc
;
1676 /* complete the job back to userspace if no error */
1683 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1684 * @phba: Pointer to HBA context object.
1685 * @diag: Flag for set link to diag or nomral operation state.
1687 * This function is responsible for issuing a sli4 mailbox command for setting
1688 * link to either diag state or normal operation state.
1691 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba
*phba
, uint32_t diag
)
1693 LPFC_MBOXQ_t
*pmboxq
;
1694 struct lpfc_mbx_set_link_diag_state
*link_diag_state
;
1695 uint32_t req_len
, alloc_len
;
1696 int mbxstatus
= MBX_SUCCESS
, rc
;
1698 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1702 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
1703 sizeof(struct lpfc_sli4_cfg_mhdr
));
1704 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1705 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
1706 req_len
, LPFC_SLI4_MBX_EMBED
);
1707 if (alloc_len
!= req_len
) {
1709 goto link_diag_state_set_out
;
1711 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1712 "3128 Set link to diagnostic state:x%x (x%x/x%x)\n",
1713 diag
, phba
->sli4_hba
.lnk_info
.lnk_tp
,
1714 phba
->sli4_hba
.lnk_info
.lnk_no
);
1716 link_diag_state
= &pmboxq
->u
.mqe
.un
.link_diag_state
;
1717 bf_set(lpfc_mbx_set_diag_state_link_num
, &link_diag_state
->u
.req
,
1718 phba
->sli4_hba
.lnk_info
.lnk_no
);
1719 bf_set(lpfc_mbx_set_diag_state_link_type
, &link_diag_state
->u
.req
,
1720 phba
->sli4_hba
.lnk_info
.lnk_tp
);
1722 bf_set(lpfc_mbx_set_diag_state_diag
,
1723 &link_diag_state
->u
.req
, 1);
1725 bf_set(lpfc_mbx_set_diag_state_diag
,
1726 &link_diag_state
->u
.req
, 0);
1728 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1730 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0))
1735 link_diag_state_set_out
:
1736 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1737 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1743 * lpfc_sli4_bsg_set_internal_loopback - set sli4 internal loopback diagnostic
1744 * @phba: Pointer to HBA context object.
1746 * This function is responsible for issuing a sli4 mailbox command for setting
1747 * up internal loopback diagnostic.
1750 lpfc_sli4_bsg_set_internal_loopback(struct lpfc_hba
*phba
)
1752 LPFC_MBOXQ_t
*pmboxq
;
1753 uint32_t req_len
, alloc_len
;
1754 struct lpfc_mbx_set_link_diag_loopback
*link_diag_loopback
;
1755 int mbxstatus
= MBX_SUCCESS
, rc
= 0;
1757 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1760 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_loopback
) -
1761 sizeof(struct lpfc_sli4_cfg_mhdr
));
1762 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1763 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK
,
1764 req_len
, LPFC_SLI4_MBX_EMBED
);
1765 if (alloc_len
!= req_len
) {
1766 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1769 link_diag_loopback
= &pmboxq
->u
.mqe
.un
.link_diag_loopback
;
1770 bf_set(lpfc_mbx_set_diag_state_link_num
,
1771 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_no
);
1772 bf_set(lpfc_mbx_set_diag_state_link_type
,
1773 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_tp
);
1774 bf_set(lpfc_mbx_set_diag_lpbk_type
, &link_diag_loopback
->u
.req
,
1775 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL
);
1777 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1778 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
)) {
1779 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1780 "3127 Failed setup loopback mode mailbox "
1781 "command, rc:x%x, status:x%x\n", mbxstatus
,
1782 pmboxq
->u
.mb
.mbxStatus
);
1785 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1786 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1791 * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic
1792 * @phba: Pointer to HBA context object.
1794 * This function set up SLI4 FC port registrations for diagnostic run, which
1795 * includes all the rpis, vfi, and also vpi.
1798 lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba
*phba
)
1802 if (phba
->pport
->fc_flag
& FC_VFI_REGISTERED
) {
1803 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1804 "3136 Port still had vfi registered: "
1805 "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
1806 phba
->pport
->fc_myDID
, phba
->fcf
.fcfi
,
1807 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
],
1808 phba
->vpi_ids
[phba
->pport
->vpi
]);
1811 rc
= lpfc_issue_reg_vfi(phba
->pport
);
1816 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
1817 * @phba: Pointer to HBA context object.
1818 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1820 * This function is responsible for placing an sli4 port into diagnostic
1821 * loopback mode in order to perform a diagnostic loopback test.
1824 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1826 struct diag_mode_set
*loopback_mode
;
1827 uint32_t link_flags
, timeout
;
1830 /* no data to return just the return code */
1831 job
->reply
->reply_payload_rcv_len
= 0;
1833 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1834 sizeof(struct diag_mode_set
)) {
1835 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1836 "3011 Received DIAG MODE request size:%d "
1837 "below the minimum size:%d\n",
1839 (int)(sizeof(struct fc_bsg_request
) +
1840 sizeof(struct diag_mode_set
)));
1845 rc
= lpfc_bsg_diag_mode_enter(phba
);
1849 /* indicate we are in loobpack diagnostic mode */
1850 spin_lock_irq(&phba
->hbalock
);
1851 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1852 spin_unlock_irq(&phba
->hbalock
);
1854 /* reset port to start frome scratch */
1855 rc
= lpfc_selective_reset(phba
);
1859 /* bring the link to diagnostic mode */
1860 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1861 "3129 Bring link to diagnostic state.\n");
1862 loopback_mode
= (struct diag_mode_set
*)
1863 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1864 link_flags
= loopback_mode
->type
;
1865 timeout
= loopback_mode
->timeout
* 100;
1867 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
1869 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1870 "3130 Failed to bring link to diagnostic "
1871 "state, rc:x%x\n", rc
);
1872 goto loopback_mode_exit
;
1875 /* wait for link down before proceeding */
1877 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1878 if (i
++ > timeout
) {
1880 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1881 "3131 Timeout waiting for link to "
1882 "diagnostic mode, timeout:%d ms\n",
1884 goto loopback_mode_exit
;
1889 /* set up loopback mode */
1890 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1891 "3132 Set up loopback mode:x%x\n", link_flags
);
1893 if (link_flags
== INTERNAL_LOOP_BACK
)
1894 rc
= lpfc_sli4_bsg_set_internal_loopback(phba
);
1895 else if (link_flags
== EXTERNAL_LOOP_BACK
)
1896 rc
= lpfc_hba_init_link_fc_topology(phba
,
1897 FLAGS_TOPOLOGY_MODE_PT_PT
,
1901 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
1902 "3141 Loopback mode:x%x not supported\n",
1904 goto loopback_mode_exit
;
1908 /* wait for the link attention interrupt */
1911 while (phba
->link_state
< LPFC_LINK_UP
) {
1912 if (i
++ > timeout
) {
1914 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1915 "3137 Timeout waiting for link up "
1916 "in loopback mode, timeout:%d ms\n",
1924 /* port resource registration setup for loopback diagnostic */
1926 /* set up a none zero myDID for loopback test */
1927 phba
->pport
->fc_myDID
= 1;
1928 rc
= lpfc_sli4_diag_fcport_reg_setup(phba
);
1930 goto loopback_mode_exit
;
1933 /* wait for the port ready */
1936 while (phba
->link_state
!= LPFC_HBA_READY
) {
1937 if (i
++ > timeout
) {
1939 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1940 "3133 Timeout waiting for port "
1941 "loopback mode ready, timeout:%d ms\n",
1950 /* clear loopback diagnostic mode */
1952 spin_lock_irq(&phba
->hbalock
);
1953 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
1954 spin_unlock_irq(&phba
->hbalock
);
1956 lpfc_bsg_diag_mode_exit(phba
);
1959 /* make error code available to userspace */
1960 job
->reply
->result
= rc
;
1961 /* complete the job back to userspace if no error */
1968 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
1969 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1971 * This function is responsible for responding to check and dispatch bsg diag
1972 * command from the user to proper driver action routines.
1975 lpfc_bsg_diag_loopback_mode(struct fc_bsg_job
*job
)
1977 struct Scsi_Host
*shost
;
1978 struct lpfc_vport
*vport
;
1979 struct lpfc_hba
*phba
;
1985 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1992 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1993 rc
= lpfc_sli3_bsg_diag_loopback_mode(phba
, job
);
1994 else if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1995 LPFC_SLI_INTF_IF_TYPE_2
)
1996 rc
= lpfc_sli4_bsg_diag_loopback_mode(phba
, job
);
2004 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
2005 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
2007 * This function is responsible for responding to check and dispatch bsg diag
2008 * command from the user to proper driver action routines.
2011 lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job
*job
)
2013 struct Scsi_Host
*shost
;
2014 struct lpfc_vport
*vport
;
2015 struct lpfc_hba
*phba
;
2016 struct diag_mode_set
*loopback_mode_end_cmd
;
2023 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2030 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2032 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2033 LPFC_SLI_INTF_IF_TYPE_2
)
2036 /* clear loopback diagnostic mode */
2037 spin_lock_irq(&phba
->hbalock
);
2038 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
2039 spin_unlock_irq(&phba
->hbalock
);
2040 loopback_mode_end_cmd
= (struct diag_mode_set
*)
2041 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2042 timeout
= loopback_mode_end_cmd
->timeout
* 100;
2044 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2046 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2047 "3139 Failed to bring link to diagnostic "
2048 "state, rc:x%x\n", rc
);
2049 goto loopback_mode_end_exit
;
2052 /* wait for link down before proceeding */
2054 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
2055 if (i
++ > timeout
) {
2057 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2058 "3140 Timeout waiting for link to "
2059 "diagnostic mode_end, timeout:%d ms\n",
2061 /* there is nothing much we can do here */
2067 /* reset port resource registrations */
2068 rc
= lpfc_selective_reset(phba
);
2069 phba
->pport
->fc_myDID
= 0;
2071 loopback_mode_end_exit
:
2072 /* make return code available to userspace */
2073 job
->reply
->result
= rc
;
2074 /* complete the job back to userspace if no error */
2081 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
2082 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
2084 * This function is to perform SLI4 diag link test request from the user
2088 lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job
*job
)
2090 struct Scsi_Host
*shost
;
2091 struct lpfc_vport
*vport
;
2092 struct lpfc_hba
*phba
;
2093 LPFC_MBOXQ_t
*pmboxq
;
2094 struct sli4_link_diag
*link_diag_test_cmd
;
2095 uint32_t req_len
, alloc_len
;
2097 struct lpfc_mbx_run_link_diag_test
*run_link_diag_test
;
2098 union lpfc_sli4_cfg_shdr
*shdr
;
2099 uint32_t shdr_status
, shdr_add_status
;
2100 struct diag_status
*diag_status_reply
;
2101 int mbxstatus
, rc
= 0;
2108 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2119 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2123 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2124 LPFC_SLI_INTF_IF_TYPE_2
) {
2129 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
2130 sizeof(struct sli4_link_diag
)) {
2131 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2132 "3013 Received LINK DIAG TEST request "
2133 " size:%d below the minimum size:%d\n",
2135 (int)(sizeof(struct fc_bsg_request
) +
2136 sizeof(struct sli4_link_diag
)));
2141 rc
= lpfc_bsg_diag_mode_enter(phba
);
2145 link_diag_test_cmd
= (struct sli4_link_diag
*)
2146 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2147 timeout
= link_diag_test_cmd
->timeout
* 100;
2149 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
2154 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2157 goto link_diag_test_exit
;
2160 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
2161 sizeof(struct lpfc_sli4_cfg_mhdr
));
2162 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2163 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
2164 req_len
, LPFC_SLI4_MBX_EMBED
);
2165 if (alloc_len
!= req_len
) {
2167 goto link_diag_test_exit
;
2169 run_link_diag_test
= &pmboxq
->u
.mqe
.un
.link_diag_test
;
2170 bf_set(lpfc_mbx_run_diag_test_link_num
, &run_link_diag_test
->u
.req
,
2171 phba
->sli4_hba
.lnk_info
.lnk_no
);
2172 bf_set(lpfc_mbx_run_diag_test_link_type
, &run_link_diag_test
->u
.req
,
2173 phba
->sli4_hba
.lnk_info
.lnk_tp
);
2174 bf_set(lpfc_mbx_run_diag_test_test_id
, &run_link_diag_test
->u
.req
,
2175 link_diag_test_cmd
->test_id
);
2176 bf_set(lpfc_mbx_run_diag_test_loops
, &run_link_diag_test
->u
.req
,
2177 link_diag_test_cmd
->loops
);
2178 bf_set(lpfc_mbx_run_diag_test_test_ver
, &run_link_diag_test
->u
.req
,
2179 link_diag_test_cmd
->test_version
);
2180 bf_set(lpfc_mbx_run_diag_test_err_act
, &run_link_diag_test
->u
.req
,
2181 link_diag_test_cmd
->error_action
);
2183 mbxstatus
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2185 shdr
= (union lpfc_sli4_cfg_shdr
*)
2186 &pmboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2187 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
2188 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
2189 if (shdr_status
|| shdr_add_status
|| mbxstatus
) {
2190 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2191 "3010 Run link diag test mailbox failed with "
2192 "mbx_status x%x status x%x, add_status x%x\n",
2193 mbxstatus
, shdr_status
, shdr_add_status
);
2196 diag_status_reply
= (struct diag_status
*)
2197 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
2199 if (job
->reply_len
<
2200 sizeof(struct fc_bsg_request
) + sizeof(struct diag_status
)) {
2201 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2202 "3012 Received Run link diag test reply "
2203 "below minimum size (%d): reply_len:%d\n",
2204 (int)(sizeof(struct fc_bsg_request
) +
2205 sizeof(struct diag_status
)),
2211 diag_status_reply
->mbox_status
= mbxstatus
;
2212 diag_status_reply
->shdr_status
= shdr_status
;
2213 diag_status_reply
->shdr_add_status
= shdr_add_status
;
2215 link_diag_test_exit
:
2216 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2219 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2221 lpfc_bsg_diag_mode_exit(phba
);
2224 /* make error code available to userspace */
2225 job
->reply
->result
= rc
;
2226 /* complete the job back to userspace if no error */
2233 * lpfcdiag_loop_self_reg - obtains a remote port login id
2234 * @phba: Pointer to HBA context object
2235 * @rpi: Pointer to a remote port login id
2237 * This function obtains a remote port login id so the diag loopback test
2238 * can send and receive its own unsolicited CT command.
2240 static int lpfcdiag_loop_self_reg(struct lpfc_hba
*phba
, uint16_t *rpi
)
2243 struct lpfc_dmabuf
*dmabuff
;
2246 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2250 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2251 status
= lpfc_reg_rpi(phba
, 0, phba
->pport
->fc_myDID
,
2252 (uint8_t *)&phba
->pport
->fc_sparam
,
2255 *rpi
= lpfc_sli4_alloc_rpi(phba
);
2256 status
= lpfc_reg_rpi(phba
, phba
->pport
->vpi
,
2257 phba
->pport
->fc_myDID
,
2258 (uint8_t *)&phba
->pport
->fc_sparam
,
2263 mempool_free(mbox
, phba
->mbox_mem_pool
);
2264 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2265 lpfc_sli4_free_rpi(phba
, *rpi
);
2269 dmabuff
= (struct lpfc_dmabuf
*) mbox
->context1
;
2270 mbox
->context1
= NULL
;
2271 mbox
->context2
= NULL
;
2272 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2274 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2275 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2277 if (status
!= MBX_TIMEOUT
)
2278 mempool_free(mbox
, phba
->mbox_mem_pool
);
2279 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2280 lpfc_sli4_free_rpi(phba
, *rpi
);
2284 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2285 *rpi
= mbox
->u
.mb
.un
.varWords
[0];
2287 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2289 mempool_free(mbox
, phba
->mbox_mem_pool
);
2294 * lpfcdiag_loop_self_unreg - unregs from the rpi
2295 * @phba: Pointer to HBA context object
2296 * @rpi: Remote port login id
2298 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2300 static int lpfcdiag_loop_self_unreg(struct lpfc_hba
*phba
, uint16_t rpi
)
2305 /* Allocate mboxq structure */
2306 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2310 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2311 lpfc_unreg_login(phba
, 0, rpi
, mbox
);
2313 lpfc_unreg_login(phba
, phba
->pport
->vpi
,
2314 phba
->sli4_hba
.rpi_ids
[rpi
], mbox
);
2316 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2318 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2319 if (status
!= MBX_TIMEOUT
)
2320 mempool_free(mbox
, phba
->mbox_mem_pool
);
2323 mempool_free(mbox
, phba
->mbox_mem_pool
);
2324 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2325 lpfc_sli4_free_rpi(phba
, rpi
);
2330 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2331 * @phba: Pointer to HBA context object
2332 * @rpi: Remote port login id
2333 * @txxri: Pointer to transmit exchange id
2334 * @rxxri: Pointer to response exchabge id
2336 * This function obtains the transmit and receive ids required to send
2337 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2338 * flags are used to the unsolicted response handler is able to process
2339 * the ct command sent on the same port.
2341 static int lpfcdiag_loop_get_xri(struct lpfc_hba
*phba
, uint16_t rpi
,
2342 uint16_t *txxri
, uint16_t * rxxri
)
2344 struct lpfc_bsg_event
*evt
;
2345 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2347 struct lpfc_dmabuf
*dmabuf
;
2348 struct ulp_bde64
*bpl
= NULL
;
2349 struct lpfc_sli_ct_request
*ctreq
= NULL
;
2353 unsigned long flags
;
2357 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2358 SLI_CT_ELX_LOOPBACK
);
2362 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2363 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2364 lpfc_bsg_event_ref(evt
);
2365 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2367 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2368 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2370 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2372 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, 0, &dmabuf
->phys
);
2374 INIT_LIST_HEAD(&dmabuf
->list
);
2375 bpl
= (struct ulp_bde64
*) dmabuf
->virt
;
2376 memset(bpl
, 0, sizeof(*bpl
));
2377 ctreq
= (struct lpfc_sli_ct_request
*)(bpl
+ 1);
2379 le32_to_cpu(putPaddrHigh(dmabuf
->phys
+
2382 le32_to_cpu(putPaddrLow(dmabuf
->phys
+
2384 bpl
->tus
.f
.bdeFlags
= 0;
2385 bpl
->tus
.f
.bdeSize
= ELX_LOOPBACK_HEADER_SZ
;
2386 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2390 if (cmdiocbq
== NULL
|| rspiocbq
== NULL
||
2391 dmabuf
== NULL
|| bpl
== NULL
|| ctreq
== NULL
||
2392 dmabuf
->virt
== NULL
) {
2394 goto err_get_xri_exit
;
2397 cmd
= &cmdiocbq
->iocb
;
2398 rsp
= &rspiocbq
->iocb
;
2400 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2402 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2403 ctreq
->RevisionId
.bits
.InId
= 0;
2404 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2405 ctreq
->FsSubType
= 0;
2406 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_XRI_SETUP
;
2407 ctreq
->CommandResponse
.bits
.Size
= 0;
2410 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(dmabuf
->phys
);
2411 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(dmabuf
->phys
);
2412 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2413 cmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(*bpl
);
2415 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= LA
;
2416 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2417 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2418 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2420 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CR
;
2421 cmd
->ulpBdeCount
= 1;
2423 cmd
->ulpClass
= CLASS3
;
2424 cmd
->ulpContext
= rpi
;
2426 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2427 cmdiocbq
->vport
= phba
->pport
;
2429 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2431 (phba
->fc_ratov
* 2)
2432 + LPFC_DRVR_TIMEOUT
);
2435 goto err_get_xri_exit
;
2437 *txxri
= rsp
->ulpContext
;
2440 evt
->wait_time_stamp
= jiffies
;
2441 time_left
= wait_event_interruptible_timeout(
2442 evt
->wq
, !list_empty(&evt
->events_to_see
),
2443 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
2444 if (list_empty(&evt
->events_to_see
))
2445 ret_val
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
2447 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2448 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2449 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2450 *rxxri
= (list_entry(evt
->events_to_get
.prev
,
2451 typeof(struct event_data
),
2457 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2458 lpfc_bsg_event_unref(evt
); /* release ref */
2459 lpfc_bsg_event_unref(evt
); /* delete */
2460 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2464 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2468 if (cmdiocbq
&& (iocb_stat
!= IOCB_TIMEDOUT
))
2469 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2471 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2476 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2477 * @phba: Pointer to HBA context object
2479 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and.
2480 * retruns the pointer to the buffer.
2482 static struct lpfc_dmabuf
*
2483 lpfc_bsg_dma_page_alloc(struct lpfc_hba
*phba
)
2485 struct lpfc_dmabuf
*dmabuf
;
2486 struct pci_dev
*pcidev
= phba
->pcidev
;
2488 /* allocate dma buffer struct */
2489 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2493 INIT_LIST_HEAD(&dmabuf
->list
);
2495 /* now, allocate dma buffer */
2496 dmabuf
->virt
= dma_alloc_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2497 &(dmabuf
->phys
), GFP_KERNEL
);
2499 if (!dmabuf
->virt
) {
2503 memset((uint8_t *)dmabuf
->virt
, 0, BSG_MBOX_SIZE
);
2509 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2510 * @phba: Pointer to HBA context object.
2511 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2513 * This routine just simply frees a dma buffer and its associated buffer
2514 * descriptor referred by @dmabuf.
2517 lpfc_bsg_dma_page_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*dmabuf
)
2519 struct pci_dev
*pcidev
= phba
->pcidev
;
2525 dma_free_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2526 dmabuf
->virt
, dmabuf
->phys
);
2532 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2533 * @phba: Pointer to HBA context object.
2534 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2536 * This routine just simply frees all dma buffers and their associated buffer
2537 * descriptors referred by @dmabuf_list.
2540 lpfc_bsg_dma_page_list_free(struct lpfc_hba
*phba
,
2541 struct list_head
*dmabuf_list
)
2543 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
2545 if (list_empty(dmabuf_list
))
2548 list_for_each_entry_safe(dmabuf
, next_dmabuf
, dmabuf_list
, list
) {
2549 list_del_init(&dmabuf
->list
);
2550 lpfc_bsg_dma_page_free(phba
, dmabuf
);
2556 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2557 * @phba: Pointer to HBA context object
2558 * @bpl: Pointer to 64 bit bde structure
2559 * @size: Number of bytes to process
2560 * @nocopydata: Flag to copy user data into the allocated buffer
2562 * This function allocates page size buffers and populates an lpfc_dmabufext.
2563 * If allowed the user data pointed to with indataptr is copied into the kernel
2564 * memory. The chained list of page size buffers is returned.
2566 static struct lpfc_dmabufext
*
2567 diag_cmd_data_alloc(struct lpfc_hba
*phba
,
2568 struct ulp_bde64
*bpl
, uint32_t size
,
2571 struct lpfc_dmabufext
*mlist
= NULL
;
2572 struct lpfc_dmabufext
*dmp
;
2573 int cnt
, offset
= 0, i
= 0;
2574 struct pci_dev
*pcidev
;
2576 pcidev
= phba
->pcidev
;
2579 /* We get chunks of 4K */
2580 if (size
> BUF_SZ_4K
)
2585 /* allocate struct lpfc_dmabufext buffer header */
2586 dmp
= kmalloc(sizeof(struct lpfc_dmabufext
), GFP_KERNEL
);
2590 INIT_LIST_HEAD(&dmp
->dma
.list
);
2592 /* Queue it to a linked list */
2594 list_add_tail(&dmp
->dma
.list
, &mlist
->dma
.list
);
2598 /* allocate buffer */
2599 dmp
->dma
.virt
= dma_alloc_coherent(&pcidev
->dev
,
2610 bpl
->tus
.f
.bdeFlags
= 0;
2611 pci_dma_sync_single_for_device(phba
->pcidev
,
2612 dmp
->dma
.phys
, LPFC_BPL_SIZE
, PCI_DMA_TODEVICE
);
2615 memset((uint8_t *)dmp
->dma
.virt
, 0, cnt
);
2616 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2619 /* build buffer ptr list for IOCB */
2620 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dmp
->dma
.phys
));
2621 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dmp
->dma
.phys
));
2622 bpl
->tus
.f
.bdeSize
= (ushort
) cnt
;
2623 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2634 diag_cmd_data_free(phba
, mlist
);
2639 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2640 * @phba: Pointer to HBA context object
2641 * @rxxri: Receive exchange id
2642 * @len: Number of data bytes
2644 * This function allocates and posts a data buffer of sufficient size to receive
2645 * an unsolicted CT command.
2647 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba
*phba
, uint16_t rxxri
,
2650 struct lpfc_sli
*psli
= &phba
->sli
;
2651 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2652 struct lpfc_iocbq
*cmdiocbq
;
2654 struct list_head head
, *curr
, *next
;
2655 struct lpfc_dmabuf
*rxbmp
;
2656 struct lpfc_dmabuf
*dmp
;
2657 struct lpfc_dmabuf
*mp
[2] = {NULL
, NULL
};
2658 struct ulp_bde64
*rxbpl
= NULL
;
2660 struct lpfc_dmabufext
*rxbuffer
= NULL
;
2665 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2666 rxbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2667 if (rxbmp
!= NULL
) {
2668 rxbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &rxbmp
->phys
);
2670 INIT_LIST_HEAD(&rxbmp
->list
);
2671 rxbpl
= (struct ulp_bde64
*) rxbmp
->virt
;
2672 rxbuffer
= diag_cmd_data_alloc(phba
, rxbpl
, len
, 0);
2676 if (!cmdiocbq
|| !rxbmp
|| !rxbpl
|| !rxbuffer
) {
2678 goto err_post_rxbufs_exit
;
2681 /* Queue buffers for the receive exchange */
2682 num_bde
= (uint32_t)rxbuffer
->flag
;
2683 dmp
= &rxbuffer
->dma
;
2685 cmd
= &cmdiocbq
->iocb
;
2688 INIT_LIST_HEAD(&head
);
2689 list_add_tail(&head
, &dmp
->list
);
2690 list_for_each_safe(curr
, next
, &head
) {
2691 mp
[i
] = list_entry(curr
, struct lpfc_dmabuf
, list
);
2694 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2695 mp
[i
]->buffer_tag
= lpfc_sli_get_buffer_tag(phba
);
2696 cmd
->un
.quexri64cx
.buff
.bde
.addrHigh
=
2697 putPaddrHigh(mp
[i
]->phys
);
2698 cmd
->un
.quexri64cx
.buff
.bde
.addrLow
=
2699 putPaddrLow(mp
[i
]->phys
);
2700 cmd
->un
.quexri64cx
.buff
.bde
.tus
.f
.bdeSize
=
2701 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2702 cmd
->un
.quexri64cx
.buff
.buffer_tag
= mp
[i
]->buffer_tag
;
2703 cmd
->ulpCommand
= CMD_QUE_XRI64_CX
;
2706 cmd
->ulpBdeCount
= 1;
2707 cmd
->unsli3
.que_xri64cx_ext_words
.ebde_count
= 0;
2710 cmd
->un
.cont64
[i
].addrHigh
= putPaddrHigh(mp
[i
]->phys
);
2711 cmd
->un
.cont64
[i
].addrLow
= putPaddrLow(mp
[i
]->phys
);
2712 cmd
->un
.cont64
[i
].tus
.f
.bdeSize
=
2713 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2714 cmd
->ulpBdeCount
= ++i
;
2716 if ((--num_bde
> 0) && (i
< 2))
2719 cmd
->ulpCommand
= CMD_QUE_XRI_BUF64_CX
;
2723 cmd
->ulpClass
= CLASS3
;
2724 cmd
->ulpContext
= rxxri
;
2726 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
2728 if (iocb_stat
== IOCB_ERROR
) {
2729 diag_cmd_data_free(phba
,
2730 (struct lpfc_dmabufext
*)mp
[0]);
2732 diag_cmd_data_free(phba
,
2733 (struct lpfc_dmabufext
*)mp
[1]);
2734 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2736 goto err_post_rxbufs_exit
;
2739 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[0]);
2741 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[1]);
2745 /* The iocb was freed by lpfc_sli_issue_iocb */
2746 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2748 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2750 goto err_post_rxbufs_exit
;
2753 cmd
= &cmdiocbq
->iocb
;
2758 err_post_rxbufs_exit
:
2762 lpfc_mbuf_free(phba
, rxbmp
->virt
, rxbmp
->phys
);
2767 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2772 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
2773 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2775 * This function receives a user data buffer to be transmitted and received on
2776 * the same port, the link must be up and in loopback mode prior
2778 * 1. A kernel buffer is allocated to copy the user data into.
2779 * 2. The port registers with "itself".
2780 * 3. The transmit and receive exchange ids are obtained.
2781 * 4. The receive exchange id is posted.
2782 * 5. A new els loopback event is created.
2783 * 6. The command and response iocbs are allocated.
2784 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2786 * This function is meant to be called n times while the port is in loopback
2787 * so it is the apps responsibility to issue a reset to take the port out
2791 lpfc_bsg_diag_loopback_run(struct fc_bsg_job
*job
)
2793 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2794 struct lpfc_hba
*phba
= vport
->phba
;
2795 struct diag_mode_test
*diag_mode
;
2796 struct lpfc_bsg_event
*evt
;
2797 struct event_data
*evdat
;
2798 struct lpfc_sli
*psli
= &phba
->sli
;
2801 size_t segment_len
= 0, segment_offset
= 0, current_offset
= 0;
2803 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
= NULL
;
2804 IOCB_t
*cmd
, *rsp
= NULL
;
2805 struct lpfc_sli_ct_request
*ctreq
;
2806 struct lpfc_dmabuf
*txbmp
;
2807 struct ulp_bde64
*txbpl
= NULL
;
2808 struct lpfc_dmabufext
*txbuffer
= NULL
;
2809 struct list_head head
;
2810 struct lpfc_dmabuf
*curr
;
2811 uint16_t txxri
= 0, rxxri
;
2813 uint8_t *ptr
= NULL
, *rx_databuf
= NULL
;
2817 unsigned long flags
;
2818 void *dataout
= NULL
;
2821 /* in case no data is returned return just the return code */
2822 job
->reply
->reply_payload_rcv_len
= 0;
2824 if (job
->request_len
<
2825 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_test
)) {
2826 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2827 "2739 Received DIAG TEST request below minimum "
2830 goto loopback_test_exit
;
2833 if (job
->request_payload
.payload_len
!=
2834 job
->reply_payload
.payload_len
) {
2836 goto loopback_test_exit
;
2838 diag_mode
= (struct diag_mode_test
*)
2839 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2841 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
2842 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
2843 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
2845 goto loopback_test_exit
;
2848 if (!lpfc_is_link_up(phba
) || !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
2850 goto loopback_test_exit
;
2853 size
= job
->request_payload
.payload_len
;
2854 full_size
= size
+ ELX_LOOPBACK_HEADER_SZ
; /* plus the header */
2856 if ((size
== 0) || (size
> 80 * BUF_SZ_4K
)) {
2858 goto loopback_test_exit
;
2861 if (full_size
>= BUF_SZ_4K
) {
2863 * Allocate memory for ioctl data. If buffer is bigger than 64k,
2864 * then we allocate 64k and re-use that buffer over and over to
2865 * xfer the whole block. This is because Linux kernel has a
2866 * problem allocating more than 120k of kernel space memory. Saw
2867 * problem with GET_FCPTARGETMAPPING...
2869 if (size
<= (64 * 1024))
2870 total_mem
= full_size
;
2872 total_mem
= 64 * 1024;
2874 /* Allocate memory for ioctl data */
2875 total_mem
= BUF_SZ_4K
;
2877 dataout
= kmalloc(total_mem
, GFP_KERNEL
);
2878 if (dataout
== NULL
) {
2880 goto loopback_test_exit
;
2884 ptr
+= ELX_LOOPBACK_HEADER_SZ
;
2885 sg_copy_to_buffer(job
->request_payload
.sg_list
,
2886 job
->request_payload
.sg_cnt
,
2888 rc
= lpfcdiag_loop_self_reg(phba
, &rpi
);
2890 goto loopback_test_exit
;
2892 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2893 rc
= lpfcdiag_loop_get_xri(phba
, rpi
, &txxri
, &rxxri
);
2895 lpfcdiag_loop_self_unreg(phba
, rpi
);
2896 goto loopback_test_exit
;
2899 rc
= lpfcdiag_loop_post_rxbufs(phba
, rxxri
, full_size
);
2901 lpfcdiag_loop_self_unreg(phba
, rpi
);
2902 goto loopback_test_exit
;
2905 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2906 SLI_CT_ELX_LOOPBACK
);
2908 lpfcdiag_loop_self_unreg(phba
, rpi
);
2910 goto loopback_test_exit
;
2913 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2914 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2915 lpfc_bsg_event_ref(evt
);
2916 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2918 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2919 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2920 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2921 txbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2924 txbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &txbmp
->phys
);
2926 INIT_LIST_HEAD(&txbmp
->list
);
2927 txbpl
= (struct ulp_bde64
*) txbmp
->virt
;
2928 txbuffer
= diag_cmd_data_alloc(phba
,
2929 txbpl
, full_size
, 0);
2933 if (!cmdiocbq
|| !txbmp
|| !txbpl
|| !txbuffer
|| !txbmp
->virt
) {
2935 goto err_loopback_test_exit
;
2937 if ((phba
->sli_rev
< LPFC_SLI_REV4
) && !rspiocbq
) {
2939 goto err_loopback_test_exit
;
2942 cmd
= &cmdiocbq
->iocb
;
2943 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2944 rsp
= &rspiocbq
->iocb
;
2946 INIT_LIST_HEAD(&head
);
2947 list_add_tail(&head
, &txbuffer
->dma
.list
);
2948 list_for_each_entry(curr
, &head
, list
) {
2949 segment_len
= ((struct lpfc_dmabufext
*)curr
)->size
;
2950 if (current_offset
== 0) {
2952 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2953 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2954 ctreq
->RevisionId
.bits
.InId
= 0;
2955 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2956 ctreq
->FsSubType
= 0;
2957 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_DATA
;
2958 ctreq
->CommandResponse
.bits
.Size
= size
;
2959 segment_offset
= ELX_LOOPBACK_HEADER_SZ
;
2963 BUG_ON(segment_offset
>= segment_len
);
2964 memcpy(curr
->virt
+ segment_offset
,
2965 ptr
+ current_offset
,
2966 segment_len
- segment_offset
);
2968 current_offset
+= segment_len
- segment_offset
;
2969 BUG_ON(current_offset
> size
);
2973 /* Build the XMIT_SEQUENCE iocb */
2974 num_bde
= (uint32_t)txbuffer
->flag
;
2976 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(txbmp
->phys
);
2977 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(txbmp
->phys
);
2978 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2979 cmd
->un
.xseq64
.bdl
.bdeSize
= (num_bde
* sizeof(struct ulp_bde64
));
2981 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
2982 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2983 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2984 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2986 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
2987 cmd
->ulpBdeCount
= 1;
2989 cmd
->ulpClass
= CLASS3
;
2991 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2992 cmd
->ulpContext
= txxri
;
2994 cmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
2995 cmd
->un
.ulpWord
[3] = phba
->sli4_hba
.rpi_ids
[rpi
];
2996 cmdiocbq
->context3
= txbmp
;
2997 cmdiocbq
->sli4_xritag
= NO_XRI
;
2998 cmd
->unsli3
.rcvsli3
.ox_id
= 0xffff;
3000 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
3001 cmdiocbq
->vport
= phba
->pport
;
3002 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
3003 rspiocbq
, (phba
->fc_ratov
* 2) +
3006 if ((iocb_stat
!= IOCB_SUCCESS
) || ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3007 (rsp
->ulpStatus
!= IOCB_SUCCESS
))) {
3008 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3009 "3126 Failed loopback test issue iocb: "
3010 "iocb_stat:x%x\n", iocb_stat
);
3012 goto err_loopback_test_exit
;
3016 time_left
= wait_event_interruptible_timeout(
3017 evt
->wq
, !list_empty(&evt
->events_to_see
),
3018 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
3020 if (list_empty(&evt
->events_to_see
)) {
3021 rc
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
3022 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3023 "3125 Not receiving unsolicited event, "
3026 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3027 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
3028 evdat
= list_entry(evt
->events_to_get
.prev
,
3029 typeof(*evdat
), node
);
3030 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3031 rx_databuf
= evdat
->data
;
3032 if (evdat
->len
!= full_size
) {
3033 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3034 "1603 Loopback test did not receive expected "
3035 "data length. actual length 0x%x expected "
3037 evdat
->len
, full_size
);
3039 } else if (rx_databuf
== NULL
)
3043 /* skip over elx loopback header */
3044 rx_databuf
+= ELX_LOOPBACK_HEADER_SZ
;
3045 job
->reply
->reply_payload_rcv_len
=
3046 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3047 job
->reply_payload
.sg_cnt
,
3049 job
->reply
->reply_payload_rcv_len
= size
;
3053 err_loopback_test_exit
:
3054 lpfcdiag_loop_self_unreg(phba
, rpi
);
3056 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3057 lpfc_bsg_event_unref(evt
); /* release ref */
3058 lpfc_bsg_event_unref(evt
); /* delete */
3059 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3061 if (cmdiocbq
!= NULL
)
3062 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
3064 if (rspiocbq
!= NULL
)
3065 lpfc_sli_release_iocbq(phba
, rspiocbq
);
3067 if (txbmp
!= NULL
) {
3068 if (txbpl
!= NULL
) {
3069 if (txbuffer
!= NULL
)
3070 diag_cmd_data_free(phba
, txbuffer
);
3071 lpfc_mbuf_free(phba
, txbmp
->virt
, txbmp
->phys
);
3078 /* make error code available to userspace */
3079 job
->reply
->result
= rc
;
3080 job
->dd_data
= NULL
;
3081 /* complete the job back to userspace if no error */
3082 if (rc
== IOCB_SUCCESS
)
3088 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
3089 * @job: GET_DFC_REV fc_bsg_job
3092 lpfc_bsg_get_dfc_rev(struct fc_bsg_job
*job
)
3094 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
3095 struct lpfc_hba
*phba
= vport
->phba
;
3096 struct get_mgmt_rev
*event_req
;
3097 struct get_mgmt_rev_reply
*event_reply
;
3100 if (job
->request_len
<
3101 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev
)) {
3102 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3103 "2740 Received GET_DFC_REV request below "
3109 event_req
= (struct get_mgmt_rev
*)
3110 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3112 event_reply
= (struct get_mgmt_rev_reply
*)
3113 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
3115 if (job
->reply_len
<
3116 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev_reply
)) {
3117 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3118 "2741 Received GET_DFC_REV reply below "
3124 event_reply
->info
.a_Major
= MANAGEMENT_MAJOR_REV
;
3125 event_reply
->info
.a_Minor
= MANAGEMENT_MINOR_REV
;
3127 job
->reply
->result
= rc
;
3134 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
3135 * @phba: Pointer to HBA context object.
3136 * @pmboxq: Pointer to mailbox command.
3138 * This is completion handler function for mailbox commands issued from
3139 * lpfc_bsg_issue_mbox function. This function is called by the
3140 * mailbox event handler function with no lock held. This function
3141 * will wake up thread waiting on the wait queue pointed by context1
3145 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3147 struct bsg_job_data
*dd_data
;
3148 struct fc_bsg_job
*job
;
3150 unsigned long flags
;
3151 uint8_t *pmb
, *pmb_buf
;
3153 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3154 dd_data
= pmboxq
->context1
;
3155 /* job already timed out? */
3157 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3162 * The outgoing buffer is readily referred from the dma buffer,
3163 * just need to get header part from mailboxq structure.
3165 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3166 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3167 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3169 job
= dd_data
->context_un
.mbox
.set_job
;
3171 size
= job
->reply_payload
.payload_len
;
3172 job
->reply
->reply_payload_rcv_len
=
3173 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3174 job
->reply_payload
.sg_cnt
,
3176 /* need to hold the lock until we set job->dd_data to NULL
3177 * to hold off the timeout handler returning to the mid-layer
3178 * while we are still processing the job.
3180 job
->dd_data
= NULL
;
3181 dd_data
->context_un
.mbox
.set_job
= NULL
;
3182 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3184 dd_data
->context_un
.mbox
.set_job
= NULL
;
3185 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3188 mempool_free(dd_data
->context_un
.mbox
.pmboxq
, phba
->mbox_mem_pool
);
3189 lpfc_bsg_dma_page_free(phba
, dd_data
->context_un
.mbox
.dmabuffers
);
3193 job
->reply
->result
= 0;
3200 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3201 * @phba: Pointer to HBA context object.
3202 * @mb: Pointer to a mailbox object.
3203 * @vport: Pointer to a vport object.
3205 * Some commands require the port to be offline, some may not be called from
3208 static int lpfc_bsg_check_cmd_access(struct lpfc_hba
*phba
,
3209 MAILBOX_t
*mb
, struct lpfc_vport
*vport
)
3211 /* return negative error values for bsg job */
3212 switch (mb
->mbxCommand
) {
3216 case MBX_CONFIG_LINK
:
3217 case MBX_CONFIG_RING
:
3218 case MBX_RESET_RING
:
3219 case MBX_UNREG_LOGIN
:
3221 case MBX_DUMP_CONTEXT
:
3225 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
3226 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3227 "2743 Command 0x%x is illegal in on-line "
3233 case MBX_WRITE_VPARMS
:
3236 case MBX_READ_CONFIG
:
3237 case MBX_READ_RCONFIG
:
3238 case MBX_READ_STATUS
:
3241 case MBX_READ_LNK_STAT
:
3242 case MBX_DUMP_MEMORY
:
3244 case MBX_UPDATE_CFG
:
3245 case MBX_KILL_BOARD
:
3247 case MBX_LOAD_EXP_ROM
:
3249 case MBX_DEL_LD_ENTRY
:
3252 case MBX_SLI4_CONFIG
:
3253 case MBX_READ_EVENT_LOG
:
3254 case MBX_READ_EVENT_LOG_STATUS
:
3255 case MBX_WRITE_EVENT_LOG
:
3256 case MBX_PORT_CAPABILITIES
:
3257 case MBX_PORT_IOV_CONTROL
:
3258 case MBX_RUN_BIU_DIAG64
:
3260 case MBX_SET_VARIABLE
:
3261 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3262 "1226 mbox: set_variable 0x%x, 0x%x\n",
3264 mb
->un
.varWords
[1]);
3265 if ((mb
->un
.varWords
[0] == SETVAR_MLOMNT
)
3266 && (mb
->un
.varWords
[1] == 1)) {
3267 phba
->wait_4_mlo_maint_flg
= 1;
3268 } else if (mb
->un
.varWords
[0] == SETVAR_MLORST
) {
3269 spin_lock_irq(&phba
->hbalock
);
3270 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
3271 spin_unlock_irq(&phba
->hbalock
);
3272 phba
->fc_topology
= LPFC_TOPOLOGY_PT_PT
;
3275 case MBX_READ_SPARM64
:
3276 case MBX_READ_TOPOLOGY
:
3278 case MBX_REG_LOGIN64
:
3279 case MBX_CONFIG_PORT
:
3280 case MBX_RUN_BIU_DIAG
:
3282 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3283 "2742 Unknown Command 0x%x\n",
3292 * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
3293 * @phba: Pointer to HBA context object.
3295 * This is routine clean up and reset BSG handling of multi-buffer mbox
3299 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba
*phba
)
3301 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
)
3304 /* free all memory, including dma buffers */
3305 lpfc_bsg_dma_page_list_free(phba
,
3306 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3307 lpfc_bsg_dma_page_free(phba
, phba
->mbox_ext_buf_ctx
.mbx_dmabuf
);
3308 /* multi-buffer write mailbox command pass-through complete */
3309 memset((char *)&phba
->mbox_ext_buf_ctx
, 0,
3310 sizeof(struct lpfc_mbox_ext_buf_ctx
));
3311 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3317 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3318 * @phba: Pointer to HBA context object.
3319 * @pmboxq: Pointer to mailbox command.
3321 * This is routine handles BSG job for mailbox commands completions with
3322 * multiple external buffers.
3324 static struct fc_bsg_job
*
3325 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3327 struct bsg_job_data
*dd_data
;
3328 struct fc_bsg_job
*job
;
3329 uint8_t *pmb
, *pmb_buf
;
3330 unsigned long flags
;
3333 struct lpfc_dmabuf
*dmabuf
;
3334 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3337 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3338 dd_data
= pmboxq
->context1
;
3339 /* has the job already timed out? */
3341 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3347 * The outgoing buffer is readily referred from the dma buffer,
3348 * just need to get header part from mailboxq structure.
3350 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3351 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3352 /* Copy the byte swapped response mailbox back to the user */
3353 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3354 /* if there is any non-embedded extended data copy that too */
3355 dmabuf
= phba
->mbox_ext_buf_ctx
.mbx_dmabuf
;
3356 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3357 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3358 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3359 pmbx
= (uint8_t *)dmabuf
->virt
;
3360 /* byte swap the extended data following the mailbox command */
3361 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3362 &pmbx
[sizeof(MAILBOX_t
)],
3363 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[0].buf_len
);
3366 job
= dd_data
->context_un
.mbox
.set_job
;
3368 size
= job
->reply_payload
.payload_len
;
3369 job
->reply
->reply_payload_rcv_len
=
3370 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3371 job
->reply_payload
.sg_cnt
,
3373 /* result for successful */
3374 job
->reply
->result
= 0;
3375 job
->dd_data
= NULL
;
3376 /* need to hold the lock util we set job->dd_data to NULL
3377 * to hold off the timeout handler from midlayer to take
3380 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3381 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3382 "2937 SLI_CONFIG ext-buffer maibox command "
3383 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3384 phba
->mbox_ext_buf_ctx
.nembType
,
3385 phba
->mbox_ext_buf_ctx
.mboxType
, size
);
3386 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
,
3387 phba
->mbox_ext_buf_ctx
.nembType
,
3388 phba
->mbox_ext_buf_ctx
.mboxType
,
3389 dma_ebuf
, sta_pos_addr
,
3390 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
, 0);
3392 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3396 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3397 "2938 SLI_CONFIG ext-buffer maibox "
3398 "command (x%x/x%x) failure, rc:x%x\n",
3399 phba
->mbox_ext_buf_ctx
.nembType
,
3400 phba
->mbox_ext_buf_ctx
.mboxType
, rc
);
3402 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_DONE
;
3409 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3410 * @phba: Pointer to HBA context object.
3411 * @pmboxq: Pointer to mailbox command.
3413 * This is completion handler function for mailbox read commands with multiple
3417 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3419 struct fc_bsg_job
*job
;
3421 /* handle the BSG job with mailbox command */
3422 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3423 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3425 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3426 "2939 SLI_CONFIG ext-buffer rd maibox command "
3427 "complete, ctxState:x%x, mbxStatus:x%x\n",
3428 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3430 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3432 if (pmboxq
->u
.mb
.mbxStatus
|| phba
->mbox_ext_buf_ctx
.numBuf
== 1)
3433 lpfc_bsg_mbox_ext_session_reset(phba
);
3435 /* free base driver mailbox structure memory */
3436 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3438 /* complete the bsg job if we have it */
3446 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3447 * @phba: Pointer to HBA context object.
3448 * @pmboxq: Pointer to mailbox command.
3450 * This is completion handler function for mailbox write commands with multiple
3454 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3456 struct fc_bsg_job
*job
;
3458 /* handle the BSG job with the mailbox command */
3459 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3460 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3462 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3463 "2940 SLI_CONFIG ext-buffer wr maibox command "
3464 "complete, ctxState:x%x, mbxStatus:x%x\n",
3465 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3467 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3469 /* free all memory, including dma buffers */
3470 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3471 lpfc_bsg_mbox_ext_session_reset(phba
);
3473 /* complete the bsg job if we have it */
3481 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba
*phba
, enum nemb_type nemb_tp
,
3482 uint32_t index
, struct lpfc_dmabuf
*mbx_dmabuf
,
3483 struct lpfc_dmabuf
*ext_dmabuf
)
3485 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3487 /* pointer to the start of mailbox command */
3488 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)mbx_dmabuf
->virt
;
3490 if (nemb_tp
== nemb_mse
) {
3492 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3494 putPaddrHigh(mbx_dmabuf
->phys
+
3496 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3498 putPaddrLow(mbx_dmabuf
->phys
+
3500 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3501 "2943 SLI_CONFIG(mse)[%d], "
3502 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3504 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3506 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3508 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3511 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3513 putPaddrHigh(ext_dmabuf
->phys
);
3514 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3516 putPaddrLow(ext_dmabuf
->phys
);
3517 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3518 "2944 SLI_CONFIG(mse)[%d], "
3519 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3521 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3523 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3525 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3530 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3532 putPaddrHigh(mbx_dmabuf
->phys
+
3534 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3536 putPaddrLow(mbx_dmabuf
->phys
+
3538 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3539 "3007 SLI_CONFIG(hbd)[%d], "
3540 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3542 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3544 sli_config_emb1_subsys
.hbd
[index
]),
3545 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3547 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3551 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3553 putPaddrHigh(ext_dmabuf
->phys
);
3554 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3556 putPaddrLow(ext_dmabuf
->phys
);
3557 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3558 "3008 SLI_CONFIG(hbd)[%d], "
3559 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3561 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3563 sli_config_emb1_subsys
.hbd
[index
]),
3564 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3566 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3574 * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
3575 * @phba: Pointer to HBA context object.
3576 * @mb: Pointer to a BSG mailbox object.
3577 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3578 * @dmabuff: Pointer to a DMA buffer descriptor.
3580 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3581 * non-embedded external bufffers.
3584 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3585 enum nemb_type nemb_tp
,
3586 struct lpfc_dmabuf
*dmabuf
)
3588 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3589 struct dfc_mbox_req
*mbox_req
;
3590 struct lpfc_dmabuf
*curr_dmabuf
, *next_dmabuf
;
3591 uint32_t ext_buf_cnt
, ext_buf_index
;
3592 struct lpfc_dmabuf
*ext_dmabuf
= NULL
;
3593 struct bsg_job_data
*dd_data
= NULL
;
3594 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3600 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3602 /* pointer to the start of mailbox command */
3603 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3605 if (nemb_tp
== nemb_mse
) {
3606 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3607 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3608 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3609 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3610 "2945 Handled SLI_CONFIG(mse) rd, "
3611 "ext_buf_cnt(%d) out of range(%d)\n",
3613 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3617 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3618 "2941 Handled SLI_CONFIG(mse) rd, "
3619 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3621 /* sanity check on interface type for support */
3622 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3623 LPFC_SLI_INTF_IF_TYPE_2
) {
3627 /* nemb_tp == nemb_hbd */
3628 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3629 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3630 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3631 "2946 Handled SLI_CONFIG(hbd) rd, "
3632 "ext_buf_cnt(%d) out of range(%d)\n",
3634 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3638 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3639 "2942 Handled SLI_CONFIG(hbd) rd, "
3640 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3643 /* before dma descriptor setup */
3644 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3645 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3647 /* reject non-embedded mailbox command with none external buffer */
3648 if (ext_buf_cnt
== 0) {
3651 } else if (ext_buf_cnt
> 1) {
3652 /* additional external read buffers */
3653 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3654 ext_dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
3659 list_add_tail(&ext_dmabuf
->list
,
3660 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3664 /* bsg tracking structure */
3665 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3671 /* mailbox command structure for base driver */
3672 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3677 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3679 /* for the first external buffer */
3680 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3682 /* for the rest of external buffer descriptors if any */
3683 if (ext_buf_cnt
> 1) {
3685 list_for_each_entry_safe(curr_dmabuf
, next_dmabuf
,
3686 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
, list
) {
3687 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
,
3688 ext_buf_index
, dmabuf
,
3694 /* after dma descriptor setup */
3695 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3696 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3698 /* construct base driver mbox command */
3699 pmb
= &pmboxq
->u
.mb
;
3700 pmbx
= (uint8_t *)dmabuf
->virt
;
3701 memcpy(pmb
, pmbx
, sizeof(*pmb
));
3702 pmb
->mbxOwner
= OWN_HOST
;
3703 pmboxq
->vport
= phba
->pport
;
3705 /* multi-buffer handling context */
3706 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3707 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_rd
;
3708 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3709 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3710 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3711 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3713 /* callback for multi-buffer read mailbox command */
3714 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_read_mbox_ext_cmpl
;
3716 /* context fields to callback function */
3717 pmboxq
->context1
= dd_data
;
3718 dd_data
->type
= TYPE_MBOX
;
3719 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3720 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
3721 dd_data
->context_un
.mbox
.set_job
= job
;
3722 job
->dd_data
= dd_data
;
3725 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3728 * Non-embedded mailbox subcommand data gets byte swapped here because
3729 * the lower level driver code only does the first 64 mailbox words.
3731 if ((!bsg_bf_get(lpfc_mbox_hdr_emb
,
3732 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) &&
3733 (nemb_tp
== nemb_mse
))
3734 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3735 &pmbx
[sizeof(MAILBOX_t
)],
3736 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3739 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3740 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3741 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3742 "2947 Issued SLI_CONFIG ext-buffer "
3743 "maibox command, rc:x%x\n", rc
);
3744 return SLI_CONFIG_HANDLED
;
3746 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3747 "2948 Failed to issue SLI_CONFIG ext-buffer "
3748 "maibox command, rc:x%x\n", rc
);
3753 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3754 lpfc_bsg_dma_page_list_free(phba
,
3755 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3757 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
3762 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
3763 * @phba: Pointer to HBA context object.
3764 * @mb: Pointer to a BSG mailbox object.
3765 * @dmabuff: Pointer to a DMA buffer descriptor.
3767 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
3768 * non-embedded external bufffers.
3771 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3772 enum nemb_type nemb_tp
,
3773 struct lpfc_dmabuf
*dmabuf
)
3775 struct dfc_mbox_req
*mbox_req
;
3776 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3777 uint32_t ext_buf_cnt
;
3778 struct bsg_job_data
*dd_data
= NULL
;
3779 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3782 int rc
= SLI_CONFIG_NOT_HANDLED
, i
;
3785 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3787 /* pointer to the start of mailbox command */
3788 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3790 if (nemb_tp
== nemb_mse
) {
3791 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3792 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3793 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3794 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3795 "2953 Failed SLI_CONFIG(mse) wr, "
3796 "ext_buf_cnt(%d) out of range(%d)\n",
3798 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3801 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3802 "2949 Handled SLI_CONFIG(mse) wr, "
3803 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3805 /* sanity check on interface type for support */
3806 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3807 LPFC_SLI_INTF_IF_TYPE_2
)
3809 /* nemb_tp == nemb_hbd */
3810 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3811 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3812 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3813 "2954 Failed SLI_CONFIG(hbd) wr, "
3814 "ext_buf_cnt(%d) out of range(%d)\n",
3816 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3819 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3820 "2950 Handled SLI_CONFIG(hbd) wr, "
3821 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3824 /* before dma buffer descriptor setup */
3825 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3826 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3828 if (ext_buf_cnt
== 0)
3831 /* for the first external buffer */
3832 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3834 /* after dma descriptor setup */
3835 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3836 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3838 /* log for looking forward */
3839 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3840 if (nemb_tp
== nemb_mse
)
3841 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3842 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
3843 i
, sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3846 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3847 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
3848 i
, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3849 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3853 /* multi-buffer handling context */
3854 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3855 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_wr
;
3856 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3857 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3858 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3859 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3861 if (ext_buf_cnt
== 1) {
3862 /* bsg tracking structure */
3863 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3869 /* mailbox command structure for base driver */
3870 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3875 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3876 pmb
= &pmboxq
->u
.mb
;
3877 mbx
= (uint8_t *)dmabuf
->virt
;
3878 memcpy(pmb
, mbx
, sizeof(*pmb
));
3879 pmb
->mbxOwner
= OWN_HOST
;
3880 pmboxq
->vport
= phba
->pport
;
3882 /* callback for multi-buffer read mailbox command */
3883 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
3885 /* context fields to callback function */
3886 pmboxq
->context1
= dd_data
;
3887 dd_data
->type
= TYPE_MBOX
;
3888 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3889 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)mbx
;
3890 dd_data
->context_un
.mbox
.set_job
= job
;
3891 job
->dd_data
= dd_data
;
3894 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3896 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3897 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3898 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3899 "2955 Issued SLI_CONFIG ext-buffer "
3900 "maibox command, rc:x%x\n", rc
);
3901 return SLI_CONFIG_HANDLED
;
3903 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3904 "2956 Failed to issue SLI_CONFIG ext-buffer "
3905 "maibox command, rc:x%x\n", rc
);
3910 /* wait for additoinal external buffers */
3911 job
->reply
->result
= 0;
3913 return SLI_CONFIG_HANDLED
;
3917 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3924 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
3925 * @phba: Pointer to HBA context object.
3926 * @mb: Pointer to a BSG mailbox object.
3927 * @dmabuff: Pointer to a DMA buffer descriptor.
3929 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
3930 * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
3931 * with embedded sussystem 0x1 and opcodes with external HBDs.
3934 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3935 struct lpfc_dmabuf
*dmabuf
)
3937 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3940 int rc
= SLI_CONFIG_NOT_HANDLED
;
3942 /* state change on new multi-buffer pass-through mailbox command */
3943 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_HOST
;
3945 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3947 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3948 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3949 subsys
= bsg_bf_get(lpfc_emb0_subcmnd_subsys
,
3950 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3951 opcode
= bsg_bf_get(lpfc_emb0_subcmnd_opcode
,
3952 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3953 if (subsys
== SLI_CONFIG_SUBSYS_FCOE
) {
3955 case FCOE_OPCODE_READ_FCF
:
3956 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3957 "2957 Handled SLI_CONFIG "
3958 "subsys_fcoe, opcode:x%x\n",
3960 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3963 case FCOE_OPCODE_ADD_FCF
:
3964 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3965 "2958 Handled SLI_CONFIG "
3966 "subsys_fcoe, opcode:x%x\n",
3968 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
3972 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3973 "2959 Reject SLI_CONFIG "
3974 "subsys_fcoe, opcode:x%x\n",
3979 } else if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
3981 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES
:
3982 case COMN_OPCODE_GET_CNTL_ATTRIBUTES
:
3983 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3984 "3106 Handled SLI_CONFIG "
3985 "subsys_comn, opcode:x%x\n",
3987 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3991 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3992 "3107 Reject SLI_CONFIG "
3993 "subsys_comn, opcode:x%x\n",
3999 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4000 "2977 Reject SLI_CONFIG "
4001 "subsys:x%d, opcode:x%x\n",
4006 subsys
= bsg_bf_get(lpfc_emb1_subcmnd_subsys
,
4007 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4008 opcode
= bsg_bf_get(lpfc_emb1_subcmnd_opcode
,
4009 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4010 if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
4012 case COMN_OPCODE_READ_OBJECT
:
4013 case COMN_OPCODE_READ_OBJECT_LIST
:
4014 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4015 "2960 Handled SLI_CONFIG "
4016 "subsys_comn, opcode:x%x\n",
4018 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4021 case COMN_OPCODE_WRITE_OBJECT
:
4022 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4023 "2961 Handled SLI_CONFIG "
4024 "subsys_comn, opcode:x%x\n",
4026 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
4030 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4031 "2962 Not handled SLI_CONFIG "
4032 "subsys_comn, opcode:x%x\n",
4034 rc
= SLI_CONFIG_NOT_HANDLED
;
4038 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4039 "2978 Not handled SLI_CONFIG "
4040 "subsys:x%d, opcode:x%x\n",
4042 rc
= SLI_CONFIG_NOT_HANDLED
;
4046 /* state reset on not handled new multi-buffer mailbox command */
4047 if (rc
!= SLI_CONFIG_HANDLED
)
4048 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
4054 * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
4055 * @phba: Pointer to HBA context object.
4057 * This routine is for requesting to abort a pass-through mailbox command with
4058 * multiple external buffers due to error condition.
4061 lpfc_bsg_mbox_ext_abort(struct lpfc_hba
*phba
)
4063 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
4064 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
4066 lpfc_bsg_mbox_ext_session_reset(phba
);
4071 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
4072 * @phba: Pointer to HBA context object.
4073 * @dmabuf: Pointer to a DMA buffer descriptor.
4075 * This routine extracts the next mailbox read external buffer back to
4076 * user space through BSG.
4079 lpfc_bsg_read_ebuf_get(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
4081 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4082 struct lpfc_dmabuf
*dmabuf
;
4087 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4088 phba
->mbox_ext_buf_ctx
.seqNum
++;
4090 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4091 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4093 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4094 size
= bsg_bf_get(lpfc_mbox_sli_config_mse_len
,
4095 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[index
]);
4096 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4097 "2963 SLI_CONFIG (mse) ext-buffer rd get "
4098 "buffer[%d], size:%d\n", index
, size
);
4100 size
= bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
4101 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd
[index
]);
4102 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4103 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
4104 "buffer[%d], size:%d\n", index
, size
);
4106 if (list_empty(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
))
4108 dmabuf
= list_first_entry(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
,
4109 struct lpfc_dmabuf
, list
);
4110 list_del_init(&dmabuf
->list
);
4112 /* after dma buffer descriptor setup */
4113 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4114 mbox_rd
, dma_ebuf
, sta_pos_addr
,
4117 pbuf
= (uint8_t *)dmabuf
->virt
;
4118 job
->reply
->reply_payload_rcv_len
=
4119 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4120 job
->reply_payload
.sg_cnt
,
4123 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4125 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4126 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4127 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
4128 "command session done\n");
4129 lpfc_bsg_mbox_ext_session_reset(phba
);
4132 job
->reply
->result
= 0;
4135 return SLI_CONFIG_HANDLED
;
4139 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
4140 * @phba: Pointer to HBA context object.
4141 * @dmabuf: Pointer to a DMA buffer descriptor.
4143 * This routine sets up the next mailbox read external buffer obtained
4144 * from user space through BSG.
4147 lpfc_bsg_write_ebuf_set(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4148 struct lpfc_dmabuf
*dmabuf
)
4150 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4151 struct bsg_job_data
*dd_data
= NULL
;
4152 LPFC_MBOXQ_t
*pmboxq
= NULL
;
4154 enum nemb_type nemb_tp
;
4160 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4161 phba
->mbox_ext_buf_ctx
.seqNum
++;
4162 nemb_tp
= phba
->mbox_ext_buf_ctx
.nembType
;
4164 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4165 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4167 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4173 pbuf
= (uint8_t *)dmabuf
->virt
;
4174 size
= job
->request_payload
.payload_len
;
4175 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4176 job
->request_payload
.sg_cnt
,
4179 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4180 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4181 "2966 SLI_CONFIG (mse) ext-buffer wr set "
4182 "buffer[%d], size:%d\n",
4183 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4186 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4187 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
4188 "buffer[%d], size:%d\n",
4189 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4193 /* set up external buffer descriptor and add to external buffer list */
4194 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, index
,
4195 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
,
4197 list_add_tail(&dmabuf
->list
, &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4199 /* after write dma buffer */
4200 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4201 mbox_wr
, dma_ebuf
, sta_pos_addr
,
4204 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4205 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4206 "2968 SLI_CONFIG ext-buffer wr all %d "
4207 "ebuffers received\n",
4208 phba
->mbox_ext_buf_ctx
.numBuf
);
4209 /* mailbox command structure for base driver */
4210 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4215 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4216 pbuf
= (uint8_t *)phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4217 pmb
= &pmboxq
->u
.mb
;
4218 memcpy(pmb
, pbuf
, sizeof(*pmb
));
4219 pmb
->mbxOwner
= OWN_HOST
;
4220 pmboxq
->vport
= phba
->pport
;
4222 /* callback for multi-buffer write mailbox command */
4223 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
4225 /* context fields to callback function */
4226 pmboxq
->context1
= dd_data
;
4227 dd_data
->type
= TYPE_MBOX
;
4228 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4229 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pbuf
;
4230 dd_data
->context_un
.mbox
.set_job
= job
;
4231 job
->dd_data
= dd_data
;
4234 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4236 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4237 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4238 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4239 "2969 Issued SLI_CONFIG ext-buffer "
4240 "maibox command, rc:x%x\n", rc
);
4241 return SLI_CONFIG_HANDLED
;
4243 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4244 "2970 Failed to issue SLI_CONFIG ext-buffer "
4245 "maibox command, rc:x%x\n", rc
);
4250 /* wait for additoinal external buffers */
4251 job
->reply
->result
= 0;
4253 return SLI_CONFIG_HANDLED
;
4256 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4263 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4264 * @phba: Pointer to HBA context object.
4265 * @mb: Pointer to a BSG mailbox object.
4266 * @dmabuff: Pointer to a DMA buffer descriptor.
4268 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4269 * command with multiple non-embedded external buffers.
4272 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4273 struct lpfc_dmabuf
*dmabuf
)
4277 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4278 "2971 SLI_CONFIG buffer (type:x%x)\n",
4279 phba
->mbox_ext_buf_ctx
.mboxType
);
4281 if (phba
->mbox_ext_buf_ctx
.mboxType
== mbox_rd
) {
4282 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_DONE
) {
4283 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4284 "2972 SLI_CONFIG rd buffer state "
4286 phba
->mbox_ext_buf_ctx
.state
);
4287 lpfc_bsg_mbox_ext_abort(phba
);
4290 rc
= lpfc_bsg_read_ebuf_get(phba
, job
);
4291 if (rc
== SLI_CONFIG_HANDLED
)
4292 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4293 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4294 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_HOST
) {
4295 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4296 "2973 SLI_CONFIG wr buffer state "
4298 phba
->mbox_ext_buf_ctx
.state
);
4299 lpfc_bsg_mbox_ext_abort(phba
);
4302 rc
= lpfc_bsg_write_ebuf_set(phba
, job
, dmabuf
);
4308 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4309 * @phba: Pointer to HBA context object.
4310 * @mb: Pointer to a BSG mailbox object.
4311 * @dmabuff: Pointer to a DMA buffer descriptor.
4313 * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
4314 * (0x9B) mailbox commands and external buffers.
4317 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4318 struct lpfc_dmabuf
*dmabuf
)
4320 struct dfc_mbox_req
*mbox_req
;
4321 int rc
= SLI_CONFIG_NOT_HANDLED
;
4324 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4326 /* mbox command with/without single external buffer */
4327 if (mbox_req
->extMboxTag
== 0 && mbox_req
->extSeqNum
== 0)
4330 /* mbox command and first external buffer */
4331 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
) {
4332 if (mbox_req
->extSeqNum
== 1) {
4333 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4334 "2974 SLI_CONFIG mailbox: tag:%d, "
4335 "seq:%d\n", mbox_req
->extMboxTag
,
4336 mbox_req
->extSeqNum
);
4337 rc
= lpfc_bsg_handle_sli_cfg_mbox(phba
, job
, dmabuf
);
4340 goto sli_cfg_ext_error
;
4344 * handle additional external buffers
4347 /* check broken pipe conditions */
4348 if (mbox_req
->extMboxTag
!= phba
->mbox_ext_buf_ctx
.mbxTag
)
4349 goto sli_cfg_ext_error
;
4350 if (mbox_req
->extSeqNum
> phba
->mbox_ext_buf_ctx
.numBuf
)
4351 goto sli_cfg_ext_error
;
4352 if (mbox_req
->extSeqNum
!= phba
->mbox_ext_buf_ctx
.seqNum
+ 1)
4353 goto sli_cfg_ext_error
;
4355 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4356 "2975 SLI_CONFIG mailbox external buffer: "
4357 "extSta:x%x, tag:%d, seq:%d\n",
4358 phba
->mbox_ext_buf_ctx
.state
, mbox_req
->extMboxTag
,
4359 mbox_req
->extSeqNum
);
4360 rc
= lpfc_bsg_handle_sli_cfg_ebuf(phba
, job
, dmabuf
);
4364 /* all other cases, broken pipe */
4365 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4366 "2976 SLI_CONFIG mailbox broken pipe: "
4367 "ctxSta:x%x, ctxNumBuf:%d "
4368 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4369 phba
->mbox_ext_buf_ctx
.state
,
4370 phba
->mbox_ext_buf_ctx
.numBuf
,
4371 phba
->mbox_ext_buf_ctx
.mbxTag
,
4372 phba
->mbox_ext_buf_ctx
.seqNum
,
4373 mbox_req
->extMboxTag
, mbox_req
->extSeqNum
);
4375 lpfc_bsg_mbox_ext_session_reset(phba
);
4381 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4382 * @phba: Pointer to HBA context object.
4383 * @mb: Pointer to a mailbox object.
4384 * @vport: Pointer to a vport object.
4386 * Allocate a tracking object, mailbox command memory, get a mailbox
4387 * from the mailbox pool, copy the caller mailbox command.
4389 * If offline and the sli is active we need to poll for the command (port is
4390 * being reset) and com-plete the job, otherwise issue the mailbox command and
4391 * let our completion handler finish the command.
4394 lpfc_bsg_issue_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4395 struct lpfc_vport
*vport
)
4397 LPFC_MBOXQ_t
*pmboxq
= NULL
; /* internal mailbox queue */
4398 MAILBOX_t
*pmb
; /* shortcut to the pmboxq mailbox */
4399 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4400 uint8_t *pmbx
= NULL
;
4401 struct bsg_job_data
*dd_data
= NULL
; /* bsg data tracking structure */
4402 struct lpfc_dmabuf
*dmabuf
= NULL
;
4403 struct dfc_mbox_req
*mbox_req
;
4404 struct READ_EVENT_LOG_VAR
*rdEventLog
;
4405 uint32_t transmit_length
, receive_length
, mode
;
4406 struct lpfc_mbx_sli4_config
*sli4_config
;
4407 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
4408 struct mbox_header
*header
;
4409 struct ulp_bde64
*bde
;
4410 uint8_t *ext
= NULL
;
4416 /* in case no data is transferred */
4417 job
->reply
->reply_payload_rcv_len
= 0;
4419 /* sanity check to protect driver */
4420 if (job
->reply_payload
.payload_len
> BSG_MBOX_SIZE
||
4421 job
->request_payload
.payload_len
> BSG_MBOX_SIZE
) {
4427 * Don't allow mailbox commands to be sent when blocked or when in
4428 * the middle of discovery
4430 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4436 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4438 /* check if requested extended data lengths are valid */
4439 if ((mbox_req
->inExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t)) ||
4440 (mbox_req
->outExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t))) {
4445 dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
4446 if (!dmabuf
|| !dmabuf
->virt
) {
4451 /* Get the mailbox command or external buffer from BSG */
4452 pmbx
= (uint8_t *)dmabuf
->virt
;
4453 size
= job
->request_payload
.payload_len
;
4454 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4455 job
->request_payload
.sg_cnt
, pmbx
, size
);
4457 /* Handle possible SLI_CONFIG with non-embedded payloads */
4458 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4459 rc
= lpfc_bsg_handle_sli_cfg_ext(phba
, job
, dmabuf
);
4460 if (rc
== SLI_CONFIG_HANDLED
)
4464 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4467 rc
= lpfc_bsg_check_cmd_access(phba
, (MAILBOX_t
*)pmbx
, vport
);
4469 goto job_done
; /* must be negative */
4471 /* allocate our bsg tracking structure */
4472 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4474 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4475 "2727 Failed allocation of dd_data\n");
4480 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4485 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4487 pmb
= &pmboxq
->u
.mb
;
4488 memcpy(pmb
, pmbx
, sizeof(*pmb
));
4489 pmb
->mbxOwner
= OWN_HOST
;
4490 pmboxq
->vport
= vport
;
4492 /* If HBA encountered an error attention, allow only DUMP
4493 * or RESTART mailbox commands until the HBA is restarted.
4495 if (phba
->pport
->stopped
&&
4496 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4497 pmb
->mbxCommand
!= MBX_RESTART
&&
4498 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4499 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4500 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4501 "2797 mbox: Issued mailbox cmd "
4502 "0x%x while in stopped state.\n",
4505 /* extended mailbox commands will need an extended buffer */
4506 if (mbox_req
->inExtWLen
|| mbox_req
->outExtWLen
) {
4508 ext
= from
+ sizeof(MAILBOX_t
);
4509 pmboxq
->context2
= ext
;
4510 pmboxq
->in_ext_byte_len
=
4511 mbox_req
->inExtWLen
* sizeof(uint32_t);
4512 pmboxq
->out_ext_byte_len
=
4513 mbox_req
->outExtWLen
* sizeof(uint32_t);
4514 pmboxq
->mbox_offset_word
= mbox_req
->mbOffset
;
4517 /* biu diag will need a kernel buffer to transfer the data
4518 * allocate our own buffer and setup the mailbox command to
4521 if (pmb
->mbxCommand
== MBX_RUN_BIU_DIAG64
) {
4522 transmit_length
= pmb
->un
.varWords
[1];
4523 receive_length
= pmb
->un
.varWords
[4];
4524 /* transmit length cannot be greater than receive length or
4525 * mailbox extension size
4527 if ((transmit_length
> receive_length
) ||
4528 (transmit_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4532 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrHigh
=
4533 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4534 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrLow
=
4535 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4537 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrHigh
=
4538 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4539 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4540 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrLow
=
4541 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4542 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4543 } else if (pmb
->mbxCommand
== MBX_READ_EVENT_LOG
) {
4544 rdEventLog
= &pmb
->un
.varRdEventLog
;
4545 receive_length
= rdEventLog
->rcv_bde64
.tus
.f
.bdeSize
;
4546 mode
= bf_get(lpfc_event_log
, rdEventLog
);
4548 /* receive length cannot be greater than mailbox
4551 if (receive_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4556 /* mode zero uses a bde like biu diags command */
4558 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4559 + sizeof(MAILBOX_t
));
4560 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4561 + sizeof(MAILBOX_t
));
4563 } else if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4564 /* Let type 4 (well known data) through because the data is
4565 * returned in varwords[4-8]
4566 * otherwise check the recieve length and fetch the buffer addr
4568 if ((pmb
->mbxCommand
== MBX_DUMP_MEMORY
) &&
4569 (pmb
->un
.varDmp
.type
!= DMP_WELL_KNOWN
)) {
4570 /* rebuild the command for sli4 using our own buffers
4571 * like we do for biu diags
4573 receive_length
= pmb
->un
.varWords
[2];
4574 /* receive length cannot be greater than mailbox
4577 if (receive_length
== 0) {
4581 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4582 + sizeof(MAILBOX_t
));
4583 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4584 + sizeof(MAILBOX_t
));
4585 } else if ((pmb
->mbxCommand
== MBX_UPDATE_CFG
) &&
4586 pmb
->un
.varUpdateCfg
.co
) {
4587 bde
= (struct ulp_bde64
*)&pmb
->un
.varWords
[4];
4589 /* bde size cannot be greater than mailbox ext size */
4590 if (bde
->tus
.f
.bdeSize
>
4591 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4595 bde
->addrHigh
= putPaddrHigh(dmabuf
->phys
4596 + sizeof(MAILBOX_t
));
4597 bde
->addrLow
= putPaddrLow(dmabuf
->phys
4598 + sizeof(MAILBOX_t
));
4599 } else if (pmb
->mbxCommand
== MBX_SLI4_CONFIG
) {
4600 /* Handling non-embedded SLI_CONFIG mailbox command */
4601 sli4_config
= &pmboxq
->u
.mqe
.un
.sli4_config
;
4602 if (!bf_get(lpfc_mbox_hdr_emb
,
4603 &sli4_config
->header
.cfg_mhdr
)) {
4604 /* rebuild the command for sli4 using our
4605 * own buffers like we do for biu diags
4607 header
= (struct mbox_header
*)
4608 &pmb
->un
.varWords
[0];
4609 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
4610 &pmb
->un
.varWords
[0];
4611 receive_length
= nembed_sge
->sge
[0].length
;
4613 /* receive length cannot be greater than
4614 * mailbox extension size
4616 if ((receive_length
== 0) ||
4618 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4623 nembed_sge
->sge
[0].pa_hi
=
4624 putPaddrHigh(dmabuf
->phys
4625 + sizeof(MAILBOX_t
));
4626 nembed_sge
->sge
[0].pa_lo
=
4627 putPaddrLow(dmabuf
->phys
4628 + sizeof(MAILBOX_t
));
4633 dd_data
->context_un
.mbox
.dmabuffers
= dmabuf
;
4635 /* setup wake call as IOCB callback */
4636 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_mbox_cmpl
;
4638 /* setup context field to pass wait_queue pointer to wake function */
4639 pmboxq
->context1
= dd_data
;
4640 dd_data
->type
= TYPE_MBOX
;
4641 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4642 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
4643 dd_data
->context_un
.mbox
.set_job
= job
;
4644 dd_data
->context_un
.mbox
.ext
= ext
;
4645 dd_data
->context_un
.mbox
.mbOffset
= mbox_req
->mbOffset
;
4646 dd_data
->context_un
.mbox
.inExtWLen
= mbox_req
->inExtWLen
;
4647 dd_data
->context_un
.mbox
.outExtWLen
= mbox_req
->outExtWLen
;
4648 job
->dd_data
= dd_data
;
4650 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4651 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4652 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4653 if (rc
!= MBX_SUCCESS
) {
4654 rc
= (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4658 /* job finished, copy the data */
4659 memcpy(pmbx
, pmb
, sizeof(*pmb
));
4660 job
->reply
->reply_payload_rcv_len
=
4661 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4662 job
->reply_payload
.sg_cnt
,
4664 /* not waiting mbox already done */
4669 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4670 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
))
4671 return 1; /* job started */
4674 /* common exit for error or job completed inline */
4676 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4677 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4685 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
4686 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
4689 lpfc_bsg_mbox_cmd(struct fc_bsg_job
*job
)
4691 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4692 struct lpfc_hba
*phba
= vport
->phba
;
4693 struct dfc_mbox_req
*mbox_req
;
4696 /* mix-and-match backward compatibility */
4697 job
->reply
->reply_payload_rcv_len
= 0;
4698 if (job
->request_len
<
4699 sizeof(struct fc_bsg_request
) + sizeof(struct dfc_mbox_req
)) {
4700 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4701 "2737 Mix-and-match backward compability "
4702 "between MBOX_REQ old size:%d and "
4703 "new request size:%d\n",
4704 (int)(job
->request_len
-
4705 sizeof(struct fc_bsg_request
)),
4706 (int)sizeof(struct dfc_mbox_req
));
4707 mbox_req
= (struct dfc_mbox_req
*)
4708 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4709 mbox_req
->extMboxTag
= 0;
4710 mbox_req
->extSeqNum
= 0;
4713 rc
= lpfc_bsg_issue_mbox(phba
, job
, vport
);
4717 job
->reply
->result
= 0;
4718 job
->dd_data
= NULL
;
4721 /* job submitted, will complete later*/
4722 rc
= 0; /* return zero, no error */
4724 /* some error occurred */
4725 job
->reply
->result
= rc
;
4726 job
->dd_data
= NULL
;
4733 * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
4734 * @phba: Pointer to HBA context object.
4735 * @cmdiocbq: Pointer to command iocb.
4736 * @rspiocbq: Pointer to response iocb.
4738 * This function is the completion handler for iocbs issued using
4739 * lpfc_menlo_cmd function. This function is called by the
4740 * ring event handler function without any lock held. This function
4741 * can be called from both worker thread context and interrupt
4742 * context. This function also can be called from another thread which
4743 * cleans up the SLI layer objects.
4744 * This function copies the contents of the response iocb to the
4745 * response iocb memory object provided by the caller of
4746 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4747 * sleeps for the iocb completion.
4750 lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba
*phba
,
4751 struct lpfc_iocbq
*cmdiocbq
,
4752 struct lpfc_iocbq
*rspiocbq
)
4754 struct bsg_job_data
*dd_data
;
4755 struct fc_bsg_job
*job
;
4757 struct lpfc_dmabuf
*bmp
;
4758 struct lpfc_bsg_menlo
*menlo
;
4759 unsigned long flags
;
4760 struct menlo_response
*menlo_resp
;
4763 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
4764 dd_data
= cmdiocbq
->context1
;
4766 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4770 menlo
= &dd_data
->context_un
.menlo
;
4771 job
= menlo
->set_job
;
4772 job
->dd_data
= NULL
; /* so timeout handler does not reply */
4774 spin_lock(&phba
->hbalock
);
4775 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
4776 if (cmdiocbq
->context2
&& rspiocbq
)
4777 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
4778 &rspiocbq
->iocb
, sizeof(IOCB_t
));
4779 spin_unlock(&phba
->hbalock
);
4782 rspiocbq
= menlo
->rspiocbq
;
4783 rsp
= &rspiocbq
->iocb
;
4785 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4786 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4787 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4788 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4790 /* always return the xri, this would be used in the case
4791 * of a menlo download to allow the data to be sent as a continuation
4794 menlo_resp
= (struct menlo_response
*)
4795 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4796 menlo_resp
->xri
= rsp
->ulpContext
;
4797 if (rsp
->ulpStatus
) {
4798 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
4799 switch (rsp
->un
.ulpWord
[4] & 0xff) {
4800 case IOERR_SEQUENCE_TIMEOUT
:
4803 case IOERR_INVALID_RPI
:
4813 job
->reply
->reply_payload_rcv_len
=
4814 rsp
->un
.genreq64
.bdl
.bdeSize
;
4816 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
4817 lpfc_sli_release_iocbq(phba
, rspiocbq
);
4818 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
4821 /* make error code available to userspace */
4822 job
->reply
->result
= rc
;
4823 /* complete the job back to userspace */
4825 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4830 * lpfc_menlo_cmd - send an ioctl for menlo hardware
4831 * @job: fc_bsg_job to handle
4833 * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
4834 * all the command completions will return the xri for the command.
4835 * For menlo data requests a gen request 64 CX is used to continue the exchange
4836 * supplied in the menlo request header xri field.
4839 lpfc_menlo_cmd(struct fc_bsg_job
*job
)
4841 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4842 struct lpfc_hba
*phba
= vport
->phba
;
4843 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
4846 struct menlo_command
*menlo_cmd
;
4847 struct menlo_response
*menlo_resp
;
4848 struct lpfc_dmabuf
*bmp
= NULL
;
4851 struct scatterlist
*sgel
= NULL
;
4854 struct bsg_job_data
*dd_data
;
4855 struct ulp_bde64
*bpl
= NULL
;
4857 /* in case no data is returned return just the return code */
4858 job
->reply
->reply_payload_rcv_len
= 0;
4860 if (job
->request_len
<
4861 sizeof(struct fc_bsg_request
) +
4862 sizeof(struct menlo_command
)) {
4863 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4864 "2784 Received MENLO_CMD request below "
4870 if (job
->reply_len
<
4871 sizeof(struct fc_bsg_request
) + sizeof(struct menlo_response
)) {
4872 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4873 "2785 Received MENLO_CMD reply below "
4879 if (!(phba
->menlo_flag
& HBA_MENLO_SUPPORT
)) {
4880 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4881 "2786 Adapter does not support menlo "
4887 menlo_cmd
= (struct menlo_command
*)
4888 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4890 menlo_resp
= (struct menlo_response
*)
4891 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4893 /* allocate our bsg tracking structure */
4894 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4896 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4897 "2787 Failed allocation of dd_data\n");
4902 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4908 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
4914 rspiocbq
= lpfc_sli_get_iocbq(phba
);
4920 rsp
= &rspiocbq
->iocb
;
4922 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
4928 INIT_LIST_HEAD(&bmp
->list
);
4929 bpl
= (struct ulp_bde64
*) bmp
->virt
;
4930 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4931 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4932 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
4933 busaddr
= sg_dma_address(sgel
);
4934 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
4935 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4936 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4937 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4938 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4942 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4943 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4944 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
4945 busaddr
= sg_dma_address(sgel
);
4946 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
4947 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4948 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4949 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4950 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4954 cmd
= &cmdiocbq
->iocb
;
4955 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
4956 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
4957 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
4958 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
4959 cmd
->un
.genreq64
.bdl
.bdeSize
=
4960 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
4961 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
4962 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
4963 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CMD
;
4964 cmd
->un
.genreq64
.w5
.hcsw
.Type
= MENLO_TRANSPORT_TYPE
; /* 0xfe */
4965 cmd
->ulpBdeCount
= 1;
4966 cmd
->ulpClass
= CLASS3
;
4967 cmd
->ulpOwner
= OWN_CHIP
;
4968 cmd
->ulpLe
= 1; /* Limited Edition */
4969 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
4970 cmdiocbq
->vport
= phba
->pport
;
4971 /* We want the firmware to timeout before we do */
4972 cmd
->ulpTimeout
= MENLO_TIMEOUT
- 5;
4973 cmdiocbq
->context3
= bmp
;
4974 cmdiocbq
->context2
= rspiocbq
;
4975 cmdiocbq
->iocb_cmpl
= lpfc_bsg_menlo_cmd_cmp
;
4976 cmdiocbq
->context1
= dd_data
;
4977 cmdiocbq
->context2
= rspiocbq
;
4978 if (menlo_cmd
->cmd
== LPFC_BSG_VENDOR_MENLO_CMD
) {
4979 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
4980 cmd
->ulpPU
= MENLO_PU
; /* 3 */
4981 cmd
->un
.ulpWord
[4] = MENLO_DID
; /* 0x0000FC0E */
4982 cmd
->ulpContext
= MENLO_CONTEXT
; /* 0 */
4984 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CX
;
4986 cmd
->un
.ulpWord
[4] = 0;
4987 cmd
->ulpContext
= menlo_cmd
->xri
;
4990 dd_data
->type
= TYPE_MENLO
;
4991 dd_data
->context_un
.menlo
.cmdiocbq
= cmdiocbq
;
4992 dd_data
->context_un
.menlo
.rspiocbq
= rspiocbq
;
4993 dd_data
->context_un
.menlo
.set_job
= job
;
4994 dd_data
->context_un
.menlo
.bmp
= bmp
;
4996 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
4998 if (rc
== IOCB_SUCCESS
)
4999 return 0; /* done for now */
5001 /* iocb failed so cleanup */
5002 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
5003 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
5004 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
5005 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
5007 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
5010 lpfc_sli_release_iocbq(phba
, rspiocbq
);
5012 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
5018 /* make error code available to userspace */
5019 job
->reply
->result
= rc
;
5020 job
->dd_data
= NULL
;
5025 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
5026 * @job: fc_bsg_job to handle
5029 lpfc_bsg_hst_vendor(struct fc_bsg_job
*job
)
5031 int command
= job
->request
->rqst_data
.h_vendor
.vendor_cmd
[0];
5035 case LPFC_BSG_VENDOR_SET_CT_EVENT
:
5036 rc
= lpfc_bsg_hba_set_event(job
);
5038 case LPFC_BSG_VENDOR_GET_CT_EVENT
:
5039 rc
= lpfc_bsg_hba_get_event(job
);
5041 case LPFC_BSG_VENDOR_SEND_MGMT_RESP
:
5042 rc
= lpfc_bsg_send_mgmt_rsp(job
);
5044 case LPFC_BSG_VENDOR_DIAG_MODE
:
5045 rc
= lpfc_bsg_diag_loopback_mode(job
);
5047 case LPFC_BSG_VENDOR_DIAG_MODE_END
:
5048 rc
= lpfc_sli4_bsg_diag_mode_end(job
);
5050 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK
:
5051 rc
= lpfc_bsg_diag_loopback_run(job
);
5053 case LPFC_BSG_VENDOR_LINK_DIAG_TEST
:
5054 rc
= lpfc_sli4_bsg_link_diag_test(job
);
5056 case LPFC_BSG_VENDOR_GET_MGMT_REV
:
5057 rc
= lpfc_bsg_get_dfc_rev(job
);
5059 case LPFC_BSG_VENDOR_MBOX
:
5060 rc
= lpfc_bsg_mbox_cmd(job
);
5062 case LPFC_BSG_VENDOR_MENLO_CMD
:
5063 case LPFC_BSG_VENDOR_MENLO_DATA
:
5064 rc
= lpfc_menlo_cmd(job
);
5068 job
->reply
->reply_payload_rcv_len
= 0;
5069 /* make error code available to userspace */
5070 job
->reply
->result
= rc
;
5078 * lpfc_bsg_request - handle a bsg request from the FC transport
5079 * @job: fc_bsg_job to handle
5082 lpfc_bsg_request(struct fc_bsg_job
*job
)
5087 msgcode
= job
->request
->msgcode
;
5089 case FC_BSG_HST_VENDOR
:
5090 rc
= lpfc_bsg_hst_vendor(job
);
5092 case FC_BSG_RPT_ELS
:
5093 rc
= lpfc_bsg_rport_els(job
);
5096 rc
= lpfc_bsg_send_mgmt_cmd(job
);
5100 job
->reply
->reply_payload_rcv_len
= 0;
5101 /* make error code available to userspace */
5102 job
->reply
->result
= rc
;
5110 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
5111 * @job: fc_bsg_job that has timed out
5113 * This function just aborts the job's IOCB. The aborted IOCB will return to
5114 * the waiting function which will handle passing the error back to userspace
5117 lpfc_bsg_timeout(struct fc_bsg_job
*job
)
5119 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
5120 struct lpfc_hba
*phba
= vport
->phba
;
5121 struct lpfc_iocbq
*cmdiocb
;
5122 struct lpfc_bsg_event
*evt
;
5123 struct lpfc_bsg_iocb
*iocb
;
5124 struct lpfc_bsg_mbox
*mbox
;
5125 struct lpfc_bsg_menlo
*menlo
;
5126 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5127 struct bsg_job_data
*dd_data
;
5128 unsigned long flags
;
5130 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
5131 dd_data
= (struct bsg_job_data
*)job
->dd_data
;
5132 /* timeout and completion crossed paths if no dd_data */
5134 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5138 switch (dd_data
->type
) {
5140 iocb
= &dd_data
->context_un
.iocb
;
5141 cmdiocb
= iocb
->cmdiocbq
;
5142 /* hint to completion handler that the job timed out */
5143 job
->reply
->result
= -EAGAIN
;
5144 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5145 /* this will call our completion handler */
5146 spin_lock_irq(&phba
->hbalock
);
5147 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5148 spin_unlock_irq(&phba
->hbalock
);
5151 evt
= dd_data
->context_un
.evt
;
5152 /* this event has no job anymore */
5153 evt
->set_job
= NULL
;
5154 job
->dd_data
= NULL
;
5155 job
->reply
->reply_payload_rcv_len
= 0;
5156 /* Return -EAGAIN which is our way of signallying the
5159 job
->reply
->result
= -EAGAIN
;
5160 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5164 mbox
= &dd_data
->context_un
.mbox
;
5165 /* this mbox has no job anymore */
5166 mbox
->set_job
= NULL
;
5167 job
->dd_data
= NULL
;
5168 job
->reply
->reply_payload_rcv_len
= 0;
5169 job
->reply
->result
= -EAGAIN
;
5170 /* the mbox completion handler can now be run */
5171 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5173 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
5174 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
5177 menlo
= &dd_data
->context_un
.menlo
;
5178 cmdiocb
= menlo
->cmdiocbq
;
5179 /* hint to completion handler that the job timed out */
5180 job
->reply
->result
= -EAGAIN
;
5181 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5182 /* this will call our completion handler */
5183 spin_lock_irq(&phba
->hbalock
);
5184 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5185 spin_unlock_irq(&phba
->hbalock
);
5188 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5192 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
5193 * otherwise an error message will be displayed on the console
5194 * so always return success (zero)