1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
21 #include <linux/interrupt.h>
22 #include <linux/mempool.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
26 #include <linux/list.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
31 #include <scsi/scsi_bsg_fc.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_debugfs.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_version.h"
49 struct lpfc_bsg_event
{
50 struct list_head node
;
54 /* Event type and waiter identifiers */
59 /* next two flags are here for the auto-delete logic */
60 unsigned long wait_time_stamp
;
63 /* seen and not seen events */
64 struct list_head events_to_get
;
65 struct list_head events_to_see
;
67 /* job waiting for this event to finish */
68 struct fc_bsg_job
*set_job
;
71 struct lpfc_bsg_iocb
{
72 struct lpfc_iocbq
*cmdiocbq
;
73 struct lpfc_iocbq
*rspiocbq
;
74 struct lpfc_dmabuf
*bmp
;
75 struct lpfc_nodelist
*ndlp
;
77 /* job waiting for this iocb to finish */
78 struct fc_bsg_job
*set_job
;
81 struct lpfc_bsg_mbox
{
84 struct lpfc_dmabuf
*dmabuffers
; /* for BIU diags */
85 uint8_t *ext
; /* extended mailbox data */
86 uint32_t mbOffset
; /* from app */
87 uint32_t inExtWLen
; /* from app */
88 uint32_t outExtWLen
; /* from app */
90 /* job waiting for this mbox command to finish */
91 struct fc_bsg_job
*set_job
;
94 #define MENLO_DID 0x0000FC0E
96 struct lpfc_bsg_menlo
{
97 struct lpfc_iocbq
*cmdiocbq
;
98 struct lpfc_iocbq
*rspiocbq
;
99 struct lpfc_dmabuf
*bmp
;
101 /* job waiting for this iocb to finish */
102 struct fc_bsg_job
*set_job
;
109 struct bsg_job_data
{
112 struct lpfc_bsg_event
*evt
;
113 struct lpfc_bsg_iocb iocb
;
114 struct lpfc_bsg_mbox mbox
;
115 struct lpfc_bsg_menlo menlo
;
120 struct list_head node
;
127 #define BUF_SZ_4K 4096
128 #define SLI_CT_ELX_LOOPBACK 0x10
130 enum ELX_LOOPBACK_CMD
{
131 ELX_LOOPBACK_XRI_SETUP
,
135 #define ELX_LOOPBACK_HEADER_SZ \
136 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
138 struct lpfc_dmabufext
{
139 struct lpfc_dmabuf dma
;
145 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
146 * @phba: Pointer to HBA context object.
147 * @cmdiocbq: Pointer to command iocb.
148 * @rspiocbq: Pointer to response iocb.
150 * This function is the completion handler for iocbs issued using
151 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
152 * ring event handler function without any lock held. This function
153 * can be called from both worker thread context and interrupt
154 * context. This function also can be called from another thread which
155 * cleans up the SLI layer objects.
156 * This function copies the contents of the response iocb to the
157 * response iocb memory object provided by the caller of
158 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
159 * sleeps for the iocb completion.
162 lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba
*phba
,
163 struct lpfc_iocbq
*cmdiocbq
,
164 struct lpfc_iocbq
*rspiocbq
)
166 struct bsg_job_data
*dd_data
;
167 struct fc_bsg_job
*job
;
169 struct lpfc_dmabuf
*bmp
;
170 struct lpfc_nodelist
*ndlp
;
171 struct lpfc_bsg_iocb
*iocb
;
175 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
176 dd_data
= cmdiocbq
->context2
;
178 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
179 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
183 iocb
= &dd_data
->context_un
.iocb
;
185 job
->dd_data
= NULL
; /* so timeout handler does not reply */
188 rsp
= &rspiocbq
->iocb
;
189 ndlp
= cmdiocbq
->context1
;
191 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
192 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
193 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
194 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
196 if (rsp
->ulpStatus
) {
197 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
198 switch (rsp
->un
.ulpWord
[4] & 0xff) {
199 case IOERR_SEQUENCE_TIMEOUT
:
202 case IOERR_INVALID_RPI
:
212 job
->reply
->reply_payload_rcv_len
=
213 rsp
->un
.genreq64
.bdl
.bdeSize
;
215 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
216 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
220 /* make error code available to userspace */
221 job
->reply
->result
= rc
;
222 /* complete the job back to userspace */
224 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
229 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
230 * @job: fc_bsg_job to handle
233 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job
*job
)
235 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
236 struct lpfc_hba
*phba
= vport
->phba
;
237 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
238 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
239 struct ulp_bde64
*bpl
= NULL
;
241 struct lpfc_iocbq
*cmdiocbq
= NULL
;
243 struct lpfc_dmabuf
*bmp
= NULL
;
246 struct scatterlist
*sgel
= NULL
;
249 struct bsg_job_data
*dd_data
;
254 /* in case no data is transferred */
255 job
->reply
->reply_payload_rcv_len
= 0;
257 /* allocate our bsg tracking structure */
258 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
260 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
261 "2733 Failed allocation of dd_data\n");
266 if (!lpfc_nlp_get(ndlp
)) {
271 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
277 if (ndlp
->nlp_flag
& NLP_ELS_SND_MASK
) {
282 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
288 cmd
= &cmdiocbq
->iocb
;
289 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
295 INIT_LIST_HEAD(&bmp
->list
);
296 bpl
= (struct ulp_bde64
*) bmp
->virt
;
297 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
298 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
299 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
300 busaddr
= sg_dma_address(sgel
);
301 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
302 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
303 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
304 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
305 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
309 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
310 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
311 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
312 busaddr
= sg_dma_address(sgel
);
313 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
314 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
315 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
316 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
317 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
321 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
322 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
323 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
324 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
325 cmd
->un
.genreq64
.bdl
.bdeSize
=
326 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
327 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
328 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
329 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
330 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
331 cmd
->un
.genreq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
332 cmd
->ulpBdeCount
= 1;
334 cmd
->ulpClass
= CLASS3
;
335 cmd
->ulpContext
= ndlp
->nlp_rpi
;
336 if (phba
->sli_rev
== LPFC_SLI_REV4
)
337 cmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
338 cmd
->ulpOwner
= OWN_CHIP
;
339 cmdiocbq
->vport
= phba
->pport
;
340 cmdiocbq
->context3
= bmp
;
341 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
342 timeout
= phba
->fc_ratov
* 2;
343 cmd
->ulpTimeout
= timeout
;
345 cmdiocbq
->iocb_cmpl
= lpfc_bsg_send_mgmt_cmd_cmp
;
346 cmdiocbq
->context1
= ndlp
;
347 cmdiocbq
->context2
= dd_data
;
348 dd_data
->type
= TYPE_IOCB
;
349 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
350 dd_data
->context_un
.iocb
.set_job
= job
;
351 dd_data
->context_un
.iocb
.bmp
= bmp
;
353 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
354 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
358 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
359 writel(creg_val
, phba
->HCregaddr
);
360 readl(phba
->HCregaddr
); /* flush */
363 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
364 if (iocb_stat
== IOCB_SUCCESS
)
365 return 0; /* done for now */
366 else if (iocb_stat
== IOCB_BUSY
)
372 /* iocb failed so cleanup */
373 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
374 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
375 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
376 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
378 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
381 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
389 /* make error code available to userspace */
390 job
->reply
->result
= rc
;
396 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
397 * @phba: Pointer to HBA context object.
398 * @cmdiocbq: Pointer to command iocb.
399 * @rspiocbq: Pointer to response iocb.
401 * This function is the completion handler for iocbs issued using
402 * lpfc_bsg_rport_els_cmp function. This function is called by the
403 * ring event handler function without any lock held. This function
404 * can be called from both worker thread context and interrupt
405 * context. This function also can be called from other thread which
406 * cleans up the SLI layer objects.
407 * This function copies the contents of the response iocb to the
408 * response iocb memory object provided by the caller of
409 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
410 * sleeps for the iocb completion.
413 lpfc_bsg_rport_els_cmp(struct lpfc_hba
*phba
,
414 struct lpfc_iocbq
*cmdiocbq
,
415 struct lpfc_iocbq
*rspiocbq
)
417 struct bsg_job_data
*dd_data
;
418 struct fc_bsg_job
*job
;
420 struct lpfc_nodelist
*ndlp
;
421 struct lpfc_dmabuf
*pbuflist
= NULL
;
422 struct fc_bsg_ctels_reply
*els_reply
;
427 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
428 dd_data
= cmdiocbq
->context1
;
429 /* normal completion and timeout crossed paths, already done */
431 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
435 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
436 if (cmdiocbq
->context2
&& rspiocbq
)
437 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
438 &rspiocbq
->iocb
, sizeof(IOCB_t
));
440 job
= dd_data
->context_un
.iocb
.set_job
;
441 cmdiocbq
= dd_data
->context_un
.iocb
.cmdiocbq
;
442 rspiocbq
= dd_data
->context_un
.iocb
.rspiocbq
;
443 rsp
= &rspiocbq
->iocb
;
444 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
446 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
447 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
448 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
449 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
451 if (job
->reply
->result
== -EAGAIN
)
453 else if (rsp
->ulpStatus
== IOSTAT_SUCCESS
)
454 job
->reply
->reply_payload_rcv_len
=
455 rsp
->un
.elsreq64
.bdl
.bdeSize
;
456 else if (rsp
->ulpStatus
== IOSTAT_LS_RJT
) {
457 job
->reply
->reply_payload_rcv_len
=
458 sizeof(struct fc_bsg_ctels_reply
);
459 /* LS_RJT data returned in word 4 */
460 rjt_data
= (uint8_t *)&rsp
->un
.ulpWord
[4];
461 els_reply
= &job
->reply
->reply_data
.ctels_reply
;
462 els_reply
->status
= FC_CTELS_STATUS_REJECT
;
463 els_reply
->rjt_data
.action
= rjt_data
[3];
464 els_reply
->rjt_data
.reason_code
= rjt_data
[2];
465 els_reply
->rjt_data
.reason_explanation
= rjt_data
[1];
466 els_reply
->rjt_data
.vendor_unique
= rjt_data
[0];
470 pbuflist
= (struct lpfc_dmabuf
*) cmdiocbq
->context3
;
471 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
472 lpfc_sli_release_iocbq(phba
, rspiocbq
);
473 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
476 /* make error code available to userspace */
477 job
->reply
->result
= rc
;
479 /* complete the job back to userspace */
481 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
486 * lpfc_bsg_rport_els - send an ELS command from a bsg request
487 * @job: fc_bsg_job to handle
490 lpfc_bsg_rport_els(struct fc_bsg_job
*job
)
492 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
493 struct lpfc_hba
*phba
= vport
->phba
;
494 struct lpfc_rport_data
*rdata
= job
->rport
->dd_data
;
495 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
499 struct lpfc_iocbq
*rspiocbq
;
500 struct lpfc_iocbq
*cmdiocbq
;
503 struct lpfc_dmabuf
*pcmd
;
504 struct lpfc_dmabuf
*prsp
;
505 struct lpfc_dmabuf
*pbuflist
= NULL
;
506 struct ulp_bde64
*bpl
;
509 struct scatterlist
*sgel
= NULL
;
512 struct bsg_job_data
*dd_data
;
516 /* in case no data is transferred */
517 job
->reply
->reply_payload_rcv_len
= 0;
519 /* allocate our bsg tracking structure */
520 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
522 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
523 "2735 Failed allocation of dd_data\n");
528 if (!lpfc_nlp_get(ndlp
)) {
533 elscmd
= job
->request
->rqst_data
.r_els
.els_code
;
534 cmdsize
= job
->request_payload
.payload_len
;
535 rspsize
= job
->reply_payload
.payload_len
;
536 rspiocbq
= lpfc_sli_get_iocbq(phba
);
543 rsp
= &rspiocbq
->iocb
;
546 cmdiocbq
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
,
547 ndlp
->nlp_DID
, elscmd
);
553 /* prep els iocb set context1 to the ndlp, context2 to the command
554 * dmabuf, context3 holds the data dmabuf
556 pcmd
= (struct lpfc_dmabuf
*) cmdiocbq
->context2
;
557 prsp
= (struct lpfc_dmabuf
*) pcmd
->list
.next
;
558 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
560 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
562 cmdiocbq
->context2
= NULL
;
564 pbuflist
= (struct lpfc_dmabuf
*) cmdiocbq
->context3
;
565 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
567 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
568 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
569 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
570 busaddr
= sg_dma_address(sgel
);
571 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
572 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
573 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
574 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
575 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
579 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
580 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
581 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
582 busaddr
= sg_dma_address(sgel
);
583 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
584 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
585 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
586 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
587 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
590 cmdiocbq
->iocb
.un
.elsreq64
.bdl
.bdeSize
=
591 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
592 cmdiocbq
->iocb
.ulpContext
= rpi
;
593 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
594 cmdiocbq
->context1
= NULL
;
595 cmdiocbq
->context2
= NULL
;
597 cmdiocbq
->iocb_cmpl
= lpfc_bsg_rport_els_cmp
;
598 cmdiocbq
->context1
= dd_data
;
599 cmdiocbq
->context2
= rspiocbq
;
600 dd_data
->type
= TYPE_IOCB
;
601 dd_data
->context_un
.iocb
.cmdiocbq
= cmdiocbq
;
602 dd_data
->context_un
.iocb
.rspiocbq
= rspiocbq
;
603 dd_data
->context_un
.iocb
.set_job
= job
;
604 dd_data
->context_un
.iocb
.bmp
= NULL
;
605 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
607 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
608 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
612 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
613 writel(creg_val
, phba
->HCregaddr
);
614 readl(phba
->HCregaddr
); /* flush */
616 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
, 0);
618 if (rc
== IOCB_SUCCESS
)
619 return 0; /* done for now */
620 else if (rc
== IOCB_BUSY
)
626 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
627 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
628 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
629 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
631 lpfc_mbuf_free(phba
, pbuflist
->virt
, pbuflist
->phys
);
633 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
636 lpfc_sli_release_iocbq(phba
, rspiocbq
);
642 /* make error code available to userspace */
643 job
->reply
->result
= rc
;
649 * lpfc_bsg_event_free - frees an allocated event structure
650 * @kref: Pointer to a kref.
652 * Called from kref_put. Back cast the kref into an event structure address.
653 * Free any events to get, delete associated nodes, free any events to see,
654 * free any data then free the event itself.
657 lpfc_bsg_event_free(struct kref
*kref
)
659 struct lpfc_bsg_event
*evt
= container_of(kref
, struct lpfc_bsg_event
,
661 struct event_data
*ed
;
663 list_del(&evt
->node
);
665 while (!list_empty(&evt
->events_to_get
)) {
666 ed
= list_entry(evt
->events_to_get
.next
, typeof(*ed
), node
);
672 while (!list_empty(&evt
->events_to_see
)) {
673 ed
= list_entry(evt
->events_to_see
.next
, typeof(*ed
), node
);
683 * lpfc_bsg_event_ref - increments the kref for an event
684 * @evt: Pointer to an event structure.
687 lpfc_bsg_event_ref(struct lpfc_bsg_event
*evt
)
689 kref_get(&evt
->kref
);
693 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
694 * @evt: Pointer to an event structure.
697 lpfc_bsg_event_unref(struct lpfc_bsg_event
*evt
)
699 kref_put(&evt
->kref
, lpfc_bsg_event_free
);
703 * lpfc_bsg_event_new - allocate and initialize a event structure
704 * @ev_mask: Mask of events.
705 * @ev_reg_id: Event reg id.
706 * @ev_req_id: Event request id.
708 static struct lpfc_bsg_event
*
709 lpfc_bsg_event_new(uint32_t ev_mask
, int ev_reg_id
, uint32_t ev_req_id
)
711 struct lpfc_bsg_event
*evt
= kzalloc(sizeof(*evt
), GFP_KERNEL
);
716 INIT_LIST_HEAD(&evt
->events_to_get
);
717 INIT_LIST_HEAD(&evt
->events_to_see
);
718 evt
->type_mask
= ev_mask
;
719 evt
->req_id
= ev_req_id
;
720 evt
->reg_id
= ev_reg_id
;
721 evt
->wait_time_stamp
= jiffies
;
722 init_waitqueue_head(&evt
->wq
);
723 kref_init(&evt
->kref
);
728 * diag_cmd_data_free - Frees an lpfc dma buffer extension
729 * @phba: Pointer to HBA context object.
730 * @mlist: Pointer to an lpfc dma buffer extension.
733 diag_cmd_data_free(struct lpfc_hba
*phba
, struct lpfc_dmabufext
*mlist
)
735 struct lpfc_dmabufext
*mlast
;
736 struct pci_dev
*pcidev
;
737 struct list_head head
, *curr
, *next
;
739 if ((!mlist
) || (!lpfc_is_link_up(phba
) &&
740 (phba
->link_flag
& LS_LOOPBACK_MODE
))) {
744 pcidev
= phba
->pcidev
;
745 list_add_tail(&head
, &mlist
->dma
.list
);
747 list_for_each_safe(curr
, next
, &head
) {
748 mlast
= list_entry(curr
, struct lpfc_dmabufext
, dma
.list
);
750 dma_free_coherent(&pcidev
->dev
,
760 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
765 * This function is called when an unsolicited CT command is received. It
766 * forwards the event to any processes registered to receive CT events.
769 lpfc_bsg_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
770 struct lpfc_iocbq
*piocbq
)
772 uint32_t evt_req_id
= 0;
775 struct lpfc_dmabuf
*dmabuf
= NULL
;
776 struct lpfc_bsg_event
*evt
;
777 struct event_data
*evt_dat
= NULL
;
778 struct lpfc_iocbq
*iocbq
;
780 struct list_head head
;
781 struct ulp_bde64
*bde
;
784 struct lpfc_dmabuf
*bdeBuf1
= piocbq
->context2
;
785 struct lpfc_dmabuf
*bdeBuf2
= piocbq
->context3
;
786 struct lpfc_hbq_entry
*hbqe
;
787 struct lpfc_sli_ct_request
*ct_req
;
788 struct fc_bsg_job
*job
= NULL
;
792 INIT_LIST_HEAD(&head
);
793 list_add_tail(&head
, &piocbq
->list
);
795 if (piocbq
->iocb
.ulpBdeCount
== 0 ||
796 piocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
== 0)
797 goto error_ct_unsol_exit
;
799 if (phba
->link_state
== LPFC_HBA_ERROR
||
800 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)))
801 goto error_ct_unsol_exit
;
803 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
806 dma_addr
= getPaddr(piocbq
->iocb
.un
.cont64
[0].addrHigh
,
807 piocbq
->iocb
.un
.cont64
[0].addrLow
);
808 dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
, dma_addr
);
811 goto error_ct_unsol_exit
;
812 ct_req
= (struct lpfc_sli_ct_request
*)dmabuf
->virt
;
813 evt_req_id
= ct_req
->FsType
;
814 cmd
= ct_req
->CommandResponse
.bits
.CmdRsp
;
815 len
= ct_req
->CommandResponse
.bits
.Size
;
816 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
817 lpfc_sli_ringpostbuf_put(phba
, pring
, dmabuf
);
819 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
820 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
821 if (!(evt
->type_mask
& FC_REG_CT_EVENT
) ||
822 evt
->req_id
!= evt_req_id
)
825 lpfc_bsg_event_ref(evt
);
826 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
827 evt_dat
= kzalloc(sizeof(*evt_dat
), GFP_KERNEL
);
828 if (evt_dat
== NULL
) {
829 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
830 lpfc_bsg_event_unref(evt
);
831 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
832 "2614 Memory allocation failed for "
837 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
838 /* take accumulated byte count from the last iocbq */
839 iocbq
= list_entry(head
.prev
, typeof(*iocbq
), list
);
840 evt_dat
->len
= iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
;
842 list_for_each_entry(iocbq
, &head
, list
) {
843 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++)
845 iocbq
->iocb
.un
.cont64
[i
].tus
.f
.bdeSize
;
849 evt_dat
->data
= kzalloc(evt_dat
->len
, GFP_KERNEL
);
850 if (evt_dat
->data
== NULL
) {
851 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
852 "2615 Memory allocation failed for "
853 "CT event data, size %d\n",
856 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
857 lpfc_bsg_event_unref(evt
);
858 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
859 goto error_ct_unsol_exit
;
862 list_for_each_entry(iocbq
, &head
, list
) {
864 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
865 bdeBuf1
= iocbq
->context2
;
866 bdeBuf2
= iocbq
->context3
;
868 for (i
= 0; i
< iocbq
->iocb
.ulpBdeCount
; i
++) {
869 if (phba
->sli3_options
&
870 LPFC_SLI3_HBQ_ENABLED
) {
872 hbqe
= (struct lpfc_hbq_entry
*)
873 &iocbq
->iocb
.un
.ulpWord
[0];
874 size
= hbqe
->bde
.tus
.f
.bdeSize
;
877 hbqe
= (struct lpfc_hbq_entry
*)
880 size
= hbqe
->bde
.tus
.f
.bdeSize
;
883 if ((offset
+ size
) > evt_dat
->len
)
884 size
= evt_dat
->len
- offset
;
886 size
= iocbq
->iocb
.un
.cont64
[i
].
888 bde
= &iocbq
->iocb
.un
.cont64
[i
];
889 dma_addr
= getPaddr(bde
->addrHigh
,
891 dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
895 lpfc_printf_log(phba
, KERN_ERR
,
896 LOG_LIBDFC
, "2616 No dmabuf "
897 "found for iocbq 0x%p\n",
899 kfree(evt_dat
->data
);
901 spin_lock_irqsave(&phba
->ct_ev_lock
,
903 lpfc_bsg_event_unref(evt
);
904 spin_unlock_irqrestore(
905 &phba
->ct_ev_lock
, flags
);
906 goto error_ct_unsol_exit
;
908 memcpy((char *)(evt_dat
->data
) + offset
,
911 if (evt_req_id
!= SLI_CT_ELX_LOOPBACK
&&
912 !(phba
->sli3_options
&
913 LPFC_SLI3_HBQ_ENABLED
)) {
914 lpfc_sli_ringpostbuf_put(phba
, pring
,
918 case ELX_LOOPBACK_DATA
:
921 diag_cmd_data_free(phba
,
922 (struct lpfc_dmabufext
925 case ELX_LOOPBACK_XRI_SETUP
:
926 if ((phba
->sli_rev
==
928 (phba
->sli3_options
&
929 LPFC_SLI3_HBQ_ENABLED
931 lpfc_in_buf_free(phba
,
934 lpfc_post_buffer(phba
,
940 if (!(phba
->sli3_options
&
941 LPFC_SLI3_HBQ_ENABLED
))
942 lpfc_post_buffer(phba
,
951 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
952 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
953 evt_dat
->immed_dat
= phba
->ctx_idx
;
954 phba
->ctx_idx
= (phba
->ctx_idx
+ 1) % 64;
955 /* Provide warning for over-run of the ct_ctx array */
956 if (phba
->ct_ctx
[evt_dat
->immed_dat
].flags
&
958 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
959 "2717 CT context array entry "
960 "[%d] over-run: oxid:x%x, "
961 "sid:x%x\n", phba
->ctx_idx
,
963 evt_dat
->immed_dat
].oxid
,
965 evt_dat
->immed_dat
].SID
);
966 phba
->ct_ctx
[evt_dat
->immed_dat
].rxid
=
967 piocbq
->iocb
.ulpContext
;
968 phba
->ct_ctx
[evt_dat
->immed_dat
].oxid
=
969 piocbq
->iocb
.unsli3
.rcvsli3
.ox_id
;
970 phba
->ct_ctx
[evt_dat
->immed_dat
].SID
=
971 piocbq
->iocb
.un
.rcvels
.remoteID
;
972 phba
->ct_ctx
[evt_dat
->immed_dat
].flags
= UNSOL_VALID
;
974 evt_dat
->immed_dat
= piocbq
->iocb
.ulpContext
;
976 evt_dat
->type
= FC_REG_CT_EVENT
;
977 list_add(&evt_dat
->node
, &evt
->events_to_see
);
978 if (evt_req_id
== SLI_CT_ELX_LOOPBACK
) {
979 wake_up_interruptible(&evt
->wq
);
980 lpfc_bsg_event_unref(evt
);
984 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
985 lpfc_bsg_event_unref(evt
);
990 job
->reply
->reply_payload_rcv_len
= size
;
991 /* make error code available to userspace */
992 job
->reply
->result
= 0;
994 /* complete the job back to userspace */
995 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
997 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1000 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1002 error_ct_unsol_exit
:
1003 if (!list_empty(&head
))
1005 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
1006 (evt_req_id
== SLI_CT_ELX_LOOPBACK
))
1012 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1013 * @job: SET_EVENT fc_bsg_job
1016 lpfc_bsg_hba_set_event(struct fc_bsg_job
*job
)
1018 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1019 struct lpfc_hba
*phba
= vport
->phba
;
1020 struct set_ct_event
*event_req
;
1021 struct lpfc_bsg_event
*evt
;
1023 struct bsg_job_data
*dd_data
= NULL
;
1025 unsigned long flags
;
1027 if (job
->request_len
<
1028 sizeof(struct fc_bsg_request
) + sizeof(struct set_ct_event
)) {
1029 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1030 "2612 Received SET_CT_EVENT below minimum "
1036 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1037 if (dd_data
== NULL
) {
1038 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1039 "2734 Failed allocation of dd_data\n");
1044 event_req
= (struct set_ct_event
*)
1045 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1046 ev_mask
= ((uint32_t)(unsigned long)event_req
->type_mask
&
1048 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1049 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1050 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1051 lpfc_bsg_event_ref(evt
);
1052 evt
->wait_time_stamp
= jiffies
;
1056 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1058 if (&evt
->node
== &phba
->ct_ev_waiters
) {
1059 /* no event waiting struct yet - first call */
1060 evt
= lpfc_bsg_event_new(ev_mask
, event_req
->ev_reg_id
,
1061 event_req
->ev_req_id
);
1063 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1064 "2617 Failed allocation of event "
1070 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1071 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
1072 lpfc_bsg_event_ref(evt
);
1073 evt
->wait_time_stamp
= jiffies
;
1074 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1077 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1079 dd_data
->type
= TYPE_EVT
;
1080 dd_data
->context_un
.evt
= evt
;
1081 evt
->set_job
= job
; /* for unsolicited command */
1082 job
->dd_data
= dd_data
; /* for fc transport timeout callback*/
1083 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1084 return 0; /* call job done later */
1087 if (dd_data
!= NULL
)
1090 job
->dd_data
= NULL
;
1095 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1096 * @job: GET_EVENT fc_bsg_job
1099 lpfc_bsg_hba_get_event(struct fc_bsg_job
*job
)
1101 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1102 struct lpfc_hba
*phba
= vport
->phba
;
1103 struct get_ct_event
*event_req
;
1104 struct get_ct_event_reply
*event_reply
;
1105 struct lpfc_bsg_event
*evt
;
1106 struct event_data
*evt_dat
= NULL
;
1107 unsigned long flags
;
1110 if (job
->request_len
<
1111 sizeof(struct fc_bsg_request
) + sizeof(struct get_ct_event
)) {
1112 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1113 "2613 Received GET_CT_EVENT request below "
1119 event_req
= (struct get_ct_event
*)
1120 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1122 event_reply
= (struct get_ct_event_reply
*)
1123 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
1124 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1125 list_for_each_entry(evt
, &phba
->ct_ev_waiters
, node
) {
1126 if (evt
->reg_id
== event_req
->ev_reg_id
) {
1127 if (list_empty(&evt
->events_to_get
))
1129 lpfc_bsg_event_ref(evt
);
1130 evt
->wait_time_stamp
= jiffies
;
1131 evt_dat
= list_entry(evt
->events_to_get
.prev
,
1132 struct event_data
, node
);
1133 list_del(&evt_dat
->node
);
1137 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1139 /* The app may continue to ask for event data until it gets
1140 * an error indicating that there isn't anymore
1142 if (evt_dat
== NULL
) {
1143 job
->reply
->reply_payload_rcv_len
= 0;
1148 if (evt_dat
->len
> job
->request_payload
.payload_len
) {
1149 evt_dat
->len
= job
->request_payload
.payload_len
;
1150 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1151 "2618 Truncated event data at %d "
1153 job
->request_payload
.payload_len
);
1156 event_reply
->type
= evt_dat
->type
;
1157 event_reply
->immed_data
= evt_dat
->immed_dat
;
1158 if (evt_dat
->len
> 0)
1159 job
->reply
->reply_payload_rcv_len
=
1160 sg_copy_from_buffer(job
->request_payload
.sg_list
,
1161 job
->request_payload
.sg_cnt
,
1162 evt_dat
->data
, evt_dat
->len
);
1164 job
->reply
->reply_payload_rcv_len
= 0;
1167 kfree(evt_dat
->data
);
1171 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1172 lpfc_bsg_event_unref(evt
);
1173 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1174 job
->dd_data
= NULL
;
1175 job
->reply
->result
= 0;
1180 job
->dd_data
= NULL
;
1181 job
->reply
->result
= rc
;
1186 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1187 * @phba: Pointer to HBA context object.
1188 * @cmdiocbq: Pointer to command iocb.
1189 * @rspiocbq: Pointer to response iocb.
1191 * This function is the completion handler for iocbs issued using
1192 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1193 * ring event handler function without any lock held. This function
1194 * can be called from both worker thread context and interrupt
1195 * context. This function also can be called from other thread which
1196 * cleans up the SLI layer objects.
1197 * This function copy the contents of the response iocb to the
1198 * response iocb memory object provided by the caller of
1199 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1200 * sleeps for the iocb completion.
1203 lpfc_issue_ct_rsp_cmp(struct lpfc_hba
*phba
,
1204 struct lpfc_iocbq
*cmdiocbq
,
1205 struct lpfc_iocbq
*rspiocbq
)
1207 struct bsg_job_data
*dd_data
;
1208 struct fc_bsg_job
*job
;
1210 struct lpfc_dmabuf
*bmp
;
1211 struct lpfc_nodelist
*ndlp
;
1212 unsigned long flags
;
1215 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
1216 dd_data
= cmdiocbq
->context2
;
1217 /* normal completion and timeout crossed paths, already done */
1219 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1223 job
= dd_data
->context_un
.iocb
.set_job
;
1224 bmp
= dd_data
->context_un
.iocb
.bmp
;
1225 rsp
= &rspiocbq
->iocb
;
1226 ndlp
= dd_data
->context_un
.iocb
.ndlp
;
1228 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1229 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1231 if (rsp
->ulpStatus
) {
1232 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1233 switch (rsp
->un
.ulpWord
[4] & 0xff) {
1234 case IOERR_SEQUENCE_TIMEOUT
:
1237 case IOERR_INVALID_RPI
:
1247 job
->reply
->reply_payload_rcv_len
=
1248 rsp
->un
.genreq64
.bdl
.bdeSize
;
1250 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1251 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
1255 /* make error code available to userspace */
1256 job
->reply
->result
= rc
;
1257 job
->dd_data
= NULL
;
1258 /* complete the job back to userspace */
1260 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
1265 * lpfc_issue_ct_rsp - issue a ct response
1266 * @phba: Pointer to HBA context object.
1267 * @job: Pointer to the job object.
1268 * @tag: tag index value into the ports context exchange array.
1269 * @bmp: Pointer to a dma buffer descriptor.
1270 * @num_entry: Number of enties in the bde.
1273 lpfc_issue_ct_rsp(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
, uint32_t tag
,
1274 struct lpfc_dmabuf
*bmp
, int num_entry
)
1277 struct lpfc_iocbq
*ctiocb
= NULL
;
1279 struct lpfc_nodelist
*ndlp
= NULL
;
1280 struct bsg_job_data
*dd_data
;
1283 /* allocate our bsg tracking structure */
1284 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
1286 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1287 "2736 Failed allocation of dd_data\n");
1292 /* Allocate buffer for command iocb */
1293 ctiocb
= lpfc_sli_get_iocbq(phba
);
1299 icmd
= &ctiocb
->iocb
;
1300 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
1301 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
1302 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
1303 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
1304 icmd
->un
.xseq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
1305 icmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
1306 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
1307 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_SOL_CTL
;
1308 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
1310 /* Fill in rest of iocb */
1311 icmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
1312 icmd
->ulpBdeCount
= 1;
1314 icmd
->ulpClass
= CLASS3
;
1315 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1316 /* Do not issue unsol response if oxid not marked as valid */
1317 if (!(phba
->ct_ctx
[tag
].flags
& UNSOL_VALID
)) {
1319 goto issue_ct_rsp_exit
;
1321 icmd
->ulpContext
= phba
->ct_ctx
[tag
].rxid
;
1322 icmd
->unsli3
.rcvsli3
.ox_id
= phba
->ct_ctx
[tag
].oxid
;
1323 ndlp
= lpfc_findnode_did(phba
->pport
, phba
->ct_ctx
[tag
].SID
);
1325 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
1326 "2721 ndlp null for oxid %x SID %x\n",
1328 phba
->ct_ctx
[tag
].SID
);
1330 goto issue_ct_rsp_exit
;
1333 /* Check if the ndlp is active */
1334 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1336 goto issue_ct_rsp_exit
;
1339 /* get a refernece count so the ndlp doesn't go away while
1342 if (!lpfc_nlp_get(ndlp
)) {
1344 goto issue_ct_rsp_exit
;
1347 icmd
->un
.ulpWord
[3] =
1348 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
1350 /* The exchange is done, mark the entry as invalid */
1351 phba
->ct_ctx
[tag
].flags
&= ~UNSOL_VALID
;
1353 icmd
->ulpContext
= (ushort
) tag
;
1355 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
1357 /* Xmit CT response on exchange <xid> */
1358 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1359 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1360 icmd
->ulpContext
, icmd
->ulpIoTag
, tag
, phba
->link_state
);
1362 ctiocb
->iocb_cmpl
= NULL
;
1363 ctiocb
->iocb_flag
|= LPFC_IO_LIBDFC
;
1364 ctiocb
->vport
= phba
->pport
;
1365 ctiocb
->context3
= bmp
;
1367 ctiocb
->iocb_cmpl
= lpfc_issue_ct_rsp_cmp
;
1368 ctiocb
->context2
= dd_data
;
1369 ctiocb
->context1
= ndlp
;
1370 dd_data
->type
= TYPE_IOCB
;
1371 dd_data
->context_un
.iocb
.cmdiocbq
= ctiocb
;
1372 dd_data
->context_un
.iocb
.rspiocbq
= NULL
;
1373 dd_data
->context_un
.iocb
.set_job
= job
;
1374 dd_data
->context_un
.iocb
.bmp
= bmp
;
1375 dd_data
->context_un
.iocb
.ndlp
= ndlp
;
1377 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
1378 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1380 goto issue_ct_rsp_exit
;
1382 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1383 writel(creg_val
, phba
->HCregaddr
);
1384 readl(phba
->HCregaddr
); /* flush */
1387 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
1389 if (rc
== IOCB_SUCCESS
)
1390 return 0; /* done for now */
1393 lpfc_sli_release_iocbq(phba
, ctiocb
);
1401 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1402 * @job: SEND_MGMT_RESP fc_bsg_job
1405 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job
*job
)
1407 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1408 struct lpfc_hba
*phba
= vport
->phba
;
1409 struct send_mgmt_resp
*mgmt_resp
= (struct send_mgmt_resp
*)
1410 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1411 struct ulp_bde64
*bpl
;
1412 struct lpfc_dmabuf
*bmp
= NULL
;
1413 struct scatterlist
*sgel
= NULL
;
1417 uint32_t tag
= mgmt_resp
->tag
;
1418 unsigned long reqbfrcnt
=
1419 (unsigned long)job
->request_payload
.payload_len
;
1422 /* in case no data is transferred */
1423 job
->reply
->reply_payload_rcv_len
= 0;
1425 if (!reqbfrcnt
|| (reqbfrcnt
> (80 * BUF_SZ_4K
))) {
1427 goto send_mgmt_rsp_exit
;
1430 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1433 goto send_mgmt_rsp_exit
;
1436 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
1439 goto send_mgmt_rsp_free_bmp
;
1442 INIT_LIST_HEAD(&bmp
->list
);
1443 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1444 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1445 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1446 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
1447 busaddr
= sg_dma_address(sgel
);
1448 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1449 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
1450 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
1451 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
1452 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
1456 rc
= lpfc_issue_ct_rsp(phba
, job
, tag
, bmp
, request_nseg
);
1458 if (rc
== IOCB_SUCCESS
)
1459 return 0; /* done for now */
1461 /* TBD need to handle a timeout */
1462 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
1463 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
1465 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1467 send_mgmt_rsp_free_bmp
:
1470 /* make error code available to userspace */
1471 job
->reply
->result
= rc
;
1472 job
->dd_data
= NULL
;
1477 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1478 * @phba: Pointer to HBA context object.
1480 * This function is responsible for preparing driver for diag loopback
1484 lpfc_bsg_diag_mode_enter(struct lpfc_hba
*phba
)
1486 struct lpfc_vport
**vports
;
1487 struct Scsi_Host
*shost
;
1488 struct lpfc_sli
*psli
;
1489 struct lpfc_sli_ring
*pring
;
1496 pring
= &psli
->ring
[LPFC_FCP_RING
];
1500 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1501 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
1502 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
1505 vports
= lpfc_create_vport_work_array(phba
);
1507 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1508 shost
= lpfc_shost_from_vport(vports
[i
]);
1509 scsi_block_requests(shost
);
1511 lpfc_destroy_vport_work_array(phba
, vports
);
1513 shost
= lpfc_shost_from_vport(phba
->pport
);
1514 scsi_block_requests(shost
);
1517 while (pring
->txcmplq_cnt
) {
1518 if (i
++ > 500) /* wait up to 5 seconds */
1526 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1527 * @phba: Pointer to HBA context object.
1529 * This function is responsible for driver exit processing of setting up
1530 * diag loopback mode on device.
1533 lpfc_bsg_diag_mode_exit(struct lpfc_hba
*phba
)
1535 struct Scsi_Host
*shost
;
1536 struct lpfc_vport
**vports
;
1539 vports
= lpfc_create_vport_work_array(phba
);
1541 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
1542 shost
= lpfc_shost_from_vport(vports
[i
]);
1543 scsi_unblock_requests(shost
);
1545 lpfc_destroy_vport_work_array(phba
, vports
);
1547 shost
= lpfc_shost_from_vport(phba
->pport
);
1548 scsi_unblock_requests(shost
);
1554 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1555 * @phba: Pointer to HBA context object.
1556 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1558 * This function is responsible for placing an sli3 port into diagnostic
1559 * loopback mode in order to perform a diagnostic loopback test.
1560 * All new scsi requests are blocked, a small delay is used to allow the
1561 * scsi requests to complete then the link is brought down. If the link is
1562 * is placed in loopback mode then scsi requests are again allowed
1563 * so the scsi mid-layer doesn't give up on the port.
1564 * All of this is done in-line.
1567 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1569 struct diag_mode_set
*loopback_mode
;
1570 uint32_t link_flags
;
1572 LPFC_MBOXQ_t
*pmboxq
= NULL
;
1573 int mbxstatus
= MBX_SUCCESS
;
1577 /* no data to return just the return code */
1578 job
->reply
->reply_payload_rcv_len
= 0;
1580 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1581 sizeof(struct diag_mode_set
)) {
1582 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1583 "2738 Received DIAG MODE request size:%d "
1584 "below the minimum size:%d\n",
1586 (int)(sizeof(struct fc_bsg_request
) +
1587 sizeof(struct diag_mode_set
)));
1592 rc
= lpfc_bsg_diag_mode_enter(phba
);
1596 /* bring the link to diagnostic mode */
1597 loopback_mode
= (struct diag_mode_set
*)
1598 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1599 link_flags
= loopback_mode
->type
;
1600 timeout
= loopback_mode
->timeout
* 100;
1602 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1605 goto loopback_mode_exit
;
1607 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1608 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1609 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1611 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1613 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0)) {
1614 /* wait for link down before proceeding */
1616 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1617 if (i
++ > timeout
) {
1619 goto loopback_mode_exit
;
1624 memset((void *)pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1625 if (link_flags
== INTERNAL_LOOP_BACK
)
1626 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
1628 pmboxq
->u
.mb
.un
.varInitLnk
.link_flags
=
1629 FLAGS_TOPOLOGY_MODE_LOOP
;
1631 pmboxq
->u
.mb
.mbxCommand
= MBX_INIT_LINK
;
1632 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1634 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1637 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
))
1640 spin_lock_irq(&phba
->hbalock
);
1641 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1642 spin_unlock_irq(&phba
->hbalock
);
1643 /* wait for the link attention interrupt */
1647 while (phba
->link_state
!= LPFC_HBA_READY
) {
1648 if (i
++ > timeout
) {
1661 lpfc_bsg_diag_mode_exit(phba
);
1664 * Let SLI layer release mboxq if mbox command completed after timeout.
1666 if (pmboxq
&& mbxstatus
!= MBX_TIMEOUT
)
1667 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1670 /* make error code available to userspace */
1671 job
->reply
->result
= rc
;
1672 /* complete the job back to userspace if no error */
1679 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1680 * @phba: Pointer to HBA context object.
1681 * @diag: Flag for set link to diag or nomral operation state.
1683 * This function is responsible for issuing a sli4 mailbox command for setting
1684 * link to either diag state or normal operation state.
1687 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba
*phba
, uint32_t diag
)
1689 LPFC_MBOXQ_t
*pmboxq
;
1690 struct lpfc_mbx_set_link_diag_state
*link_diag_state
;
1691 uint32_t req_len
, alloc_len
;
1692 int mbxstatus
= MBX_SUCCESS
, rc
;
1694 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1698 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
1699 sizeof(struct lpfc_sli4_cfg_mhdr
));
1700 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1701 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
1702 req_len
, LPFC_SLI4_MBX_EMBED
);
1703 if (alloc_len
!= req_len
) {
1705 goto link_diag_state_set_out
;
1707 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1708 "3128 Set link to diagnostic state:x%x (x%x/x%x)\n",
1709 diag
, phba
->sli4_hba
.lnk_info
.lnk_tp
,
1710 phba
->sli4_hba
.lnk_info
.lnk_no
);
1712 link_diag_state
= &pmboxq
->u
.mqe
.un
.link_diag_state
;
1713 bf_set(lpfc_mbx_set_diag_state_link_num
, &link_diag_state
->u
.req
,
1714 phba
->sli4_hba
.lnk_info
.lnk_no
);
1715 bf_set(lpfc_mbx_set_diag_state_link_type
, &link_diag_state
->u
.req
,
1716 phba
->sli4_hba
.lnk_info
.lnk_tp
);
1718 bf_set(lpfc_mbx_set_diag_state_diag
,
1719 &link_diag_state
->u
.req
, 1);
1721 bf_set(lpfc_mbx_set_diag_state_diag
,
1722 &link_diag_state
->u
.req
, 0);
1724 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1726 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->u
.mb
.mbxStatus
== 0))
1731 link_diag_state_set_out
:
1732 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1733 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1739 * lpfc_sli4_bsg_set_internal_loopback - set sli4 internal loopback diagnostic
1740 * @phba: Pointer to HBA context object.
1742 * This function is responsible for issuing a sli4 mailbox command for setting
1743 * up internal loopback diagnostic.
1746 lpfc_sli4_bsg_set_internal_loopback(struct lpfc_hba
*phba
)
1748 LPFC_MBOXQ_t
*pmboxq
;
1749 uint32_t req_len
, alloc_len
;
1750 struct lpfc_mbx_set_link_diag_loopback
*link_diag_loopback
;
1751 int mbxstatus
= MBX_SUCCESS
, rc
= 0;
1753 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1756 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_loopback
) -
1757 sizeof(struct lpfc_sli4_cfg_mhdr
));
1758 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1759 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK
,
1760 req_len
, LPFC_SLI4_MBX_EMBED
);
1761 if (alloc_len
!= req_len
) {
1762 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1765 link_diag_loopback
= &pmboxq
->u
.mqe
.un
.link_diag_loopback
;
1766 bf_set(lpfc_mbx_set_diag_state_link_num
,
1767 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_no
);
1768 bf_set(lpfc_mbx_set_diag_state_link_type
,
1769 &link_diag_loopback
->u
.req
, phba
->sli4_hba
.lnk_info
.lnk_tp
);
1770 bf_set(lpfc_mbx_set_diag_lpbk_type
, &link_diag_loopback
->u
.req
,
1771 LPFC_DIAG_LOOPBACK_TYPE_SERDES
);
1773 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
);
1774 if ((mbxstatus
!= MBX_SUCCESS
) || (pmboxq
->u
.mb
.mbxStatus
)) {
1775 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1776 "3127 Failed setup loopback mode mailbox "
1777 "command, rc:x%x, status:x%x\n", mbxstatus
,
1778 pmboxq
->u
.mb
.mbxStatus
);
1781 if (pmboxq
&& (mbxstatus
!= MBX_TIMEOUT
))
1782 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1787 * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic
1788 * @phba: Pointer to HBA context object.
1790 * This function set up SLI4 FC port registrations for diagnostic run, which
1791 * includes all the rpis, vfi, and also vpi.
1794 lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba
*phba
)
1798 if (phba
->pport
->fc_flag
& FC_VFI_REGISTERED
) {
1799 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1800 "3136 Port still had vfi registered: "
1801 "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
1802 phba
->pport
->fc_myDID
, phba
->fcf
.fcfi
,
1803 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
],
1804 phba
->vpi_ids
[phba
->pport
->vpi
]);
1807 rc
= lpfc_issue_reg_vfi(phba
->pport
);
1812 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
1813 * @phba: Pointer to HBA context object.
1814 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1816 * This function is responsible for placing an sli4 port into diagnostic
1817 * loopback mode in order to perform a diagnostic loopback test.
1820 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
1822 struct diag_mode_set
*loopback_mode
;
1823 uint32_t link_flags
, timeout
;
1826 /* no data to return just the return code */
1827 job
->reply
->reply_payload_rcv_len
= 0;
1829 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
1830 sizeof(struct diag_mode_set
)) {
1831 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1832 "3011 Received DIAG MODE request size:%d "
1833 "below the minimum size:%d\n",
1835 (int)(sizeof(struct fc_bsg_request
) +
1836 sizeof(struct diag_mode_set
)));
1841 rc
= lpfc_bsg_diag_mode_enter(phba
);
1845 /* indicate we are in loobpack diagnostic mode */
1846 spin_lock_irq(&phba
->hbalock
);
1847 phba
->link_flag
|= LS_LOOPBACK_MODE
;
1848 spin_unlock_irq(&phba
->hbalock
);
1850 /* reset port to start frome scratch */
1851 rc
= lpfc_selective_reset(phba
);
1855 /* bring the link to diagnostic mode */
1856 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1857 "3129 Bring link to diagnostic state.\n");
1858 loopback_mode
= (struct diag_mode_set
*)
1859 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
1860 link_flags
= loopback_mode
->type
;
1861 timeout
= loopback_mode
->timeout
* 100;
1863 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
1865 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
1866 "3130 Failed to bring link to diagnostic "
1867 "state, rc:x%x\n", rc
);
1868 goto loopback_mode_exit
;
1871 /* wait for link down before proceeding */
1873 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
1874 if (i
++ > timeout
) {
1876 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1877 "3131 Timeout waiting for link to "
1878 "diagnostic mode, timeout:%d ms\n",
1880 goto loopback_mode_exit
;
1885 /* set up loopback mode */
1886 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1887 "3132 Set up loopback mode:x%x\n", link_flags
);
1889 if (link_flags
== INTERNAL_LOOP_BACK
)
1890 rc
= lpfc_sli4_bsg_set_internal_loopback(phba
);
1891 else if (link_flags
== EXTERNAL_LOOP_BACK
)
1892 rc
= lpfc_hba_init_link_fc_topology(phba
,
1893 FLAGS_TOPOLOGY_MODE_PT_PT
,
1897 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
1898 "3141 Loopback mode:x%x not supported\n",
1900 goto loopback_mode_exit
;
1904 /* wait for the link attention interrupt */
1907 while (phba
->link_state
< LPFC_LINK_UP
) {
1908 if (i
++ > timeout
) {
1910 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1911 "3137 Timeout waiting for link up "
1912 "in loopback mode, timeout:%d ms\n",
1920 /* port resource registration setup for loopback diagnostic */
1922 /* set up a none zero myDID for loopback test */
1923 phba
->pport
->fc_myDID
= 1;
1924 rc
= lpfc_sli4_diag_fcport_reg_setup(phba
);
1926 goto loopback_mode_exit
;
1929 /* wait for the port ready */
1932 while (phba
->link_state
!= LPFC_HBA_READY
) {
1933 if (i
++ > timeout
) {
1935 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
1936 "3133 Timeout waiting for port "
1937 "loopback mode ready, timeout:%d ms\n",
1946 /* clear loopback diagnostic mode */
1948 spin_lock_irq(&phba
->hbalock
);
1949 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
1950 spin_unlock_irq(&phba
->hbalock
);
1952 lpfc_bsg_diag_mode_exit(phba
);
1955 /* make error code available to userspace */
1956 job
->reply
->result
= rc
;
1957 /* complete the job back to userspace if no error */
1964 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
1965 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1967 * This function is responsible for responding to check and dispatch bsg diag
1968 * command from the user to proper driver action routines.
1971 lpfc_bsg_diag_loopback_mode(struct fc_bsg_job
*job
)
1973 struct Scsi_Host
*shost
;
1974 struct lpfc_vport
*vport
;
1975 struct lpfc_hba
*phba
;
1981 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
1988 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1989 rc
= lpfc_sli3_bsg_diag_loopback_mode(phba
, job
);
1990 else if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1991 LPFC_SLI_INTF_IF_TYPE_2
)
1992 rc
= lpfc_sli4_bsg_diag_loopback_mode(phba
, job
);
2000 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
2001 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
2003 * This function is responsible for responding to check and dispatch bsg diag
2004 * command from the user to proper driver action routines.
2007 lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job
*job
)
2009 struct Scsi_Host
*shost
;
2010 struct lpfc_vport
*vport
;
2011 struct lpfc_hba
*phba
;
2012 struct diag_mode_set
*loopback_mode_end_cmd
;
2019 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2026 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2028 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2029 LPFC_SLI_INTF_IF_TYPE_2
)
2032 /* clear loopback diagnostic mode */
2033 spin_lock_irq(&phba
->hbalock
);
2034 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
2035 spin_unlock_irq(&phba
->hbalock
);
2036 loopback_mode_end_cmd
= (struct diag_mode_set
*)
2037 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2038 timeout
= loopback_mode_end_cmd
->timeout
* 100;
2040 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2042 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2043 "3139 Failed to bring link to diagnostic "
2044 "state, rc:x%x\n", rc
);
2045 goto loopback_mode_end_exit
;
2048 /* wait for link down before proceeding */
2050 while (phba
->link_state
!= LPFC_LINK_DOWN
) {
2051 if (i
++ > timeout
) {
2053 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
2054 "3140 Timeout waiting for link to "
2055 "diagnostic mode_end, timeout:%d ms\n",
2057 /* there is nothing much we can do here */
2063 /* reset port resource registrations */
2064 rc
= lpfc_selective_reset(phba
);
2065 phba
->pport
->fc_myDID
= 0;
2067 loopback_mode_end_exit
:
2068 /* make return code available to userspace */
2069 job
->reply
->result
= rc
;
2070 /* complete the job back to userspace if no error */
2077 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
2078 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
2080 * This function is to perform SLI4 diag link test request from the user
2084 lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job
*job
)
2086 struct Scsi_Host
*shost
;
2087 struct lpfc_vport
*vport
;
2088 struct lpfc_hba
*phba
;
2089 LPFC_MBOXQ_t
*pmboxq
;
2090 struct sli4_link_diag
*link_diag_test_cmd
;
2091 uint32_t req_len
, alloc_len
;
2093 struct lpfc_mbx_run_link_diag_test
*run_link_diag_test
;
2094 union lpfc_sli4_cfg_shdr
*shdr
;
2095 uint32_t shdr_status
, shdr_add_status
;
2096 struct diag_status
*diag_status_reply
;
2097 int mbxstatus
, rc
= 0;
2104 vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2115 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2119 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2120 LPFC_SLI_INTF_IF_TYPE_2
) {
2125 if (job
->request_len
< sizeof(struct fc_bsg_request
) +
2126 sizeof(struct sli4_link_diag
)) {
2127 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2128 "3013 Received LINK DIAG TEST request "
2129 " size:%d below the minimum size:%d\n",
2131 (int)(sizeof(struct fc_bsg_request
) +
2132 sizeof(struct sli4_link_diag
)));
2137 rc
= lpfc_bsg_diag_mode_enter(phba
);
2141 link_diag_test_cmd
= (struct sli4_link_diag
*)
2142 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2143 timeout
= link_diag_test_cmd
->timeout
* 100;
2145 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 1);
2150 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2153 goto link_diag_test_exit
;
2156 req_len
= (sizeof(struct lpfc_mbx_set_link_diag_state
) -
2157 sizeof(struct lpfc_sli4_cfg_mhdr
));
2158 alloc_len
= lpfc_sli4_config(phba
, pmboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2159 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE
,
2160 req_len
, LPFC_SLI4_MBX_EMBED
);
2161 if (alloc_len
!= req_len
) {
2163 goto link_diag_test_exit
;
2165 run_link_diag_test
= &pmboxq
->u
.mqe
.un
.link_diag_test
;
2166 bf_set(lpfc_mbx_run_diag_test_link_num
, &run_link_diag_test
->u
.req
,
2167 phba
->sli4_hba
.lnk_info
.lnk_no
);
2168 bf_set(lpfc_mbx_run_diag_test_link_type
, &run_link_diag_test
->u
.req
,
2169 phba
->sli4_hba
.lnk_info
.lnk_tp
);
2170 bf_set(lpfc_mbx_run_diag_test_test_id
, &run_link_diag_test
->u
.req
,
2171 link_diag_test_cmd
->test_id
);
2172 bf_set(lpfc_mbx_run_diag_test_loops
, &run_link_diag_test
->u
.req
,
2173 link_diag_test_cmd
->loops
);
2174 bf_set(lpfc_mbx_run_diag_test_test_ver
, &run_link_diag_test
->u
.req
,
2175 link_diag_test_cmd
->test_version
);
2176 bf_set(lpfc_mbx_run_diag_test_err_act
, &run_link_diag_test
->u
.req
,
2177 link_diag_test_cmd
->error_action
);
2179 mbxstatus
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2181 shdr
= (union lpfc_sli4_cfg_shdr
*)
2182 &pmboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2183 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
2184 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
2185 if (shdr_status
|| shdr_add_status
|| mbxstatus
) {
2186 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
2187 "3010 Run link diag test mailbox failed with "
2188 "mbx_status x%x status x%x, add_status x%x\n",
2189 mbxstatus
, shdr_status
, shdr_add_status
);
2192 diag_status_reply
= (struct diag_status
*)
2193 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
2195 if (job
->reply_len
<
2196 sizeof(struct fc_bsg_request
) + sizeof(struct diag_status
)) {
2197 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2198 "3012 Received Run link diag test reply "
2199 "below minimum size (%d): reply_len:%d\n",
2200 (int)(sizeof(struct fc_bsg_request
) +
2201 sizeof(struct diag_status
)),
2207 diag_status_reply
->mbox_status
= mbxstatus
;
2208 diag_status_reply
->shdr_status
= shdr_status
;
2209 diag_status_reply
->shdr_add_status
= shdr_add_status
;
2211 link_diag_test_exit
:
2212 rc
= lpfc_sli4_bsg_set_link_diag_state(phba
, 0);
2215 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2217 lpfc_bsg_diag_mode_exit(phba
);
2220 /* make error code available to userspace */
2221 job
->reply
->result
= rc
;
2222 /* complete the job back to userspace if no error */
2229 * lpfcdiag_loop_self_reg - obtains a remote port login id
2230 * @phba: Pointer to HBA context object
2231 * @rpi: Pointer to a remote port login id
2233 * This function obtains a remote port login id so the diag loopback test
2234 * can send and receive its own unsolicited CT command.
2236 static int lpfcdiag_loop_self_reg(struct lpfc_hba
*phba
, uint16_t *rpi
)
2239 struct lpfc_dmabuf
*dmabuff
;
2242 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2246 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2247 status
= lpfc_reg_rpi(phba
, 0, phba
->pport
->fc_myDID
,
2248 (uint8_t *)&phba
->pport
->fc_sparam
,
2251 *rpi
= lpfc_sli4_alloc_rpi(phba
);
2252 status
= lpfc_reg_rpi(phba
, phba
->pport
->vpi
,
2253 phba
->pport
->fc_myDID
,
2254 (uint8_t *)&phba
->pport
->fc_sparam
,
2259 mempool_free(mbox
, phba
->mbox_mem_pool
);
2260 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2261 lpfc_sli4_free_rpi(phba
, *rpi
);
2265 dmabuff
= (struct lpfc_dmabuf
*) mbox
->context1
;
2266 mbox
->context1
= NULL
;
2267 mbox
->context2
= NULL
;
2268 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2270 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2271 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2273 if (status
!= MBX_TIMEOUT
)
2274 mempool_free(mbox
, phba
->mbox_mem_pool
);
2275 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2276 lpfc_sli4_free_rpi(phba
, *rpi
);
2280 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2281 *rpi
= mbox
->u
.mb
.un
.varWords
[0];
2283 lpfc_mbuf_free(phba
, dmabuff
->virt
, dmabuff
->phys
);
2285 mempool_free(mbox
, phba
->mbox_mem_pool
);
2290 * lpfcdiag_loop_self_unreg - unregs from the rpi
2291 * @phba: Pointer to HBA context object
2292 * @rpi: Remote port login id
2294 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2296 static int lpfcdiag_loop_self_unreg(struct lpfc_hba
*phba
, uint16_t rpi
)
2301 /* Allocate mboxq structure */
2302 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2306 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2307 lpfc_unreg_login(phba
, 0, rpi
, mbox
);
2309 lpfc_unreg_login(phba
, phba
->pport
->vpi
,
2310 phba
->sli4_hba
.rpi_ids
[rpi
], mbox
);
2312 status
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2314 if ((status
!= MBX_SUCCESS
) || (mbox
->u
.mb
.mbxStatus
)) {
2315 if (status
!= MBX_TIMEOUT
)
2316 mempool_free(mbox
, phba
->mbox_mem_pool
);
2319 mempool_free(mbox
, phba
->mbox_mem_pool
);
2320 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2321 lpfc_sli4_free_rpi(phba
, rpi
);
2326 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2327 * @phba: Pointer to HBA context object
2328 * @rpi: Remote port login id
2329 * @txxri: Pointer to transmit exchange id
2330 * @rxxri: Pointer to response exchabge id
2332 * This function obtains the transmit and receive ids required to send
2333 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2334 * flags are used to the unsolicted response handler is able to process
2335 * the ct command sent on the same port.
2337 static int lpfcdiag_loop_get_xri(struct lpfc_hba
*phba
, uint16_t rpi
,
2338 uint16_t *txxri
, uint16_t * rxxri
)
2340 struct lpfc_bsg_event
*evt
;
2341 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
2343 struct lpfc_dmabuf
*dmabuf
;
2344 struct ulp_bde64
*bpl
= NULL
;
2345 struct lpfc_sli_ct_request
*ctreq
= NULL
;
2349 unsigned long flags
;
2353 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2354 SLI_CT_ELX_LOOPBACK
);
2358 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2359 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2360 lpfc_bsg_event_ref(evt
);
2361 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2363 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2364 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2366 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2368 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, 0, &dmabuf
->phys
);
2370 INIT_LIST_HEAD(&dmabuf
->list
);
2371 bpl
= (struct ulp_bde64
*) dmabuf
->virt
;
2372 memset(bpl
, 0, sizeof(*bpl
));
2373 ctreq
= (struct lpfc_sli_ct_request
*)(bpl
+ 1);
2375 le32_to_cpu(putPaddrHigh(dmabuf
->phys
+
2378 le32_to_cpu(putPaddrLow(dmabuf
->phys
+
2380 bpl
->tus
.f
.bdeFlags
= 0;
2381 bpl
->tus
.f
.bdeSize
= ELX_LOOPBACK_HEADER_SZ
;
2382 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2386 if (cmdiocbq
== NULL
|| rspiocbq
== NULL
||
2387 dmabuf
== NULL
|| bpl
== NULL
|| ctreq
== NULL
||
2388 dmabuf
->virt
== NULL
) {
2390 goto err_get_xri_exit
;
2393 cmd
= &cmdiocbq
->iocb
;
2394 rsp
= &rspiocbq
->iocb
;
2396 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2398 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2399 ctreq
->RevisionId
.bits
.InId
= 0;
2400 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2401 ctreq
->FsSubType
= 0;
2402 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_XRI_SETUP
;
2403 ctreq
->CommandResponse
.bits
.Size
= 0;
2406 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(dmabuf
->phys
);
2407 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(dmabuf
->phys
);
2408 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2409 cmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(*bpl
);
2411 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= LA
;
2412 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2413 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2414 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2416 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CR
;
2417 cmd
->ulpBdeCount
= 1;
2419 cmd
->ulpClass
= CLASS3
;
2420 cmd
->ulpContext
= rpi
;
2422 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2423 cmdiocbq
->vport
= phba
->pport
;
2425 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2427 (phba
->fc_ratov
* 2)
2428 + LPFC_DRVR_TIMEOUT
);
2431 goto err_get_xri_exit
;
2433 *txxri
= rsp
->ulpContext
;
2436 evt
->wait_time_stamp
= jiffies
;
2437 time_left
= wait_event_interruptible_timeout(
2438 evt
->wq
, !list_empty(&evt
->events_to_see
),
2439 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
2440 if (list_empty(&evt
->events_to_see
))
2441 ret_val
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
2443 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2444 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
2445 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2446 *rxxri
= (list_entry(evt
->events_to_get
.prev
,
2447 typeof(struct event_data
),
2453 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2454 lpfc_bsg_event_unref(evt
); /* release ref */
2455 lpfc_bsg_event_unref(evt
); /* delete */
2456 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2460 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2464 if (cmdiocbq
&& (iocb_stat
!= IOCB_TIMEDOUT
))
2465 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2467 lpfc_sli_release_iocbq(phba
, rspiocbq
);
2472 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2473 * @phba: Pointer to HBA context object
2475 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and.
2476 * retruns the pointer to the buffer.
2478 static struct lpfc_dmabuf
*
2479 lpfc_bsg_dma_page_alloc(struct lpfc_hba
*phba
)
2481 struct lpfc_dmabuf
*dmabuf
;
2482 struct pci_dev
*pcidev
= phba
->pcidev
;
2484 /* allocate dma buffer struct */
2485 dmabuf
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2489 INIT_LIST_HEAD(&dmabuf
->list
);
2491 /* now, allocate dma buffer */
2492 dmabuf
->virt
= dma_alloc_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2493 &(dmabuf
->phys
), GFP_KERNEL
);
2495 if (!dmabuf
->virt
) {
2499 memset((uint8_t *)dmabuf
->virt
, 0, BSG_MBOX_SIZE
);
2505 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2506 * @phba: Pointer to HBA context object.
2507 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2509 * This routine just simply frees a dma buffer and its associated buffer
2510 * descriptor referred by @dmabuf.
2513 lpfc_bsg_dma_page_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*dmabuf
)
2515 struct pci_dev
*pcidev
= phba
->pcidev
;
2521 dma_free_coherent(&pcidev
->dev
, BSG_MBOX_SIZE
,
2522 dmabuf
->virt
, dmabuf
->phys
);
2528 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2529 * @phba: Pointer to HBA context object.
2530 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2532 * This routine just simply frees all dma buffers and their associated buffer
2533 * descriptors referred by @dmabuf_list.
2536 lpfc_bsg_dma_page_list_free(struct lpfc_hba
*phba
,
2537 struct list_head
*dmabuf_list
)
2539 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
2541 if (list_empty(dmabuf_list
))
2544 list_for_each_entry_safe(dmabuf
, next_dmabuf
, dmabuf_list
, list
) {
2545 list_del_init(&dmabuf
->list
);
2546 lpfc_bsg_dma_page_free(phba
, dmabuf
);
2552 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2553 * @phba: Pointer to HBA context object
2554 * @bpl: Pointer to 64 bit bde structure
2555 * @size: Number of bytes to process
2556 * @nocopydata: Flag to copy user data into the allocated buffer
2558 * This function allocates page size buffers and populates an lpfc_dmabufext.
2559 * If allowed the user data pointed to with indataptr is copied into the kernel
2560 * memory. The chained list of page size buffers is returned.
2562 static struct lpfc_dmabufext
*
2563 diag_cmd_data_alloc(struct lpfc_hba
*phba
,
2564 struct ulp_bde64
*bpl
, uint32_t size
,
2567 struct lpfc_dmabufext
*mlist
= NULL
;
2568 struct lpfc_dmabufext
*dmp
;
2569 int cnt
, offset
= 0, i
= 0;
2570 struct pci_dev
*pcidev
;
2572 pcidev
= phba
->pcidev
;
2575 /* We get chunks of 4K */
2576 if (size
> BUF_SZ_4K
)
2581 /* allocate struct lpfc_dmabufext buffer header */
2582 dmp
= kmalloc(sizeof(struct lpfc_dmabufext
), GFP_KERNEL
);
2586 INIT_LIST_HEAD(&dmp
->dma
.list
);
2588 /* Queue it to a linked list */
2590 list_add_tail(&dmp
->dma
.list
, &mlist
->dma
.list
);
2594 /* allocate buffer */
2595 dmp
->dma
.virt
= dma_alloc_coherent(&pcidev
->dev
,
2606 bpl
->tus
.f
.bdeFlags
= 0;
2607 pci_dma_sync_single_for_device(phba
->pcidev
,
2608 dmp
->dma
.phys
, LPFC_BPL_SIZE
, PCI_DMA_TODEVICE
);
2611 memset((uint8_t *)dmp
->dma
.virt
, 0, cnt
);
2612 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
2615 /* build buffer ptr list for IOCB */
2616 bpl
->addrLow
= le32_to_cpu(putPaddrLow(dmp
->dma
.phys
));
2617 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(dmp
->dma
.phys
));
2618 bpl
->tus
.f
.bdeSize
= (ushort
) cnt
;
2619 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
2630 diag_cmd_data_free(phba
, mlist
);
2635 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2636 * @phba: Pointer to HBA context object
2637 * @rxxri: Receive exchange id
2638 * @len: Number of data bytes
2640 * This function allocates and posts a data buffer of sufficient size to receive
2641 * an unsolicted CT command.
2643 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba
*phba
, uint16_t rxxri
,
2646 struct lpfc_sli
*psli
= &phba
->sli
;
2647 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2648 struct lpfc_iocbq
*cmdiocbq
;
2650 struct list_head head
, *curr
, *next
;
2651 struct lpfc_dmabuf
*rxbmp
;
2652 struct lpfc_dmabuf
*dmp
;
2653 struct lpfc_dmabuf
*mp
[2] = {NULL
, NULL
};
2654 struct ulp_bde64
*rxbpl
= NULL
;
2656 struct lpfc_dmabufext
*rxbuffer
= NULL
;
2661 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2662 rxbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2663 if (rxbmp
!= NULL
) {
2664 rxbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &rxbmp
->phys
);
2666 INIT_LIST_HEAD(&rxbmp
->list
);
2667 rxbpl
= (struct ulp_bde64
*) rxbmp
->virt
;
2668 rxbuffer
= diag_cmd_data_alloc(phba
, rxbpl
, len
, 0);
2672 if (!cmdiocbq
|| !rxbmp
|| !rxbpl
|| !rxbuffer
) {
2674 goto err_post_rxbufs_exit
;
2677 /* Queue buffers for the receive exchange */
2678 num_bde
= (uint32_t)rxbuffer
->flag
;
2679 dmp
= &rxbuffer
->dma
;
2681 cmd
= &cmdiocbq
->iocb
;
2684 INIT_LIST_HEAD(&head
);
2685 list_add_tail(&head
, &dmp
->list
);
2686 list_for_each_safe(curr
, next
, &head
) {
2687 mp
[i
] = list_entry(curr
, struct lpfc_dmabuf
, list
);
2690 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2691 mp
[i
]->buffer_tag
= lpfc_sli_get_buffer_tag(phba
);
2692 cmd
->un
.quexri64cx
.buff
.bde
.addrHigh
=
2693 putPaddrHigh(mp
[i
]->phys
);
2694 cmd
->un
.quexri64cx
.buff
.bde
.addrLow
=
2695 putPaddrLow(mp
[i
]->phys
);
2696 cmd
->un
.quexri64cx
.buff
.bde
.tus
.f
.bdeSize
=
2697 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2698 cmd
->un
.quexri64cx
.buff
.buffer_tag
= mp
[i
]->buffer_tag
;
2699 cmd
->ulpCommand
= CMD_QUE_XRI64_CX
;
2702 cmd
->ulpBdeCount
= 1;
2703 cmd
->unsli3
.que_xri64cx_ext_words
.ebde_count
= 0;
2706 cmd
->un
.cont64
[i
].addrHigh
= putPaddrHigh(mp
[i
]->phys
);
2707 cmd
->un
.cont64
[i
].addrLow
= putPaddrLow(mp
[i
]->phys
);
2708 cmd
->un
.cont64
[i
].tus
.f
.bdeSize
=
2709 ((struct lpfc_dmabufext
*)mp
[i
])->size
;
2710 cmd
->ulpBdeCount
= ++i
;
2712 if ((--num_bde
> 0) && (i
< 2))
2715 cmd
->ulpCommand
= CMD_QUE_XRI_BUF64_CX
;
2719 cmd
->ulpClass
= CLASS3
;
2720 cmd
->ulpContext
= rxxri
;
2722 iocb_stat
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
2724 if (iocb_stat
== IOCB_ERROR
) {
2725 diag_cmd_data_free(phba
,
2726 (struct lpfc_dmabufext
*)mp
[0]);
2728 diag_cmd_data_free(phba
,
2729 (struct lpfc_dmabufext
*)mp
[1]);
2730 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2732 goto err_post_rxbufs_exit
;
2735 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[0]);
2737 lpfc_sli_ringpostbuf_put(phba
, pring
, mp
[1]);
2741 /* The iocb was freed by lpfc_sli_issue_iocb */
2742 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2744 dmp
= list_entry(next
, struct lpfc_dmabuf
, list
);
2746 goto err_post_rxbufs_exit
;
2749 cmd
= &cmdiocbq
->iocb
;
2754 err_post_rxbufs_exit
:
2758 lpfc_mbuf_free(phba
, rxbmp
->virt
, rxbmp
->phys
);
2763 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
2768 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
2769 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2771 * This function receives a user data buffer to be transmitted and received on
2772 * the same port, the link must be up and in loopback mode prior
2774 * 1. A kernel buffer is allocated to copy the user data into.
2775 * 2. The port registers with "itself".
2776 * 3. The transmit and receive exchange ids are obtained.
2777 * 4. The receive exchange id is posted.
2778 * 5. A new els loopback event is created.
2779 * 6. The command and response iocbs are allocated.
2780 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2782 * This function is meant to be called n times while the port is in loopback
2783 * so it is the apps responsibility to issue a reset to take the port out
2787 lpfc_bsg_diag_loopback_run(struct fc_bsg_job
*job
)
2789 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
2790 struct lpfc_hba
*phba
= vport
->phba
;
2791 struct diag_mode_test
*diag_mode
;
2792 struct lpfc_bsg_event
*evt
;
2793 struct event_data
*evdat
;
2794 struct lpfc_sli
*psli
= &phba
->sli
;
2797 size_t segment_len
= 0, segment_offset
= 0, current_offset
= 0;
2799 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
= NULL
;
2800 IOCB_t
*cmd
, *rsp
= NULL
;
2801 struct lpfc_sli_ct_request
*ctreq
;
2802 struct lpfc_dmabuf
*txbmp
;
2803 struct ulp_bde64
*txbpl
= NULL
;
2804 struct lpfc_dmabufext
*txbuffer
= NULL
;
2805 struct list_head head
;
2806 struct lpfc_dmabuf
*curr
;
2807 uint16_t txxri
= 0, rxxri
;
2809 uint8_t *ptr
= NULL
, *rx_databuf
= NULL
;
2813 unsigned long flags
;
2814 void *dataout
= NULL
;
2817 /* in case no data is returned return just the return code */
2818 job
->reply
->reply_payload_rcv_len
= 0;
2820 if (job
->request_len
<
2821 sizeof(struct fc_bsg_request
) + sizeof(struct diag_mode_test
)) {
2822 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
2823 "2739 Received DIAG TEST request below minimum "
2826 goto loopback_test_exit
;
2829 if (job
->request_payload
.payload_len
!=
2830 job
->reply_payload
.payload_len
) {
2832 goto loopback_test_exit
;
2834 diag_mode
= (struct diag_mode_test
*)
2835 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
2837 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
2838 (psli
->sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
2839 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
))) {
2841 goto loopback_test_exit
;
2844 if (!lpfc_is_link_up(phba
) || !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
2846 goto loopback_test_exit
;
2849 size
= job
->request_payload
.payload_len
;
2850 full_size
= size
+ ELX_LOOPBACK_HEADER_SZ
; /* plus the header */
2852 if ((size
== 0) || (size
> 80 * BUF_SZ_4K
)) {
2854 goto loopback_test_exit
;
2857 if (full_size
>= BUF_SZ_4K
) {
2859 * Allocate memory for ioctl data. If buffer is bigger than 64k,
2860 * then we allocate 64k and re-use that buffer over and over to
2861 * xfer the whole block. This is because Linux kernel has a
2862 * problem allocating more than 120k of kernel space memory. Saw
2863 * problem with GET_FCPTARGETMAPPING...
2865 if (size
<= (64 * 1024))
2866 total_mem
= full_size
;
2868 total_mem
= 64 * 1024;
2870 /* Allocate memory for ioctl data */
2871 total_mem
= BUF_SZ_4K
;
2873 dataout
= kmalloc(total_mem
, GFP_KERNEL
);
2874 if (dataout
== NULL
) {
2876 goto loopback_test_exit
;
2880 ptr
+= ELX_LOOPBACK_HEADER_SZ
;
2881 sg_copy_to_buffer(job
->request_payload
.sg_list
,
2882 job
->request_payload
.sg_cnt
,
2884 rc
= lpfcdiag_loop_self_reg(phba
, &rpi
);
2886 goto loopback_test_exit
;
2888 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2889 rc
= lpfcdiag_loop_get_xri(phba
, rpi
, &txxri
, &rxxri
);
2891 lpfcdiag_loop_self_unreg(phba
, rpi
);
2892 goto loopback_test_exit
;
2895 rc
= lpfcdiag_loop_post_rxbufs(phba
, rxxri
, full_size
);
2897 lpfcdiag_loop_self_unreg(phba
, rpi
);
2898 goto loopback_test_exit
;
2901 evt
= lpfc_bsg_event_new(FC_REG_CT_EVENT
, current
->pid
,
2902 SLI_CT_ELX_LOOPBACK
);
2904 lpfcdiag_loop_self_unreg(phba
, rpi
);
2906 goto loopback_test_exit
;
2909 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
2910 list_add(&evt
->node
, &phba
->ct_ev_waiters
);
2911 lpfc_bsg_event_ref(evt
);
2912 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
2914 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
2915 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2916 rspiocbq
= lpfc_sli_get_iocbq(phba
);
2917 txbmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2920 txbmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &txbmp
->phys
);
2922 INIT_LIST_HEAD(&txbmp
->list
);
2923 txbpl
= (struct ulp_bde64
*) txbmp
->virt
;
2924 txbuffer
= diag_cmd_data_alloc(phba
,
2925 txbpl
, full_size
, 0);
2929 if (!cmdiocbq
|| !txbmp
|| !txbpl
|| !txbuffer
|| !txbmp
->virt
) {
2931 goto err_loopback_test_exit
;
2933 if ((phba
->sli_rev
< LPFC_SLI_REV4
) && !rspiocbq
) {
2935 goto err_loopback_test_exit
;
2938 cmd
= &cmdiocbq
->iocb
;
2939 if (phba
->sli_rev
< LPFC_SLI_REV4
)
2940 rsp
= &rspiocbq
->iocb
;
2942 INIT_LIST_HEAD(&head
);
2943 list_add_tail(&head
, &txbuffer
->dma
.list
);
2944 list_for_each_entry(curr
, &head
, list
) {
2945 segment_len
= ((struct lpfc_dmabufext
*)curr
)->size
;
2946 if (current_offset
== 0) {
2948 memset(ctreq
, 0, ELX_LOOPBACK_HEADER_SZ
);
2949 ctreq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2950 ctreq
->RevisionId
.bits
.InId
= 0;
2951 ctreq
->FsType
= SLI_CT_ELX_LOOPBACK
;
2952 ctreq
->FsSubType
= 0;
2953 ctreq
->CommandResponse
.bits
.CmdRsp
= ELX_LOOPBACK_DATA
;
2954 ctreq
->CommandResponse
.bits
.Size
= size
;
2955 segment_offset
= ELX_LOOPBACK_HEADER_SZ
;
2959 BUG_ON(segment_offset
>= segment_len
);
2960 memcpy(curr
->virt
+ segment_offset
,
2961 ptr
+ current_offset
,
2962 segment_len
- segment_offset
);
2964 current_offset
+= segment_len
- segment_offset
;
2965 BUG_ON(current_offset
> size
);
2969 /* Build the XMIT_SEQUENCE iocb */
2970 num_bde
= (uint32_t)txbuffer
->flag
;
2972 cmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(txbmp
->phys
);
2973 cmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(txbmp
->phys
);
2974 cmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
2975 cmd
->un
.xseq64
.bdl
.bdeSize
= (num_bde
* sizeof(struct ulp_bde64
));
2977 cmd
->un
.xseq64
.w5
.hcsw
.Fctl
= (LS
| LA
);
2978 cmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
2979 cmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
2980 cmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
2982 cmd
->ulpCommand
= CMD_XMIT_SEQUENCE64_CX
;
2983 cmd
->ulpBdeCount
= 1;
2985 cmd
->ulpClass
= CLASS3
;
2987 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2988 cmd
->ulpContext
= txxri
;
2990 cmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
2991 cmd
->un
.ulpWord
[3] = phba
->sli4_hba
.rpi_ids
[rpi
];
2992 cmdiocbq
->context3
= txbmp
;
2993 cmdiocbq
->sli4_xritag
= NO_XRI
;
2994 cmd
->unsli3
.rcvsli3
.ox_id
= 0xffff;
2996 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
2997 cmdiocbq
->vport
= phba
->pport
;
2998 iocb_stat
= lpfc_sli_issue_iocb_wait(phba
, LPFC_ELS_RING
, cmdiocbq
,
2999 rspiocbq
, (phba
->fc_ratov
* 2) +
3002 if ((iocb_stat
!= IOCB_SUCCESS
) || ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3003 (rsp
->ulpStatus
!= IOCB_SUCCESS
))) {
3004 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3005 "3126 Failed loopback test issue iocb: "
3006 "iocb_stat:x%x\n", iocb_stat
);
3008 goto err_loopback_test_exit
;
3012 time_left
= wait_event_interruptible_timeout(
3013 evt
->wq
, !list_empty(&evt
->events_to_see
),
3014 ((phba
->fc_ratov
* 2) + LPFC_DRVR_TIMEOUT
) * HZ
);
3016 if (list_empty(&evt
->events_to_see
)) {
3017 rc
= (time_left
) ? -EINTR
: -ETIMEDOUT
;
3018 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3019 "3125 Not receiving unsolicited event, "
3022 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3023 list_move(evt
->events_to_see
.prev
, &evt
->events_to_get
);
3024 evdat
= list_entry(evt
->events_to_get
.prev
,
3025 typeof(*evdat
), node
);
3026 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3027 rx_databuf
= evdat
->data
;
3028 if (evdat
->len
!= full_size
) {
3029 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3030 "1603 Loopback test did not receive expected "
3031 "data length. actual length 0x%x expected "
3033 evdat
->len
, full_size
);
3035 } else if (rx_databuf
== NULL
)
3039 /* skip over elx loopback header */
3040 rx_databuf
+= ELX_LOOPBACK_HEADER_SZ
;
3041 job
->reply
->reply_payload_rcv_len
=
3042 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3043 job
->reply_payload
.sg_cnt
,
3045 job
->reply
->reply_payload_rcv_len
= size
;
3049 err_loopback_test_exit
:
3050 lpfcdiag_loop_self_unreg(phba
, rpi
);
3052 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3053 lpfc_bsg_event_unref(evt
); /* release ref */
3054 lpfc_bsg_event_unref(evt
); /* delete */
3055 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3057 if (cmdiocbq
!= NULL
)
3058 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
3060 if (rspiocbq
!= NULL
)
3061 lpfc_sli_release_iocbq(phba
, rspiocbq
);
3063 if (txbmp
!= NULL
) {
3064 if (txbpl
!= NULL
) {
3065 if (txbuffer
!= NULL
)
3066 diag_cmd_data_free(phba
, txbuffer
);
3067 lpfc_mbuf_free(phba
, txbmp
->virt
, txbmp
->phys
);
3074 /* make error code available to userspace */
3075 job
->reply
->result
= rc
;
3076 job
->dd_data
= NULL
;
3077 /* complete the job back to userspace if no error */
3078 if (rc
== IOCB_SUCCESS
)
3084 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
3085 * @job: GET_DFC_REV fc_bsg_job
3088 lpfc_bsg_get_dfc_rev(struct fc_bsg_job
*job
)
3090 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
3091 struct lpfc_hba
*phba
= vport
->phba
;
3092 struct get_mgmt_rev
*event_req
;
3093 struct get_mgmt_rev_reply
*event_reply
;
3096 if (job
->request_len
<
3097 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev
)) {
3098 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3099 "2740 Received GET_DFC_REV request below "
3105 event_req
= (struct get_mgmt_rev
*)
3106 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3108 event_reply
= (struct get_mgmt_rev_reply
*)
3109 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
3111 if (job
->reply_len
<
3112 sizeof(struct fc_bsg_request
) + sizeof(struct get_mgmt_rev_reply
)) {
3113 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3114 "2741 Received GET_DFC_REV reply below "
3120 event_reply
->info
.a_Major
= MANAGEMENT_MAJOR_REV
;
3121 event_reply
->info
.a_Minor
= MANAGEMENT_MINOR_REV
;
3123 job
->reply
->result
= rc
;
3130 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
3131 * @phba: Pointer to HBA context object.
3132 * @pmboxq: Pointer to mailbox command.
3134 * This is completion handler function for mailbox commands issued from
3135 * lpfc_bsg_issue_mbox function. This function is called by the
3136 * mailbox event handler function with no lock held. This function
3137 * will wake up thread waiting on the wait queue pointed by context1
3141 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3143 struct bsg_job_data
*dd_data
;
3144 struct fc_bsg_job
*job
;
3146 unsigned long flags
;
3147 uint8_t *pmb
, *pmb_buf
;
3149 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3150 dd_data
= pmboxq
->context1
;
3151 /* job already timed out? */
3153 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3158 * The outgoing buffer is readily referred from the dma buffer,
3159 * just need to get header part from mailboxq structure.
3161 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3162 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3163 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3165 job
= dd_data
->context_un
.mbox
.set_job
;
3167 size
= job
->reply_payload
.payload_len
;
3168 job
->reply
->reply_payload_rcv_len
=
3169 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3170 job
->reply_payload
.sg_cnt
,
3172 /* need to hold the lock until we set job->dd_data to NULL
3173 * to hold off the timeout handler returning to the mid-layer
3174 * while we are still processing the job.
3176 job
->dd_data
= NULL
;
3177 dd_data
->context_un
.mbox
.set_job
= NULL
;
3178 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3180 dd_data
->context_un
.mbox
.set_job
= NULL
;
3181 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3184 mempool_free(dd_data
->context_un
.mbox
.pmboxq
, phba
->mbox_mem_pool
);
3185 lpfc_bsg_dma_page_free(phba
, dd_data
->context_un
.mbox
.dmabuffers
);
3189 job
->reply
->result
= 0;
3196 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3197 * @phba: Pointer to HBA context object.
3198 * @mb: Pointer to a mailbox object.
3199 * @vport: Pointer to a vport object.
3201 * Some commands require the port to be offline, some may not be called from
3204 static int lpfc_bsg_check_cmd_access(struct lpfc_hba
*phba
,
3205 MAILBOX_t
*mb
, struct lpfc_vport
*vport
)
3207 /* return negative error values for bsg job */
3208 switch (mb
->mbxCommand
) {
3212 case MBX_CONFIG_LINK
:
3213 case MBX_CONFIG_RING
:
3214 case MBX_RESET_RING
:
3215 case MBX_UNREG_LOGIN
:
3217 case MBX_DUMP_CONTEXT
:
3221 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
3222 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3223 "2743 Command 0x%x is illegal in on-line "
3229 case MBX_WRITE_VPARMS
:
3232 case MBX_READ_CONFIG
:
3233 case MBX_READ_RCONFIG
:
3234 case MBX_READ_STATUS
:
3237 case MBX_READ_LNK_STAT
:
3238 case MBX_DUMP_MEMORY
:
3240 case MBX_UPDATE_CFG
:
3241 case MBX_KILL_BOARD
:
3243 case MBX_LOAD_EXP_ROM
:
3245 case MBX_DEL_LD_ENTRY
:
3248 case MBX_SLI4_CONFIG
:
3249 case MBX_READ_EVENT_LOG
:
3250 case MBX_READ_EVENT_LOG_STATUS
:
3251 case MBX_WRITE_EVENT_LOG
:
3252 case MBX_PORT_CAPABILITIES
:
3253 case MBX_PORT_IOV_CONTROL
:
3254 case MBX_RUN_BIU_DIAG64
:
3256 case MBX_SET_VARIABLE
:
3257 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3258 "1226 mbox: set_variable 0x%x, 0x%x\n",
3260 mb
->un
.varWords
[1]);
3261 if ((mb
->un
.varWords
[0] == SETVAR_MLOMNT
)
3262 && (mb
->un
.varWords
[1] == 1)) {
3263 phba
->wait_4_mlo_maint_flg
= 1;
3264 } else if (mb
->un
.varWords
[0] == SETVAR_MLORST
) {
3265 spin_lock_irq(&phba
->hbalock
);
3266 phba
->link_flag
&= ~LS_LOOPBACK_MODE
;
3267 spin_unlock_irq(&phba
->hbalock
);
3268 phba
->fc_topology
= LPFC_TOPOLOGY_PT_PT
;
3271 case MBX_READ_SPARM64
:
3272 case MBX_READ_TOPOLOGY
:
3274 case MBX_REG_LOGIN64
:
3275 case MBX_CONFIG_PORT
:
3276 case MBX_RUN_BIU_DIAG
:
3278 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
3279 "2742 Unknown Command 0x%x\n",
3288 * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
3289 * @phba: Pointer to HBA context object.
3291 * This is routine clean up and reset BSG handling of multi-buffer mbox
3295 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba
*phba
)
3297 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
)
3300 /* free all memory, including dma buffers */
3301 lpfc_bsg_dma_page_list_free(phba
,
3302 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3303 lpfc_bsg_dma_page_free(phba
, phba
->mbox_ext_buf_ctx
.mbx_dmabuf
);
3304 /* multi-buffer write mailbox command pass-through complete */
3305 memset((char *)&phba
->mbox_ext_buf_ctx
, 0,
3306 sizeof(struct lpfc_mbox_ext_buf_ctx
));
3307 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3313 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3314 * @phba: Pointer to HBA context object.
3315 * @pmboxq: Pointer to mailbox command.
3317 * This is routine handles BSG job for mailbox commands completions with
3318 * multiple external buffers.
3320 static struct fc_bsg_job
*
3321 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3323 struct bsg_job_data
*dd_data
;
3324 struct fc_bsg_job
*job
;
3325 uint8_t *pmb
, *pmb_buf
;
3326 unsigned long flags
;
3329 struct lpfc_dmabuf
*dmabuf
;
3330 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3333 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
3334 dd_data
= pmboxq
->context1
;
3335 /* has the job already timed out? */
3337 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3343 * The outgoing buffer is readily referred from the dma buffer,
3344 * just need to get header part from mailboxq structure.
3346 pmb
= (uint8_t *)&pmboxq
->u
.mb
;
3347 pmb_buf
= (uint8_t *)dd_data
->context_un
.mbox
.mb
;
3348 /* Copy the byte swapped response mailbox back to the user */
3349 memcpy(pmb_buf
, pmb
, sizeof(MAILBOX_t
));
3350 /* if there is any non-embedded extended data copy that too */
3351 dmabuf
= phba
->mbox_ext_buf_ctx
.mbx_dmabuf
;
3352 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3353 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3354 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3355 pmbx
= (uint8_t *)dmabuf
->virt
;
3356 /* byte swap the extended data following the mailbox command */
3357 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3358 &pmbx
[sizeof(MAILBOX_t
)],
3359 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[0].buf_len
);
3362 job
= dd_data
->context_un
.mbox
.set_job
;
3364 size
= job
->reply_payload
.payload_len
;
3365 job
->reply
->reply_payload_rcv_len
=
3366 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
3367 job
->reply_payload
.sg_cnt
,
3369 /* result for successful */
3370 job
->reply
->result
= 0;
3371 job
->dd_data
= NULL
;
3372 /* need to hold the lock util we set job->dd_data to NULL
3373 * to hold off the timeout handler from midlayer to take
3376 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3377 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3378 "2937 SLI_CONFIG ext-buffer maibox command "
3379 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3380 phba
->mbox_ext_buf_ctx
.nembType
,
3381 phba
->mbox_ext_buf_ctx
.mboxType
, size
);
3382 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
,
3383 phba
->mbox_ext_buf_ctx
.nembType
,
3384 phba
->mbox_ext_buf_ctx
.mboxType
,
3385 dma_ebuf
, sta_pos_addr
,
3386 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
, 0);
3388 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
3392 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3393 "2938 SLI_CONFIG ext-buffer maibox "
3394 "command (x%x/x%x) failure, rc:x%x\n",
3395 phba
->mbox_ext_buf_ctx
.nembType
,
3396 phba
->mbox_ext_buf_ctx
.mboxType
, rc
);
3398 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_DONE
;
3405 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3406 * @phba: Pointer to HBA context object.
3407 * @pmboxq: Pointer to mailbox command.
3409 * This is completion handler function for mailbox read commands with multiple
3413 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3415 struct fc_bsg_job
*job
;
3417 /* handle the BSG job with mailbox command */
3418 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3419 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3421 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3422 "2939 SLI_CONFIG ext-buffer rd maibox command "
3423 "complete, ctxState:x%x, mbxStatus:x%x\n",
3424 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3426 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3428 if (pmboxq
->u
.mb
.mbxStatus
|| phba
->mbox_ext_buf_ctx
.numBuf
== 1)
3429 lpfc_bsg_mbox_ext_session_reset(phba
);
3431 /* free base driver mailbox structure memory */
3432 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3434 /* complete the bsg job if we have it */
3442 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3443 * @phba: Pointer to HBA context object.
3444 * @pmboxq: Pointer to mailbox command.
3446 * This is completion handler function for mailbox write commands with multiple
3450 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
3452 struct fc_bsg_job
*job
;
3454 /* handle the BSG job with the mailbox command */
3455 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_ABTS
)
3456 pmboxq
->u
.mb
.mbxStatus
= MBXERR_ERROR
;
3458 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3459 "2940 SLI_CONFIG ext-buffer wr maibox command "
3460 "complete, ctxState:x%x, mbxStatus:x%x\n",
3461 phba
->mbox_ext_buf_ctx
.state
, pmboxq
->u
.mb
.mbxStatus
);
3463 job
= lpfc_bsg_issue_mbox_ext_handle_job(phba
, pmboxq
);
3465 /* free all memory, including dma buffers */
3466 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3467 lpfc_bsg_mbox_ext_session_reset(phba
);
3469 /* complete the bsg job if we have it */
3477 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba
*phba
, enum nemb_type nemb_tp
,
3478 uint32_t index
, struct lpfc_dmabuf
*mbx_dmabuf
,
3479 struct lpfc_dmabuf
*ext_dmabuf
)
3481 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3483 /* pointer to the start of mailbox command */
3484 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)mbx_dmabuf
->virt
;
3486 if (nemb_tp
== nemb_mse
) {
3488 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3490 putPaddrHigh(mbx_dmabuf
->phys
+
3492 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3494 putPaddrLow(mbx_dmabuf
->phys
+
3496 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3497 "2943 SLI_CONFIG(mse)[%d], "
3498 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3500 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3502 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3504 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3507 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3509 putPaddrHigh(ext_dmabuf
->phys
);
3510 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3512 putPaddrLow(ext_dmabuf
->phys
);
3513 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3514 "2944 SLI_CONFIG(mse)[%d], "
3515 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3517 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3519 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3521 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3526 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3528 putPaddrHigh(mbx_dmabuf
->phys
+
3530 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3532 putPaddrLow(mbx_dmabuf
->phys
+
3534 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3535 "3007 SLI_CONFIG(hbd)[%d], "
3536 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3538 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3540 sli_config_emb1_subsys
.hbd
[index
]),
3541 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3543 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3547 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3549 putPaddrHigh(ext_dmabuf
->phys
);
3550 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3552 putPaddrLow(ext_dmabuf
->phys
);
3553 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3554 "3008 SLI_CONFIG(hbd)[%d], "
3555 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3557 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3559 sli_config_emb1_subsys
.hbd
[index
]),
3560 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3562 sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3570 * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
3571 * @phba: Pointer to HBA context object.
3572 * @mb: Pointer to a BSG mailbox object.
3573 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3574 * @dmabuff: Pointer to a DMA buffer descriptor.
3576 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3577 * non-embedded external bufffers.
3580 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3581 enum nemb_type nemb_tp
,
3582 struct lpfc_dmabuf
*dmabuf
)
3584 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3585 struct dfc_mbox_req
*mbox_req
;
3586 struct lpfc_dmabuf
*curr_dmabuf
, *next_dmabuf
;
3587 uint32_t ext_buf_cnt
, ext_buf_index
;
3588 struct lpfc_dmabuf
*ext_dmabuf
= NULL
;
3589 struct bsg_job_data
*dd_data
= NULL
;
3590 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3596 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3598 /* pointer to the start of mailbox command */
3599 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3601 if (nemb_tp
== nemb_mse
) {
3602 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3603 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3604 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3605 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3606 "2945 Handled SLI_CONFIG(mse) rd, "
3607 "ext_buf_cnt(%d) out of range(%d)\n",
3609 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3613 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3614 "2941 Handled SLI_CONFIG(mse) rd, "
3615 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3617 /* sanity check on interface type for support */
3618 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3619 LPFC_SLI_INTF_IF_TYPE_2
) {
3623 /* nemb_tp == nemb_hbd */
3624 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3625 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3626 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3627 "2946 Handled SLI_CONFIG(hbd) rd, "
3628 "ext_buf_cnt(%d) out of range(%d)\n",
3630 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3634 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3635 "2942 Handled SLI_CONFIG(hbd) rd, "
3636 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3639 /* before dma descriptor setup */
3640 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3641 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3643 /* reject non-embedded mailbox command with none external buffer */
3644 if (ext_buf_cnt
== 0) {
3647 } else if (ext_buf_cnt
> 1) {
3648 /* additional external read buffers */
3649 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3650 ext_dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
3655 list_add_tail(&ext_dmabuf
->list
,
3656 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3660 /* bsg tracking structure */
3661 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3667 /* mailbox command structure for base driver */
3668 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3673 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3675 /* for the first external buffer */
3676 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3678 /* for the rest of external buffer descriptors if any */
3679 if (ext_buf_cnt
> 1) {
3681 list_for_each_entry_safe(curr_dmabuf
, next_dmabuf
,
3682 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
, list
) {
3683 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
,
3684 ext_buf_index
, dmabuf
,
3690 /* after dma descriptor setup */
3691 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_rd
, dma_mbox
,
3692 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3694 /* construct base driver mbox command */
3695 pmb
= &pmboxq
->u
.mb
;
3696 pmbx
= (uint8_t *)dmabuf
->virt
;
3697 memcpy(pmb
, pmbx
, sizeof(*pmb
));
3698 pmb
->mbxOwner
= OWN_HOST
;
3699 pmboxq
->vport
= phba
->pport
;
3701 /* multi-buffer handling context */
3702 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3703 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_rd
;
3704 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3705 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3706 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3707 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3709 /* callback for multi-buffer read mailbox command */
3710 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_read_mbox_ext_cmpl
;
3712 /* context fields to callback function */
3713 pmboxq
->context1
= dd_data
;
3714 dd_data
->type
= TYPE_MBOX
;
3715 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3716 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
3717 dd_data
->context_un
.mbox
.set_job
= job
;
3718 job
->dd_data
= dd_data
;
3721 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3724 * Non-embedded mailbox subcommand data gets byte swapped here because
3725 * the lower level driver code only does the first 64 mailbox words.
3727 if ((!bsg_bf_get(lpfc_mbox_hdr_emb
,
3728 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) &&
3729 (nemb_tp
== nemb_mse
))
3730 lpfc_sli_pcimem_bcopy(&pmbx
[sizeof(MAILBOX_t
)],
3731 &pmbx
[sizeof(MAILBOX_t
)],
3732 sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3735 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3736 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3737 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3738 "2947 Issued SLI_CONFIG ext-buffer "
3739 "maibox command, rc:x%x\n", rc
);
3740 return SLI_CONFIG_HANDLED
;
3742 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3743 "2948 Failed to issue SLI_CONFIG ext-buffer "
3744 "maibox command, rc:x%x\n", rc
);
3749 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3750 lpfc_bsg_dma_page_list_free(phba
,
3751 &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
3753 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
3758 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
3759 * @phba: Pointer to HBA context object.
3760 * @mb: Pointer to a BSG mailbox object.
3761 * @dmabuff: Pointer to a DMA buffer descriptor.
3763 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
3764 * non-embedded external bufffers.
3767 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3768 enum nemb_type nemb_tp
,
3769 struct lpfc_dmabuf
*dmabuf
)
3771 struct dfc_mbox_req
*mbox_req
;
3772 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3773 uint32_t ext_buf_cnt
;
3774 struct bsg_job_data
*dd_data
= NULL
;
3775 LPFC_MBOXQ_t
*pmboxq
= NULL
;
3778 int rc
= SLI_CONFIG_NOT_HANDLED
, i
;
3781 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
3783 /* pointer to the start of mailbox command */
3784 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3786 if (nemb_tp
== nemb_mse
) {
3787 ext_buf_cnt
= bsg_bf_get(lpfc_mbox_hdr_mse_cnt
,
3788 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
);
3789 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_MSE
) {
3790 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3791 "2953 Failed SLI_CONFIG(mse) wr, "
3792 "ext_buf_cnt(%d) out of range(%d)\n",
3794 LPFC_MBX_SLI_CONFIG_MAX_MSE
);
3797 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3798 "2949 Handled SLI_CONFIG(mse) wr, "
3799 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3801 /* sanity check on interface type for support */
3802 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3803 LPFC_SLI_INTF_IF_TYPE_2
)
3805 /* nemb_tp == nemb_hbd */
3806 ext_buf_cnt
= sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd_count
;
3807 if (ext_buf_cnt
> LPFC_MBX_SLI_CONFIG_MAX_HBD
) {
3808 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3809 "2954 Failed SLI_CONFIG(hbd) wr, "
3810 "ext_buf_cnt(%d) out of range(%d)\n",
3812 LPFC_MBX_SLI_CONFIG_MAX_HBD
);
3815 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3816 "2950 Handled SLI_CONFIG(hbd) wr, "
3817 "ext_buf_cnt:%d\n", ext_buf_cnt
);
3820 /* before dma buffer descriptor setup */
3821 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3822 sta_pre_addr
, dmabuf
, ext_buf_cnt
);
3824 if (ext_buf_cnt
== 0)
3827 /* for the first external buffer */
3828 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, 0, dmabuf
, dmabuf
);
3830 /* after dma descriptor setup */
3831 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, nemb_tp
, mbox_wr
, dma_mbox
,
3832 sta_pos_addr
, dmabuf
, ext_buf_cnt
);
3834 /* log for looking forward */
3835 for (i
= 1; i
< ext_buf_cnt
; i
++) {
3836 if (nemb_tp
== nemb_mse
)
3837 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3838 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
3839 i
, sli_cfg_mbx
->un
.sli_config_emb0_subsys
.
3842 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3843 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
3844 i
, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
3845 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.
3849 /* multi-buffer handling context */
3850 phba
->mbox_ext_buf_ctx
.nembType
= nemb_tp
;
3851 phba
->mbox_ext_buf_ctx
.mboxType
= mbox_wr
;
3852 phba
->mbox_ext_buf_ctx
.numBuf
= ext_buf_cnt
;
3853 phba
->mbox_ext_buf_ctx
.mbxTag
= mbox_req
->extMboxTag
;
3854 phba
->mbox_ext_buf_ctx
.seqNum
= mbox_req
->extSeqNum
;
3855 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
= dmabuf
;
3857 if (ext_buf_cnt
== 1) {
3858 /* bsg tracking structure */
3859 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
3865 /* mailbox command structure for base driver */
3866 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3871 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3872 pmb
= &pmboxq
->u
.mb
;
3873 mbx
= (uint8_t *)dmabuf
->virt
;
3874 memcpy(pmb
, mbx
, sizeof(*pmb
));
3875 pmb
->mbxOwner
= OWN_HOST
;
3876 pmboxq
->vport
= phba
->pport
;
3878 /* callback for multi-buffer read mailbox command */
3879 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
3881 /* context fields to callback function */
3882 pmboxq
->context1
= dd_data
;
3883 dd_data
->type
= TYPE_MBOX
;
3884 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
3885 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)mbx
;
3886 dd_data
->context_un
.mbox
.set_job
= job
;
3887 job
->dd_data
= dd_data
;
3890 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
3892 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
3893 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
3894 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3895 "2955 Issued SLI_CONFIG ext-buffer "
3896 "maibox command, rc:x%x\n", rc
);
3897 return SLI_CONFIG_HANDLED
;
3899 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
3900 "2956 Failed to issue SLI_CONFIG ext-buffer "
3901 "maibox command, rc:x%x\n", rc
);
3906 /* wait for additoinal external buffers */
3907 job
->reply
->result
= 0;
3909 return SLI_CONFIG_HANDLED
;
3913 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3920 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
3921 * @phba: Pointer to HBA context object.
3922 * @mb: Pointer to a BSG mailbox object.
3923 * @dmabuff: Pointer to a DMA buffer descriptor.
3925 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
3926 * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
3927 * with embedded sussystem 0x1 and opcodes with external HBDs.
3930 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
3931 struct lpfc_dmabuf
*dmabuf
)
3933 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
3936 int rc
= SLI_CONFIG_NOT_HANDLED
;
3938 /* state change on new multi-buffer pass-through mailbox command */
3939 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_HOST
;
3941 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)dmabuf
->virt
;
3943 if (!bsg_bf_get(lpfc_mbox_hdr_emb
,
3944 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.sli_config_hdr
)) {
3945 subsys
= bsg_bf_get(lpfc_emb0_subcmnd_subsys
,
3946 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3947 opcode
= bsg_bf_get(lpfc_emb0_subcmnd_opcode
,
3948 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
);
3949 if (subsys
== SLI_CONFIG_SUBSYS_FCOE
) {
3951 case FCOE_OPCODE_READ_FCF
:
3952 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3953 "2957 Handled SLI_CONFIG "
3954 "subsys_fcoe, opcode:x%x\n",
3956 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3959 case FCOE_OPCODE_ADD_FCF
:
3960 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3961 "2958 Handled SLI_CONFIG "
3962 "subsys_fcoe, opcode:x%x\n",
3964 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
3968 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3969 "2959 Reject SLI_CONFIG "
3970 "subsys_fcoe, opcode:x%x\n",
3975 } else if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
3977 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES
:
3978 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3979 "3106 Handled SLI_CONFIG "
3980 "subsys_fcoe, opcode:x%x\n",
3982 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
3986 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3987 "3107 Reject SLI_CONFIG "
3988 "subsys_fcoe, opcode:x%x\n",
3994 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
3995 "2977 Reject SLI_CONFIG "
3996 "subsys:x%d, opcode:x%x\n",
4001 subsys
= bsg_bf_get(lpfc_emb1_subcmnd_subsys
,
4002 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4003 opcode
= bsg_bf_get(lpfc_emb1_subcmnd_opcode
,
4004 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
);
4005 if (subsys
== SLI_CONFIG_SUBSYS_COMN
) {
4007 case COMN_OPCODE_READ_OBJECT
:
4008 case COMN_OPCODE_READ_OBJECT_LIST
:
4009 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4010 "2960 Handled SLI_CONFIG "
4011 "subsys_comn, opcode:x%x\n",
4013 rc
= lpfc_bsg_sli_cfg_read_cmd_ext(phba
, job
,
4016 case COMN_OPCODE_WRITE_OBJECT
:
4017 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4018 "2961 Handled SLI_CONFIG "
4019 "subsys_comn, opcode:x%x\n",
4021 rc
= lpfc_bsg_sli_cfg_write_cmd_ext(phba
, job
,
4025 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4026 "2962 Not handled SLI_CONFIG "
4027 "subsys_comn, opcode:x%x\n",
4029 rc
= SLI_CONFIG_NOT_HANDLED
;
4033 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4034 "2978 Not handled SLI_CONFIG "
4035 "subsys:x%d, opcode:x%x\n",
4037 rc
= SLI_CONFIG_NOT_HANDLED
;
4041 /* state reset on not handled new multi-buffer mailbox command */
4042 if (rc
!= SLI_CONFIG_HANDLED
)
4043 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_IDLE
;
4049 * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
4050 * @phba: Pointer to HBA context object.
4052 * This routine is for requesting to abort a pass-through mailbox command with
4053 * multiple external buffers due to error condition.
4056 lpfc_bsg_mbox_ext_abort(struct lpfc_hba
*phba
)
4058 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
4059 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
4061 lpfc_bsg_mbox_ext_session_reset(phba
);
4066 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
4067 * @phba: Pointer to HBA context object.
4068 * @dmabuf: Pointer to a DMA buffer descriptor.
4070 * This routine extracts the next mailbox read external buffer back to
4071 * user space through BSG.
4074 lpfc_bsg_read_ebuf_get(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
)
4076 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4077 struct lpfc_dmabuf
*dmabuf
;
4082 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4083 phba
->mbox_ext_buf_ctx
.seqNum
++;
4085 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4086 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4088 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4089 size
= bsg_bf_get(lpfc_mbox_sli_config_mse_len
,
4090 &sli_cfg_mbx
->un
.sli_config_emb0_subsys
.mse
[index
]);
4091 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4092 "2963 SLI_CONFIG (mse) ext-buffer rd get "
4093 "buffer[%d], size:%d\n", index
, size
);
4095 size
= bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len
,
4096 &sli_cfg_mbx
->un
.sli_config_emb1_subsys
.hbd
[index
]);
4097 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4098 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
4099 "buffer[%d], size:%d\n", index
, size
);
4101 if (list_empty(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
))
4103 dmabuf
= list_first_entry(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
,
4104 struct lpfc_dmabuf
, list
);
4105 list_del_init(&dmabuf
->list
);
4107 /* after dma buffer descriptor setup */
4108 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4109 mbox_rd
, dma_ebuf
, sta_pos_addr
,
4112 pbuf
= (uint8_t *)dmabuf
->virt
;
4113 job
->reply
->reply_payload_rcv_len
=
4114 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4115 job
->reply_payload
.sg_cnt
,
4118 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4120 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4121 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4122 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
4123 "command session done\n");
4124 lpfc_bsg_mbox_ext_session_reset(phba
);
4127 job
->reply
->result
= 0;
4130 return SLI_CONFIG_HANDLED
;
4134 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
4135 * @phba: Pointer to HBA context object.
4136 * @dmabuf: Pointer to a DMA buffer descriptor.
4138 * This routine sets up the next mailbox read external buffer obtained
4139 * from user space through BSG.
4142 lpfc_bsg_write_ebuf_set(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4143 struct lpfc_dmabuf
*dmabuf
)
4145 struct lpfc_sli_config_mbox
*sli_cfg_mbx
;
4146 struct bsg_job_data
*dd_data
= NULL
;
4147 LPFC_MBOXQ_t
*pmboxq
= NULL
;
4149 enum nemb_type nemb_tp
;
4155 index
= phba
->mbox_ext_buf_ctx
.seqNum
;
4156 phba
->mbox_ext_buf_ctx
.seqNum
++;
4157 nemb_tp
= phba
->mbox_ext_buf_ctx
.nembType
;
4159 sli_cfg_mbx
= (struct lpfc_sli_config_mbox
*)
4160 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4162 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4168 pbuf
= (uint8_t *)dmabuf
->virt
;
4169 size
= job
->request_payload
.payload_len
;
4170 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4171 job
->request_payload
.sg_cnt
,
4174 if (phba
->mbox_ext_buf_ctx
.nembType
== nemb_mse
) {
4175 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4176 "2966 SLI_CONFIG (mse) ext-buffer wr set "
4177 "buffer[%d], size:%d\n",
4178 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4181 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4182 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
4183 "buffer[%d], size:%d\n",
4184 phba
->mbox_ext_buf_ctx
.seqNum
, size
);
4188 /* set up external buffer descriptor and add to external buffer list */
4189 lpfc_bsg_sli_cfg_dma_desc_setup(phba
, nemb_tp
, index
,
4190 phba
->mbox_ext_buf_ctx
.mbx_dmabuf
,
4192 list_add_tail(&dmabuf
->list
, &phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4194 /* after write dma buffer */
4195 lpfc_idiag_mbxacc_dump_bsg_mbox(phba
, phba
->mbox_ext_buf_ctx
.nembType
,
4196 mbox_wr
, dma_ebuf
, sta_pos_addr
,
4199 if (phba
->mbox_ext_buf_ctx
.seqNum
== phba
->mbox_ext_buf_ctx
.numBuf
) {
4200 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4201 "2968 SLI_CONFIG ext-buffer wr all %d "
4202 "ebuffers received\n",
4203 phba
->mbox_ext_buf_ctx
.numBuf
);
4204 /* mailbox command structure for base driver */
4205 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4210 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4211 pbuf
= (uint8_t *)phba
->mbox_ext_buf_ctx
.mbx_dmabuf
->virt
;
4212 pmb
= &pmboxq
->u
.mb
;
4213 memcpy(pmb
, pbuf
, sizeof(*pmb
));
4214 pmb
->mbxOwner
= OWN_HOST
;
4215 pmboxq
->vport
= phba
->pport
;
4217 /* callback for multi-buffer write mailbox command */
4218 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_write_mbox_ext_cmpl
;
4220 /* context fields to callback function */
4221 pmboxq
->context1
= dd_data
;
4222 dd_data
->type
= TYPE_MBOX
;
4223 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4224 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pbuf
;
4225 dd_data
->context_un
.mbox
.set_job
= job
;
4226 job
->dd_data
= dd_data
;
4229 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_PORT
;
4231 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4232 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
)) {
4233 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4234 "2969 Issued SLI_CONFIG ext-buffer "
4235 "maibox command, rc:x%x\n", rc
);
4236 return SLI_CONFIG_HANDLED
;
4238 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4239 "2970 Failed to issue SLI_CONFIG ext-buffer "
4240 "maibox command, rc:x%x\n", rc
);
4245 /* wait for additoinal external buffers */
4246 job
->reply
->result
= 0;
4248 return SLI_CONFIG_HANDLED
;
4251 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4258 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4259 * @phba: Pointer to HBA context object.
4260 * @mb: Pointer to a BSG mailbox object.
4261 * @dmabuff: Pointer to a DMA buffer descriptor.
4263 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4264 * command with multiple non-embedded external buffers.
4267 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4268 struct lpfc_dmabuf
*dmabuf
)
4272 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4273 "2971 SLI_CONFIG buffer (type:x%x)\n",
4274 phba
->mbox_ext_buf_ctx
.mboxType
);
4276 if (phba
->mbox_ext_buf_ctx
.mboxType
== mbox_rd
) {
4277 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_DONE
) {
4278 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4279 "2972 SLI_CONFIG rd buffer state "
4281 phba
->mbox_ext_buf_ctx
.state
);
4282 lpfc_bsg_mbox_ext_abort(phba
);
4285 rc
= lpfc_bsg_read_ebuf_get(phba
, job
);
4286 if (rc
== SLI_CONFIG_HANDLED
)
4287 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4288 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4289 if (phba
->mbox_ext_buf_ctx
.state
!= LPFC_BSG_MBOX_HOST
) {
4290 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4291 "2973 SLI_CONFIG wr buffer state "
4293 phba
->mbox_ext_buf_ctx
.state
);
4294 lpfc_bsg_mbox_ext_abort(phba
);
4297 rc
= lpfc_bsg_write_ebuf_set(phba
, job
, dmabuf
);
4303 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4304 * @phba: Pointer to HBA context object.
4305 * @mb: Pointer to a BSG mailbox object.
4306 * @dmabuff: Pointer to a DMA buffer descriptor.
4308 * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
4309 * (0x9B) mailbox commands and external buffers.
4312 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4313 struct lpfc_dmabuf
*dmabuf
)
4315 struct dfc_mbox_req
*mbox_req
;
4316 int rc
= SLI_CONFIG_NOT_HANDLED
;
4319 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4321 /* mbox command with/without single external buffer */
4322 if (mbox_req
->extMboxTag
== 0 && mbox_req
->extSeqNum
== 0)
4325 /* mbox command and first external buffer */
4326 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_IDLE
) {
4327 if (mbox_req
->extSeqNum
== 1) {
4328 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4329 "2974 SLI_CONFIG mailbox: tag:%d, "
4330 "seq:%d\n", mbox_req
->extMboxTag
,
4331 mbox_req
->extSeqNum
);
4332 rc
= lpfc_bsg_handle_sli_cfg_mbox(phba
, job
, dmabuf
);
4335 goto sli_cfg_ext_error
;
4339 * handle additional external buffers
4342 /* check broken pipe conditions */
4343 if (mbox_req
->extMboxTag
!= phba
->mbox_ext_buf_ctx
.mbxTag
)
4344 goto sli_cfg_ext_error
;
4345 if (mbox_req
->extSeqNum
> phba
->mbox_ext_buf_ctx
.numBuf
)
4346 goto sli_cfg_ext_error
;
4347 if (mbox_req
->extSeqNum
!= phba
->mbox_ext_buf_ctx
.seqNum
+ 1)
4348 goto sli_cfg_ext_error
;
4350 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4351 "2975 SLI_CONFIG mailbox external buffer: "
4352 "extSta:x%x, tag:%d, seq:%d\n",
4353 phba
->mbox_ext_buf_ctx
.state
, mbox_req
->extMboxTag
,
4354 mbox_req
->extSeqNum
);
4355 rc
= lpfc_bsg_handle_sli_cfg_ebuf(phba
, job
, dmabuf
);
4359 /* all other cases, broken pipe */
4360 lpfc_printf_log(phba
, KERN_ERR
, LOG_LIBDFC
,
4361 "2976 SLI_CONFIG mailbox broken pipe: "
4362 "ctxSta:x%x, ctxNumBuf:%d "
4363 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4364 phba
->mbox_ext_buf_ctx
.state
,
4365 phba
->mbox_ext_buf_ctx
.numBuf
,
4366 phba
->mbox_ext_buf_ctx
.mbxTag
,
4367 phba
->mbox_ext_buf_ctx
.seqNum
,
4368 mbox_req
->extMboxTag
, mbox_req
->extSeqNum
);
4370 lpfc_bsg_mbox_ext_session_reset(phba
);
4376 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4377 * @phba: Pointer to HBA context object.
4378 * @mb: Pointer to a mailbox object.
4379 * @vport: Pointer to a vport object.
4381 * Allocate a tracking object, mailbox command memory, get a mailbox
4382 * from the mailbox pool, copy the caller mailbox command.
4384 * If offline and the sli is active we need to poll for the command (port is
4385 * being reset) and com-plete the job, otherwise issue the mailbox command and
4386 * let our completion handler finish the command.
4389 lpfc_bsg_issue_mbox(struct lpfc_hba
*phba
, struct fc_bsg_job
*job
,
4390 struct lpfc_vport
*vport
)
4392 LPFC_MBOXQ_t
*pmboxq
= NULL
; /* internal mailbox queue */
4393 MAILBOX_t
*pmb
; /* shortcut to the pmboxq mailbox */
4394 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4395 uint8_t *pmbx
= NULL
;
4396 struct bsg_job_data
*dd_data
= NULL
; /* bsg data tracking structure */
4397 struct lpfc_dmabuf
*dmabuf
= NULL
;
4398 struct dfc_mbox_req
*mbox_req
;
4399 struct READ_EVENT_LOG_VAR
*rdEventLog
;
4400 uint32_t transmit_length
, receive_length
, mode
;
4401 struct lpfc_mbx_sli4_config
*sli4_config
;
4402 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
4403 struct mbox_header
*header
;
4404 struct ulp_bde64
*bde
;
4405 uint8_t *ext
= NULL
;
4411 /* in case no data is transferred */
4412 job
->reply
->reply_payload_rcv_len
= 0;
4414 /* sanity check to protect driver */
4415 if (job
->reply_payload
.payload_len
> BSG_MBOX_SIZE
||
4416 job
->request_payload
.payload_len
> BSG_MBOX_SIZE
) {
4422 * Don't allow mailbox commands to be sent when blocked or when in
4423 * the middle of discovery
4425 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4431 (struct dfc_mbox_req
*)job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4433 /* check if requested extended data lengths are valid */
4434 if ((mbox_req
->inExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t)) ||
4435 (mbox_req
->outExtWLen
> BSG_MBOX_SIZE
/sizeof(uint32_t))) {
4440 dmabuf
= lpfc_bsg_dma_page_alloc(phba
);
4441 if (!dmabuf
|| !dmabuf
->virt
) {
4446 /* Get the mailbox command or external buffer from BSG */
4447 pmbx
= (uint8_t *)dmabuf
->virt
;
4448 size
= job
->request_payload
.payload_len
;
4449 sg_copy_to_buffer(job
->request_payload
.sg_list
,
4450 job
->request_payload
.sg_cnt
, pmbx
, size
);
4452 /* Handle possible SLI_CONFIG with non-embedded payloads */
4453 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4454 rc
= lpfc_bsg_handle_sli_cfg_ext(phba
, job
, dmabuf
);
4455 if (rc
== SLI_CONFIG_HANDLED
)
4459 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4462 rc
= lpfc_bsg_check_cmd_access(phba
, (MAILBOX_t
*)pmbx
, vport
);
4464 goto job_done
; /* must be negative */
4466 /* allocate our bsg tracking structure */
4467 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4469 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4470 "2727 Failed allocation of dd_data\n");
4475 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4480 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4482 pmb
= &pmboxq
->u
.mb
;
4483 memcpy(pmb
, pmbx
, sizeof(*pmb
));
4484 pmb
->mbxOwner
= OWN_HOST
;
4485 pmboxq
->vport
= vport
;
4487 /* If HBA encountered an error attention, allow only DUMP
4488 * or RESTART mailbox commands until the HBA is restarted.
4490 if (phba
->pport
->stopped
&&
4491 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4492 pmb
->mbxCommand
!= MBX_RESTART
&&
4493 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4494 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4495 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4496 "2797 mbox: Issued mailbox cmd "
4497 "0x%x while in stopped state.\n",
4500 /* extended mailbox commands will need an extended buffer */
4501 if (mbox_req
->inExtWLen
|| mbox_req
->outExtWLen
) {
4503 ext
= from
+ sizeof(MAILBOX_t
);
4504 pmboxq
->context2
= ext
;
4505 pmboxq
->in_ext_byte_len
=
4506 mbox_req
->inExtWLen
* sizeof(uint32_t);
4507 pmboxq
->out_ext_byte_len
=
4508 mbox_req
->outExtWLen
* sizeof(uint32_t);
4509 pmboxq
->mbox_offset_word
= mbox_req
->mbOffset
;
4512 /* biu diag will need a kernel buffer to transfer the data
4513 * allocate our own buffer and setup the mailbox command to
4516 if (pmb
->mbxCommand
== MBX_RUN_BIU_DIAG64
) {
4517 transmit_length
= pmb
->un
.varWords
[1];
4518 receive_length
= pmb
->un
.varWords
[4];
4519 /* transmit length cannot be greater than receive length or
4520 * mailbox extension size
4522 if ((transmit_length
> receive_length
) ||
4523 (transmit_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4527 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrHigh
=
4528 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4529 pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.addrLow
=
4530 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
));
4532 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrHigh
=
4533 putPaddrHigh(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4534 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4535 pmb
->un
.varBIUdiag
.un
.s2
.rcv_bde64
.addrLow
=
4536 putPaddrLow(dmabuf
->phys
+ sizeof(MAILBOX_t
)
4537 + pmb
->un
.varBIUdiag
.un
.s2
.xmit_bde64
.tus
.f
.bdeSize
);
4538 } else if (pmb
->mbxCommand
== MBX_READ_EVENT_LOG
) {
4539 rdEventLog
= &pmb
->un
.varRdEventLog
;
4540 receive_length
= rdEventLog
->rcv_bde64
.tus
.f
.bdeSize
;
4541 mode
= bf_get(lpfc_event_log
, rdEventLog
);
4543 /* receive length cannot be greater than mailbox
4546 if (receive_length
> BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4551 /* mode zero uses a bde like biu diags command */
4553 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4554 + sizeof(MAILBOX_t
));
4555 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4556 + sizeof(MAILBOX_t
));
4558 } else if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4559 if (pmb
->mbxCommand
== MBX_DUMP_MEMORY
) {
4560 /* rebuild the command for sli4 using our own buffers
4561 * like we do for biu diags
4563 receive_length
= pmb
->un
.varWords
[2];
4564 /* receive length cannot be greater than mailbox
4567 if (receive_length
== 0) {
4571 pmb
->un
.varWords
[3] = putPaddrLow(dmabuf
->phys
4572 + sizeof(MAILBOX_t
));
4573 pmb
->un
.varWords
[4] = putPaddrHigh(dmabuf
->phys
4574 + sizeof(MAILBOX_t
));
4575 } else if ((pmb
->mbxCommand
== MBX_UPDATE_CFG
) &&
4576 pmb
->un
.varUpdateCfg
.co
) {
4577 bde
= (struct ulp_bde64
*)&pmb
->un
.varWords
[4];
4579 /* bde size cannot be greater than mailbox ext size */
4580 if (bde
->tus
.f
.bdeSize
>
4581 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
)) {
4585 bde
->addrHigh
= putPaddrHigh(dmabuf
->phys
4586 + sizeof(MAILBOX_t
));
4587 bde
->addrLow
= putPaddrLow(dmabuf
->phys
4588 + sizeof(MAILBOX_t
));
4589 } else if (pmb
->mbxCommand
== MBX_SLI4_CONFIG
) {
4590 /* Handling non-embedded SLI_CONFIG mailbox command */
4591 sli4_config
= &pmboxq
->u
.mqe
.un
.sli4_config
;
4592 if (!bf_get(lpfc_mbox_hdr_emb
,
4593 &sli4_config
->header
.cfg_mhdr
)) {
4594 /* rebuild the command for sli4 using our
4595 * own buffers like we do for biu diags
4597 header
= (struct mbox_header
*)
4598 &pmb
->un
.varWords
[0];
4599 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
4600 &pmb
->un
.varWords
[0];
4601 receive_length
= nembed_sge
->sge
[0].length
;
4603 /* receive length cannot be greater than
4604 * mailbox extension size
4606 if ((receive_length
== 0) ||
4608 BSG_MBOX_SIZE
- sizeof(MAILBOX_t
))) {
4613 nembed_sge
->sge
[0].pa_hi
=
4614 putPaddrHigh(dmabuf
->phys
4615 + sizeof(MAILBOX_t
));
4616 nembed_sge
->sge
[0].pa_lo
=
4617 putPaddrLow(dmabuf
->phys
4618 + sizeof(MAILBOX_t
));
4623 dd_data
->context_un
.mbox
.dmabuffers
= dmabuf
;
4625 /* setup wake call as IOCB callback */
4626 pmboxq
->mbox_cmpl
= lpfc_bsg_issue_mbox_cmpl
;
4628 /* setup context field to pass wait_queue pointer to wake function */
4629 pmboxq
->context1
= dd_data
;
4630 dd_data
->type
= TYPE_MBOX
;
4631 dd_data
->context_un
.mbox
.pmboxq
= pmboxq
;
4632 dd_data
->context_un
.mbox
.mb
= (MAILBOX_t
*)pmbx
;
4633 dd_data
->context_un
.mbox
.set_job
= job
;
4634 dd_data
->context_un
.mbox
.ext
= ext
;
4635 dd_data
->context_un
.mbox
.mbOffset
= mbox_req
->mbOffset
;
4636 dd_data
->context_un
.mbox
.inExtWLen
= mbox_req
->inExtWLen
;
4637 dd_data
->context_un
.mbox
.outExtWLen
= mbox_req
->outExtWLen
;
4638 job
->dd_data
= dd_data
;
4640 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4641 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4642 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4643 if (rc
!= MBX_SUCCESS
) {
4644 rc
= (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4648 /* job finished, copy the data */
4649 memcpy(pmbx
, pmb
, sizeof(*pmb
));
4650 job
->reply
->reply_payload_rcv_len
=
4651 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
4652 job
->reply_payload
.sg_cnt
,
4654 /* not waiting mbox already done */
4659 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
4660 if ((rc
== MBX_SUCCESS
) || (rc
== MBX_BUSY
))
4661 return 1; /* job started */
4664 /* common exit for error or job completed inline */
4666 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4667 lpfc_bsg_dma_page_free(phba
, dmabuf
);
4675 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
4676 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
4679 lpfc_bsg_mbox_cmd(struct fc_bsg_job
*job
)
4681 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4682 struct lpfc_hba
*phba
= vport
->phba
;
4683 struct dfc_mbox_req
*mbox_req
;
4686 /* mix-and-match backward compatibility */
4687 job
->reply
->reply_payload_rcv_len
= 0;
4688 if (job
->request_len
<
4689 sizeof(struct fc_bsg_request
) + sizeof(struct dfc_mbox_req
)) {
4690 lpfc_printf_log(phba
, KERN_INFO
, LOG_LIBDFC
,
4691 "2737 Mix-and-match backward compability "
4692 "between MBOX_REQ old size:%d and "
4693 "new request size:%d\n",
4694 (int)(job
->request_len
-
4695 sizeof(struct fc_bsg_request
)),
4696 (int)sizeof(struct dfc_mbox_req
));
4697 mbox_req
= (struct dfc_mbox_req
*)
4698 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4699 mbox_req
->extMboxTag
= 0;
4700 mbox_req
->extSeqNum
= 0;
4703 rc
= lpfc_bsg_issue_mbox(phba
, job
, vport
);
4707 job
->reply
->result
= 0;
4708 job
->dd_data
= NULL
;
4711 /* job submitted, will complete later*/
4712 rc
= 0; /* return zero, no error */
4714 /* some error occurred */
4715 job
->reply
->result
= rc
;
4716 job
->dd_data
= NULL
;
4723 * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
4724 * @phba: Pointer to HBA context object.
4725 * @cmdiocbq: Pointer to command iocb.
4726 * @rspiocbq: Pointer to response iocb.
4728 * This function is the completion handler for iocbs issued using
4729 * lpfc_menlo_cmd function. This function is called by the
4730 * ring event handler function without any lock held. This function
4731 * can be called from both worker thread context and interrupt
4732 * context. This function also can be called from another thread which
4733 * cleans up the SLI layer objects.
4734 * This function copies the contents of the response iocb to the
4735 * response iocb memory object provided by the caller of
4736 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4737 * sleeps for the iocb completion.
4740 lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba
*phba
,
4741 struct lpfc_iocbq
*cmdiocbq
,
4742 struct lpfc_iocbq
*rspiocbq
)
4744 struct bsg_job_data
*dd_data
;
4745 struct fc_bsg_job
*job
;
4747 struct lpfc_dmabuf
*bmp
;
4748 struct lpfc_bsg_menlo
*menlo
;
4749 unsigned long flags
;
4750 struct menlo_response
*menlo_resp
;
4753 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
4754 dd_data
= cmdiocbq
->context1
;
4756 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4760 menlo
= &dd_data
->context_un
.menlo
;
4761 job
= menlo
->set_job
;
4762 job
->dd_data
= NULL
; /* so timeout handler does not reply */
4764 spin_lock(&phba
->hbalock
);
4765 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
4766 if (cmdiocbq
->context2
&& rspiocbq
)
4767 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
4768 &rspiocbq
->iocb
, sizeof(IOCB_t
));
4769 spin_unlock(&phba
->hbalock
);
4772 rspiocbq
= menlo
->rspiocbq
;
4773 rsp
= &rspiocbq
->iocb
;
4775 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4776 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4777 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4778 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4780 /* always return the xri, this would be used in the case
4781 * of a menlo download to allow the data to be sent as a continuation
4784 menlo_resp
= (struct menlo_response
*)
4785 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4786 menlo_resp
->xri
= rsp
->ulpContext
;
4787 if (rsp
->ulpStatus
) {
4788 if (rsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
4789 switch (rsp
->un
.ulpWord
[4] & 0xff) {
4790 case IOERR_SEQUENCE_TIMEOUT
:
4793 case IOERR_INVALID_RPI
:
4803 job
->reply
->reply_payload_rcv_len
=
4804 rsp
->un
.genreq64
.bdl
.bdeSize
;
4806 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
4807 lpfc_sli_release_iocbq(phba
, rspiocbq
);
4808 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
4811 /* make error code available to userspace */
4812 job
->reply
->result
= rc
;
4813 /* complete the job back to userspace */
4815 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
4820 * lpfc_menlo_cmd - send an ioctl for menlo hardware
4821 * @job: fc_bsg_job to handle
4823 * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
4824 * all the command completions will return the xri for the command.
4825 * For menlo data requests a gen request 64 CX is used to continue the exchange
4826 * supplied in the menlo request header xri field.
4829 lpfc_menlo_cmd(struct fc_bsg_job
*job
)
4831 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
4832 struct lpfc_hba
*phba
= vport
->phba
;
4833 struct lpfc_iocbq
*cmdiocbq
, *rspiocbq
;
4836 struct menlo_command
*menlo_cmd
;
4837 struct menlo_response
*menlo_resp
;
4838 struct lpfc_dmabuf
*bmp
= NULL
;
4841 struct scatterlist
*sgel
= NULL
;
4844 struct bsg_job_data
*dd_data
;
4845 struct ulp_bde64
*bpl
= NULL
;
4847 /* in case no data is returned return just the return code */
4848 job
->reply
->reply_payload_rcv_len
= 0;
4850 if (job
->request_len
<
4851 sizeof(struct fc_bsg_request
) +
4852 sizeof(struct menlo_command
)) {
4853 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4854 "2784 Received MENLO_CMD request below "
4860 if (job
->reply_len
<
4861 sizeof(struct fc_bsg_request
) + sizeof(struct menlo_response
)) {
4862 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4863 "2785 Received MENLO_CMD reply below "
4869 if (!(phba
->menlo_flag
& HBA_MENLO_SUPPORT
)) {
4870 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4871 "2786 Adapter does not support menlo "
4877 menlo_cmd
= (struct menlo_command
*)
4878 job
->request
->rqst_data
.h_vendor
.vendor_cmd
;
4880 menlo_resp
= (struct menlo_response
*)
4881 job
->reply
->reply_data
.vendor_reply
.vendor_rsp
;
4883 /* allocate our bsg tracking structure */
4884 dd_data
= kmalloc(sizeof(struct bsg_job_data
), GFP_KERNEL
);
4886 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LIBDFC
,
4887 "2787 Failed allocation of dd_data\n");
4892 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4898 cmdiocbq
= lpfc_sli_get_iocbq(phba
);
4904 rspiocbq
= lpfc_sli_get_iocbq(phba
);
4910 rsp
= &rspiocbq
->iocb
;
4912 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &bmp
->phys
);
4918 INIT_LIST_HEAD(&bmp
->list
);
4919 bpl
= (struct ulp_bde64
*) bmp
->virt
;
4920 request_nseg
= pci_map_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4921 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4922 for_each_sg(job
->request_payload
.sg_list
, sgel
, request_nseg
, numbde
) {
4923 busaddr
= sg_dma_address(sgel
);
4924 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
4925 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4926 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4927 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4928 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4932 reply_nseg
= pci_map_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4933 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4934 for_each_sg(job
->reply_payload
.sg_list
, sgel
, reply_nseg
, numbde
) {
4935 busaddr
= sg_dma_address(sgel
);
4936 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
4937 bpl
->tus
.f
.bdeSize
= sg_dma_len(sgel
);
4938 bpl
->tus
.w
= cpu_to_le32(bpl
->tus
.w
);
4939 bpl
->addrLow
= cpu_to_le32(putPaddrLow(busaddr
));
4940 bpl
->addrHigh
= cpu_to_le32(putPaddrHigh(busaddr
));
4944 cmd
= &cmdiocbq
->iocb
;
4945 cmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
4946 cmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
4947 cmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
4948 cmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
4949 cmd
->un
.genreq64
.bdl
.bdeSize
=
4950 (request_nseg
+ reply_nseg
) * sizeof(struct ulp_bde64
);
4951 cmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
4952 cmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
4953 cmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CMD
;
4954 cmd
->un
.genreq64
.w5
.hcsw
.Type
= MENLO_TRANSPORT_TYPE
; /* 0xfe */
4955 cmd
->ulpBdeCount
= 1;
4956 cmd
->ulpClass
= CLASS3
;
4957 cmd
->ulpOwner
= OWN_CHIP
;
4958 cmd
->ulpLe
= 1; /* Limited Edition */
4959 cmdiocbq
->iocb_flag
|= LPFC_IO_LIBDFC
;
4960 cmdiocbq
->vport
= phba
->pport
;
4961 /* We want the firmware to timeout before we do */
4962 cmd
->ulpTimeout
= MENLO_TIMEOUT
- 5;
4963 cmdiocbq
->context3
= bmp
;
4964 cmdiocbq
->context2
= rspiocbq
;
4965 cmdiocbq
->iocb_cmpl
= lpfc_bsg_menlo_cmd_cmp
;
4966 cmdiocbq
->context1
= dd_data
;
4967 cmdiocbq
->context2
= rspiocbq
;
4968 if (menlo_cmd
->cmd
== LPFC_BSG_VENDOR_MENLO_CMD
) {
4969 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
4970 cmd
->ulpPU
= MENLO_PU
; /* 3 */
4971 cmd
->un
.ulpWord
[4] = MENLO_DID
; /* 0x0000FC0E */
4972 cmd
->ulpContext
= MENLO_CONTEXT
; /* 0 */
4974 cmd
->ulpCommand
= CMD_GEN_REQUEST64_CX
;
4976 cmd
->un
.ulpWord
[4] = 0;
4977 cmd
->ulpContext
= menlo_cmd
->xri
;
4980 dd_data
->type
= TYPE_MENLO
;
4981 dd_data
->context_un
.menlo
.cmdiocbq
= cmdiocbq
;
4982 dd_data
->context_un
.menlo
.rspiocbq
= rspiocbq
;
4983 dd_data
->context_un
.menlo
.set_job
= job
;
4984 dd_data
->context_un
.menlo
.bmp
= bmp
;
4986 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, cmdiocbq
,
4988 if (rc
== IOCB_SUCCESS
)
4989 return 0; /* done for now */
4991 /* iocb failed so cleanup */
4992 pci_unmap_sg(phba
->pcidev
, job
->request_payload
.sg_list
,
4993 job
->request_payload
.sg_cnt
, DMA_TO_DEVICE
);
4994 pci_unmap_sg(phba
->pcidev
, job
->reply_payload
.sg_list
,
4995 job
->reply_payload
.sg_cnt
, DMA_FROM_DEVICE
);
4997 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
5000 lpfc_sli_release_iocbq(phba
, rspiocbq
);
5002 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
5008 /* make error code available to userspace */
5009 job
->reply
->result
= rc
;
5010 job
->dd_data
= NULL
;
5015 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
5016 * @job: fc_bsg_job to handle
5019 lpfc_bsg_hst_vendor(struct fc_bsg_job
*job
)
5021 int command
= job
->request
->rqst_data
.h_vendor
.vendor_cmd
[0];
5025 case LPFC_BSG_VENDOR_SET_CT_EVENT
:
5026 rc
= lpfc_bsg_hba_set_event(job
);
5028 case LPFC_BSG_VENDOR_GET_CT_EVENT
:
5029 rc
= lpfc_bsg_hba_get_event(job
);
5031 case LPFC_BSG_VENDOR_SEND_MGMT_RESP
:
5032 rc
= lpfc_bsg_send_mgmt_rsp(job
);
5034 case LPFC_BSG_VENDOR_DIAG_MODE
:
5035 rc
= lpfc_bsg_diag_loopback_mode(job
);
5037 case LPFC_BSG_VENDOR_DIAG_MODE_END
:
5038 rc
= lpfc_sli4_bsg_diag_mode_end(job
);
5040 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK
:
5041 rc
= lpfc_bsg_diag_loopback_run(job
);
5043 case LPFC_BSG_VENDOR_LINK_DIAG_TEST
:
5044 rc
= lpfc_sli4_bsg_link_diag_test(job
);
5046 case LPFC_BSG_VENDOR_GET_MGMT_REV
:
5047 rc
= lpfc_bsg_get_dfc_rev(job
);
5049 case LPFC_BSG_VENDOR_MBOX
:
5050 rc
= lpfc_bsg_mbox_cmd(job
);
5052 case LPFC_BSG_VENDOR_MENLO_CMD
:
5053 case LPFC_BSG_VENDOR_MENLO_DATA
:
5054 rc
= lpfc_menlo_cmd(job
);
5058 job
->reply
->reply_payload_rcv_len
= 0;
5059 /* make error code available to userspace */
5060 job
->reply
->result
= rc
;
5068 * lpfc_bsg_request - handle a bsg request from the FC transport
5069 * @job: fc_bsg_job to handle
5072 lpfc_bsg_request(struct fc_bsg_job
*job
)
5077 msgcode
= job
->request
->msgcode
;
5079 case FC_BSG_HST_VENDOR
:
5080 rc
= lpfc_bsg_hst_vendor(job
);
5082 case FC_BSG_RPT_ELS
:
5083 rc
= lpfc_bsg_rport_els(job
);
5086 rc
= lpfc_bsg_send_mgmt_cmd(job
);
5090 job
->reply
->reply_payload_rcv_len
= 0;
5091 /* make error code available to userspace */
5092 job
->reply
->result
= rc
;
5100 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
5101 * @job: fc_bsg_job that has timed out
5103 * This function just aborts the job's IOCB. The aborted IOCB will return to
5104 * the waiting function which will handle passing the error back to userspace
5107 lpfc_bsg_timeout(struct fc_bsg_job
*job
)
5109 struct lpfc_vport
*vport
= (struct lpfc_vport
*)job
->shost
->hostdata
;
5110 struct lpfc_hba
*phba
= vport
->phba
;
5111 struct lpfc_iocbq
*cmdiocb
;
5112 struct lpfc_bsg_event
*evt
;
5113 struct lpfc_bsg_iocb
*iocb
;
5114 struct lpfc_bsg_mbox
*mbox
;
5115 struct lpfc_bsg_menlo
*menlo
;
5116 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5117 struct bsg_job_data
*dd_data
;
5118 unsigned long flags
;
5120 spin_lock_irqsave(&phba
->ct_ev_lock
, flags
);
5121 dd_data
= (struct bsg_job_data
*)job
->dd_data
;
5122 /* timeout and completion crossed paths if no dd_data */
5124 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5128 switch (dd_data
->type
) {
5130 iocb
= &dd_data
->context_un
.iocb
;
5131 cmdiocb
= iocb
->cmdiocbq
;
5132 /* hint to completion handler that the job timed out */
5133 job
->reply
->result
= -EAGAIN
;
5134 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5135 /* this will call our completion handler */
5136 spin_lock_irq(&phba
->hbalock
);
5137 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5138 spin_unlock_irq(&phba
->hbalock
);
5141 evt
= dd_data
->context_un
.evt
;
5142 /* this event has no job anymore */
5143 evt
->set_job
= NULL
;
5144 job
->dd_data
= NULL
;
5145 job
->reply
->reply_payload_rcv_len
= 0;
5146 /* Return -EAGAIN which is our way of signallying the
5149 job
->reply
->result
= -EAGAIN
;
5150 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5154 mbox
= &dd_data
->context_un
.mbox
;
5155 /* this mbox has no job anymore */
5156 mbox
->set_job
= NULL
;
5157 job
->dd_data
= NULL
;
5158 job
->reply
->reply_payload_rcv_len
= 0;
5159 job
->reply
->result
= -EAGAIN
;
5160 /* the mbox completion handler can now be run */
5161 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5163 if (phba
->mbox_ext_buf_ctx
.state
== LPFC_BSG_MBOX_PORT
)
5164 phba
->mbox_ext_buf_ctx
.state
= LPFC_BSG_MBOX_ABTS
;
5167 menlo
= &dd_data
->context_un
.menlo
;
5168 cmdiocb
= menlo
->cmdiocbq
;
5169 /* hint to completion handler that the job timed out */
5170 job
->reply
->result
= -EAGAIN
;
5171 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5172 /* this will call our completion handler */
5173 spin_lock_irq(&phba
->hbalock
);
5174 lpfc_sli_issue_abort_iotag(phba
, pring
, cmdiocb
);
5175 spin_unlock_irq(&phba
->hbalock
);
5178 spin_unlock_irqrestore(&phba
->ct_ev_lock
, flags
);
5182 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
5183 * otherwise an error message will be displayed on the console
5184 * so always return success (zero)