1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2009-2015 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
23 #include <linux/interrupt.h>
24 #include <linux/mempool.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
28 #include <linux/list.h>
29 #include <linux/bsg-lib.h>
30 #include <linux/vmalloc.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_transport_fc.h>
35 #include <scsi/scsi_bsg_fc.h>
36 #include <scsi/fc/fc_fs.h>
41 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
45 #include "lpfc_scsi.h"
47 #include "lpfc_logmsg.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_debugfs.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_version.h"
53 struct lpfc_bsg_event {
54 struct list_head node;
58 /* Event type and waiter identifiers */
63 /* next two flags are here for the auto-delete logic */
64 unsigned long wait_time_stamp;
67 /* seen and not seen events */
68 struct list_head events_to_get;
69 struct list_head events_to_see;
71 /* driver data associated with the job */
75 struct lpfc_bsg_iocb {
76 struct lpfc_iocbq *cmdiocbq;
77 struct lpfc_dmabuf *rmp;
78 struct lpfc_nodelist *ndlp;
81 struct lpfc_bsg_mbox {
84 struct lpfc_dmabuf *dmabuffers; /* for BIU diags */
85 uint8_t *ext; /* extended mailbox data */
86 uint32_t mbOffset; /* from app */
87 uint32_t inExtWLen; /* from app */
88 uint32_t outExtWLen; /* from app */
96 struct bsg_job *set_job; /* job waiting for this iocb to finish */
98 struct lpfc_bsg_event *evt;
99 struct lpfc_bsg_iocb iocb;
100 struct lpfc_bsg_mbox mbox;
105 struct list_head node;
112 #define BUF_SZ_4K 4096
113 #define SLI_CT_ELX_LOOPBACK 0x10
115 enum ELX_LOOPBACK_CMD {
116 ELX_LOOPBACK_XRI_SETUP,
120 #define ELX_LOOPBACK_HEADER_SZ \
121 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
123 struct lpfc_dmabufext {
124 struct lpfc_dmabuf dma;
130 lpfc_free_bsg_buffers(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
132 struct lpfc_dmabuf *mlast, *next_mlast;
135 list_for_each_entry_safe(mlast, next_mlast, &mlist->list,
137 list_del(&mlast->list);
138 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
141 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
147 static struct lpfc_dmabuf *
148 lpfc_alloc_bsg_buffers(struct lpfc_hba *phba, unsigned int size,
149 int outbound_buffers, struct ulp_bde64 *bpl,
152 struct lpfc_dmabuf *mlist = NULL;
153 struct lpfc_dmabuf *mp;
154 unsigned int bytes_left = size;
156 /* Verify we can support the size specified */
157 if (!size || (size > (*bpl_entries * LPFC_BPL_SIZE)))
160 /* Determine the number of dma buffers to allocate */
161 *bpl_entries = (size % LPFC_BPL_SIZE ? size/LPFC_BPL_SIZE + 1 :
164 /* Allocate dma buffer and place in BPL passed */
166 /* Allocate dma buffer */
167 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
170 lpfc_free_bsg_buffers(phba, mlist);
174 INIT_LIST_HEAD(&mp->list);
175 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
180 lpfc_free_bsg_buffers(phba, mlist);
184 /* Queue it to a linked list */
188 list_add_tail(&mp->list, &mlist->list);
190 /* Add buffer to buffer pointer list */
191 if (outbound_buffers)
192 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
194 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
195 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
196 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
197 bpl->tus.f.bdeSize = (uint16_t)
198 (bytes_left >= LPFC_BPL_SIZE ? LPFC_BPL_SIZE :
200 bytes_left -= bpl->tus.f.bdeSize;
201 bpl->tus.w = le32_to_cpu(bpl->tus.w);
208 lpfc_bsg_copy_data(struct lpfc_dmabuf *dma_buffers,
209 struct bsg_buffer *bsg_buffers,
210 unsigned int bytes_to_transfer, int to_buffers)
213 struct lpfc_dmabuf *mp;
214 unsigned int transfer_bytes, bytes_copied = 0;
215 unsigned int sg_offset, dma_offset;
216 unsigned char *dma_address, *sg_address;
217 LIST_HEAD(temp_list);
218 struct sg_mapping_iter miter;
220 unsigned int sg_flags = SG_MITER_ATOMIC;
223 list_splice_init(&dma_buffers->list, &temp_list);
224 list_add(&dma_buffers->list, &temp_list);
227 sg_flags |= SG_MITER_FROM_SG;
229 sg_flags |= SG_MITER_TO_SG;
230 sg_miter_start(&miter, bsg_buffers->sg_list, bsg_buffers->sg_cnt,
232 local_irq_save(flags);
233 sg_valid = sg_miter_next(&miter);
234 list_for_each_entry(mp, &temp_list, list) {
236 while (bytes_to_transfer && sg_valid &&
237 (dma_offset < LPFC_BPL_SIZE)) {
238 dma_address = mp->virt + dma_offset;
240 /* Continue previous partial transfer of sg */
241 sg_address = miter.addr + sg_offset;
242 transfer_bytes = miter.length - sg_offset;
244 sg_address = miter.addr;
245 transfer_bytes = miter.length;
247 if (bytes_to_transfer < transfer_bytes)
248 transfer_bytes = bytes_to_transfer;
249 if (transfer_bytes > (LPFC_BPL_SIZE - dma_offset))
250 transfer_bytes = LPFC_BPL_SIZE - dma_offset;
252 memcpy(dma_address, sg_address, transfer_bytes);
254 memcpy(sg_address, dma_address, transfer_bytes);
255 dma_offset += transfer_bytes;
256 sg_offset += transfer_bytes;
257 bytes_to_transfer -= transfer_bytes;
258 bytes_copied += transfer_bytes;
259 if (sg_offset >= miter.length) {
261 sg_valid = sg_miter_next(&miter);
265 sg_miter_stop(&miter);
266 local_irq_restore(flags);
267 list_del_init(&dma_buffers->list);
268 list_splice(&temp_list, &dma_buffers->list);
273 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
274 * @phba: Pointer to HBA context object.
275 * @cmdiocbq: Pointer to command iocb.
276 * @rspiocbq: Pointer to response iocb.
278 * This function is the completion handler for iocbs issued using
279 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
280 * ring event handler function without any lock held. This function
281 * can be called from both worker thread context and interrupt
282 * context. This function also can be called from another thread which
283 * cleans up the SLI layer objects.
284 * This function copies the contents of the response iocb to the
285 * response iocb memory object provided by the caller of
286 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
287 * sleeps for the iocb completion.
290 lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
291 struct lpfc_iocbq *cmdiocbq,
292 struct lpfc_iocbq *rspiocbq)
294 struct bsg_job_data *dd_data;
296 struct fc_bsg_reply *bsg_reply;
297 struct lpfc_dmabuf *bmp, *cmp, *rmp;
298 struct lpfc_nodelist *ndlp;
299 struct lpfc_bsg_iocb *iocb;
302 u32 ulp_status, ulp_word4, total_data_placed;
304 dd_data = cmdiocbq->context_un.dd_data;
306 /* Determine if job has been aborted */
307 spin_lock_irqsave(&phba->ct_ev_lock, flags);
308 job = dd_data->set_job;
310 bsg_reply = job->reply;
311 /* Prevent timeout handling from trying to abort job */
314 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
316 /* Close the timeout handler abort window */
317 spin_lock_irqsave(&phba->hbalock, flags);
318 cmdiocbq->cmd_flag &= ~LPFC_IO_CMD_OUTSTANDING;
319 spin_unlock_irqrestore(&phba->hbalock, flags);
321 iocb = &dd_data->context_un.iocb;
322 ndlp = iocb->cmdiocbq->ndlp;
324 cmp = cmdiocbq->cmd_dmabuf;
325 bmp = cmdiocbq->bpl_dmabuf;
326 ulp_status = get_job_ulpstatus(phba, rspiocbq);
327 ulp_word4 = get_job_word4(phba, rspiocbq);
328 total_data_placed = get_job_data_placed(phba, rspiocbq);
330 /* Copy the completed data or set the error status */
334 if (ulp_status == IOSTAT_LOCAL_REJECT) {
335 switch (ulp_word4 & IOERR_PARAM_MASK) {
336 case IOERR_SEQUENCE_TIMEOUT:
339 case IOERR_INVALID_RPI:
350 bsg_reply->reply_payload_rcv_len =
351 lpfc_bsg_copy_data(rmp, &job->reply_payload,
352 total_data_placed, 0);
356 lpfc_free_bsg_buffers(phba, cmp);
357 lpfc_free_bsg_buffers(phba, rmp);
358 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
361 lpfc_sli_release_iocbq(phba, cmdiocbq);
364 /* Complete the job if the job is still active */
367 bsg_reply->result = rc;
368 bsg_job_done(job, bsg_reply->result,
369 bsg_reply->reply_payload_rcv_len);
375 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
376 * @job: fc_bsg_job to handle
379 lpfc_bsg_send_mgmt_cmd(struct bsg_job *job)
381 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
382 struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
383 struct lpfc_hba *phba = vport->phba;
384 struct lpfc_nodelist *ndlp = rdata->pnode;
385 struct fc_bsg_reply *bsg_reply = job->reply;
386 struct ulp_bde64 *bpl = NULL;
387 struct lpfc_iocbq *cmdiocbq = NULL;
388 struct lpfc_dmabuf *bmp = NULL, *cmp = NULL, *rmp = NULL;
389 int request_nseg, reply_nseg;
391 struct bsg_job_data *dd_data;
398 /* in case no data is transferred */
399 bsg_reply->reply_payload_rcv_len = 0;
401 if (test_bit(NLP_PLOGI_SND, &ndlp->nlp_flag) ||
402 test_bit(NLP_PRLI_SND, &ndlp->nlp_flag) ||
403 test_bit(NLP_ADISC_SND, &ndlp->nlp_flag) ||
404 test_bit(NLP_LOGO_SND, &ndlp->nlp_flag) ||
405 test_bit(NLP_RNID_SND, &ndlp->nlp_flag))
408 /* allocate our bsg tracking structure */
409 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
411 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
412 "2733 Failed allocation of dd_data\n");
417 cmdiocbq = lpfc_sli_get_iocbq(phba);
423 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
428 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
434 INIT_LIST_HEAD(&bmp->list);
436 bpl = (struct ulp_bde64 *) bmp->virt;
437 request_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64);
438 cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len,
439 1, bpl, &request_nseg);
444 lpfc_bsg_copy_data(cmp, &job->request_payload,
445 job->request_payload.payload_len, 1);
448 reply_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64) - request_nseg;
449 rmp = lpfc_alloc_bsg_buffers(phba, job->reply_payload.payload_len, 0,
456 num_entry = request_nseg + reply_nseg;
458 if (phba->sli_rev == LPFC_SLI_REV4)
459 ulp_context = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
461 ulp_context = ndlp->nlp_rpi;
463 lpfc_sli_prep_gen_req(phba, cmdiocbq, bmp, ulp_context, num_entry,
466 cmdiocbq->num_bdes = num_entry;
467 cmdiocbq->vport = phba->pport;
468 cmdiocbq->cmd_dmabuf = cmp;
469 cmdiocbq->bpl_dmabuf = bmp;
470 cmdiocbq->cmd_flag |= LPFC_IO_LIBDFC;
472 cmdiocbq->cmd_cmpl = lpfc_bsg_send_mgmt_cmd_cmp;
473 cmdiocbq->context_un.dd_data = dd_data;
475 dd_data->type = TYPE_IOCB;
476 dd_data->set_job = job;
477 dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
478 dd_data->context_un.iocb.rmp = rmp;
479 job->dd_data = dd_data;
481 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
482 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
486 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
487 writel(creg_val, phba->HCregaddr);
488 readl(phba->HCregaddr); /* flush */
491 cmdiocbq->ndlp = lpfc_nlp_get(ndlp);
492 if (!cmdiocbq->ndlp) {
497 iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
498 if (iocb_stat == IOCB_SUCCESS) {
499 spin_lock_irqsave(&phba->hbalock, flags);
500 /* make sure the I/O had not been completed yet */
501 if (cmdiocbq->cmd_flag & LPFC_IO_LIBDFC) {
502 /* open up abort window to timeout handler */
503 cmdiocbq->cmd_flag |= LPFC_IO_CMD_OUTSTANDING;
505 spin_unlock_irqrestore(&phba->hbalock, flags);
506 return 0; /* done for now */
507 } else if (iocb_stat == IOCB_BUSY) {
513 /* iocb failed so cleanup */
517 lpfc_free_bsg_buffers(phba, rmp);
519 lpfc_free_bsg_buffers(phba, cmp);
522 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
525 lpfc_sli_release_iocbq(phba, cmdiocbq);
529 /* make error code available to userspace */
530 bsg_reply->result = rc;
536 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
537 * @phba: Pointer to HBA context object.
538 * @cmdiocbq: Pointer to command iocb.
539 * @rspiocbq: Pointer to response iocb.
541 * This function is the completion handler for iocbs issued using
542 * lpfc_bsg_rport_els_cmp function. This function is called by the
543 * ring event handler function without any lock held. This function
544 * can be called from both worker thread context and interrupt
545 * context. This function also can be called from other thread which
546 * cleans up the SLI layer objects.
547 * This function copies the contents of the response iocb to the
548 * response iocb memory object provided by the caller of
549 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
550 * sleeps for the iocb completion.
553 lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
554 struct lpfc_iocbq *cmdiocbq,
555 struct lpfc_iocbq *rspiocbq)
557 struct bsg_job_data *dd_data;
559 struct fc_bsg_reply *bsg_reply;
560 struct lpfc_nodelist *ndlp;
561 struct lpfc_dmabuf *pcmd = NULL, *prsp = NULL;
562 struct fc_bsg_ctels_reply *els_reply;
565 unsigned int rsp_size;
567 u32 ulp_status, ulp_word4, total_data_placed;
569 dd_data = cmdiocbq->context_un.dd_data;
570 ndlp = dd_data->context_un.iocb.ndlp;
571 cmdiocbq->ndlp = ndlp;
573 /* Determine if job has been aborted */
574 spin_lock_irqsave(&phba->ct_ev_lock, flags);
575 job = dd_data->set_job;
577 bsg_reply = job->reply;
578 /* Prevent timeout handling from trying to abort job */
581 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
583 /* Close the timeout handler abort window */
584 spin_lock_irqsave(&phba->hbalock, flags);
585 cmdiocbq->cmd_flag &= ~LPFC_IO_CMD_OUTSTANDING;
586 spin_unlock_irqrestore(&phba->hbalock, flags);
588 ulp_status = get_job_ulpstatus(phba, rspiocbq);
589 ulp_word4 = get_job_word4(phba, rspiocbq);
590 total_data_placed = get_job_data_placed(phba, rspiocbq);
591 pcmd = cmdiocbq->cmd_dmabuf;
592 prsp = (struct lpfc_dmabuf *)pcmd->list.next;
594 /* Copy the completed job data or determine the job status if job is
599 if (ulp_status == IOSTAT_SUCCESS) {
600 rsp_size = total_data_placed;
601 bsg_reply->reply_payload_rcv_len =
602 sg_copy_from_buffer(job->reply_payload.sg_list,
603 job->reply_payload.sg_cnt,
606 } else if (ulp_status == IOSTAT_LS_RJT) {
607 bsg_reply->reply_payload_rcv_len =
608 sizeof(struct fc_bsg_ctels_reply);
609 /* LS_RJT data returned in word 4 */
610 rjt_data = (uint8_t *)&ulp_word4;
611 els_reply = &bsg_reply->reply_data.ctels_reply;
612 els_reply->status = FC_CTELS_STATUS_REJECT;
613 els_reply->rjt_data.action = rjt_data[3];
614 els_reply->rjt_data.reason_code = rjt_data[2];
615 els_reply->rjt_data.reason_explanation = rjt_data[1];
616 els_reply->rjt_data.vendor_unique = rjt_data[0];
617 } else if (ulp_status == IOSTAT_LOCAL_REJECT &&
618 (ulp_word4 & IOERR_PARAM_MASK) ==
619 IOERR_SEQUENCE_TIMEOUT) {
626 lpfc_els_free_iocb(phba, cmdiocbq);
631 /* Complete the job if the job is still active */
634 bsg_reply->result = rc;
635 bsg_job_done(job, bsg_reply->result,
636 bsg_reply->reply_payload_rcv_len);
642 * lpfc_bsg_rport_els - send an ELS command from a bsg request
643 * @job: fc_bsg_job to handle
646 lpfc_bsg_rport_els(struct bsg_job *job)
648 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
649 struct lpfc_hba *phba = vport->phba;
650 struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
651 struct lpfc_nodelist *ndlp = rdata->pnode;
652 struct fc_bsg_request *bsg_request = job->request;
653 struct fc_bsg_reply *bsg_reply = job->reply;
656 struct lpfc_iocbq *cmdiocbq;
658 struct bsg_job_data *dd_data;
663 /* in case no data is transferred */
664 bsg_reply->reply_payload_rcv_len = 0;
666 /* verify the els command is not greater than the
667 * maximum ELS transfer size.
670 if (job->request_payload.payload_len > FCELSSIZE) {
675 /* allocate our bsg tracking structure */
676 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
678 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
679 "2735 Failed allocation of dd_data\n");
684 elscmd = bsg_request->rqst_data.r_els.els_code;
685 cmdsize = job->request_payload.payload_len;
687 if (!lpfc_nlp_get(ndlp)) {
692 /* We will use the allocated dma buffers by prep els iocb for command
693 * and response to ensure if the job times out and the request is freed,
694 * we won't be dma into memory that is no longer allocated to for the
697 cmdiocbq = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp,
698 ndlp->nlp_DID, elscmd);
704 /* Transfer the request payload to allocated command dma buffer */
705 sg_copy_to_buffer(job->request_payload.sg_list,
706 job->request_payload.sg_cnt,
707 cmdiocbq->cmd_dmabuf->virt,
712 if (phba->sli_rev == LPFC_SLI_REV4)
713 bf_set(wqe_ctxt_tag, &cmdiocbq->wqe.generic.wqe_com,
714 phba->sli4_hba.rpi_ids[rpi]);
716 cmdiocbq->iocb.ulpContext = rpi;
717 cmdiocbq->cmd_flag |= LPFC_IO_LIBDFC;
718 cmdiocbq->context_un.dd_data = dd_data;
719 cmdiocbq->ndlp = ndlp;
720 cmdiocbq->cmd_cmpl = lpfc_bsg_rport_els_cmp;
721 dd_data->type = TYPE_IOCB;
722 dd_data->set_job = job;
723 dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
724 dd_data->context_un.iocb.ndlp = ndlp;
725 dd_data->context_un.iocb.rmp = NULL;
726 job->dd_data = dd_data;
728 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
729 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
733 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
734 writel(creg_val, phba->HCregaddr);
735 readl(phba->HCregaddr); /* flush */
738 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
739 if (rc == IOCB_SUCCESS) {
740 spin_lock_irqsave(&phba->hbalock, flags);
741 /* make sure the I/O had not been completed/released */
742 if (cmdiocbq->cmd_flag & LPFC_IO_LIBDFC) {
743 /* open up abort window to timeout handler */
744 cmdiocbq->cmd_flag |= LPFC_IO_CMD_OUTSTANDING;
746 spin_unlock_irqrestore(&phba->hbalock, flags);
747 return 0; /* done for now */
748 } else if (rc == IOCB_BUSY) {
754 /* I/O issue failed. Cleanup resources. */
757 lpfc_els_free_iocb(phba, cmdiocbq);
766 /* make error code available to userspace */
767 bsg_reply->result = rc;
773 * lpfc_bsg_event_free - frees an allocated event structure
774 * @kref: Pointer to a kref.
776 * Called from kref_put. Back cast the kref into an event structure address.
777 * Free any events to get, delete associated nodes, free any events to see,
778 * free any data then free the event itself.
781 lpfc_bsg_event_free(struct kref *kref)
783 struct lpfc_bsg_event *evt = container_of(kref, struct lpfc_bsg_event,
785 struct event_data *ed;
787 list_del(&evt->node);
789 while (!list_empty(&evt->events_to_get)) {
790 ed = list_entry(evt->events_to_get.next, typeof(*ed), node);
796 while (!list_empty(&evt->events_to_see)) {
797 ed = list_entry(evt->events_to_see.next, typeof(*ed), node);
808 * lpfc_bsg_event_ref - increments the kref for an event
809 * @evt: Pointer to an event structure.
812 lpfc_bsg_event_ref(struct lpfc_bsg_event *evt)
814 kref_get(&evt->kref);
818 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
819 * @evt: Pointer to an event structure.
822 lpfc_bsg_event_unref(struct lpfc_bsg_event *evt)
824 kref_put(&evt->kref, lpfc_bsg_event_free);
828 * lpfc_bsg_event_new - allocate and initialize a event structure
829 * @ev_mask: Mask of events.
830 * @ev_reg_id: Event reg id.
831 * @ev_req_id: Event request id.
833 static struct lpfc_bsg_event *
834 lpfc_bsg_event_new(uint32_t ev_mask, int ev_reg_id, uint32_t ev_req_id)
836 struct lpfc_bsg_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL);
841 INIT_LIST_HEAD(&evt->events_to_get);
842 INIT_LIST_HEAD(&evt->events_to_see);
843 evt->type_mask = ev_mask;
844 evt->req_id = ev_req_id;
845 evt->reg_id = ev_reg_id;
846 evt->wait_time_stamp = jiffies;
848 init_waitqueue_head(&evt->wq);
849 kref_init(&evt->kref);
854 * diag_cmd_data_free - Frees an lpfc dma buffer extension
855 * @phba: Pointer to HBA context object.
856 * @mlist: Pointer to an lpfc dma buffer extension.
859 diag_cmd_data_free(struct lpfc_hba *phba, struct lpfc_dmabufext *mlist)
861 struct lpfc_dmabufext *mlast;
862 struct pci_dev *pcidev;
863 struct list_head head, *curr, *next;
865 if ((!mlist) || (!lpfc_is_link_up(phba) &&
866 (phba->link_flag & LS_LOOPBACK_MODE))) {
870 pcidev = phba->pcidev;
871 list_add_tail(&head, &mlist->dma.list);
873 list_for_each_safe(curr, next, &head) {
874 mlast = list_entry(curr, struct lpfc_dmabufext , dma.list);
876 dma_free_coherent(&pcidev->dev,
886 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
888 * This function is called when an unsolicited CT command is received. It
889 * forwards the event to any processes registered to receive CT events.
892 lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
893 struct lpfc_iocbq *piocbq)
895 uint32_t evt_req_id = 0;
897 struct lpfc_dmabuf *dmabuf = NULL;
898 struct lpfc_bsg_event *evt;
899 struct event_data *evt_dat = NULL;
900 struct lpfc_iocbq *iocbq;
903 struct list_head head;
904 struct ulp_bde64 *bde;
907 struct lpfc_dmabuf *bdeBuf1 = piocbq->cmd_dmabuf;
908 struct lpfc_dmabuf *bdeBuf2 = piocbq->bpl_dmabuf;
909 struct lpfc_sli_ct_request *ct_req;
910 struct bsg_job *job = NULL;
911 struct fc_bsg_reply *bsg_reply;
912 struct bsg_job_data *dd_data = NULL;
917 INIT_LIST_HEAD(&head);
918 list_add_tail(&head, &piocbq->list);
920 ct_req = (struct lpfc_sli_ct_request *)bdeBuf1->virt;
921 evt_req_id = ct_req->FsType;
922 cmd = be16_to_cpu(ct_req->CommandResponse.bits.CmdRsp);
924 spin_lock_irqsave(&phba->ct_ev_lock, flags);
925 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
926 if (!(evt->type_mask & FC_REG_CT_EVENT) ||
927 evt->req_id != evt_req_id)
930 lpfc_bsg_event_ref(evt);
931 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
932 evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL);
933 if (evt_dat == NULL) {
934 spin_lock_irqsave(&phba->ct_ev_lock, flags);
935 lpfc_bsg_event_unref(evt);
936 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
937 "2614 Memory allocation failed for "
942 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
943 /* take accumulated byte count from the last iocbq */
944 iocbq = list_entry(head.prev, typeof(*iocbq), list);
945 if (phba->sli_rev == LPFC_SLI_REV4)
946 evt_dat->len = iocbq->wcqe_cmpl.total_data_placed;
948 evt_dat->len = iocbq->iocb.unsli3.rcvsli3.acc_len;
950 list_for_each_entry(iocbq, &head, list) {
952 for (i = 0; i < iocb->ulpBdeCount;
955 iocb->un.cont64[i].tus.f.bdeSize;
959 evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL);
960 if (evt_dat->data == NULL) {
961 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
962 "2615 Memory allocation failed for "
963 "CT event data, size %d\n",
966 spin_lock_irqsave(&phba->ct_ev_lock, flags);
967 lpfc_bsg_event_unref(evt);
968 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
969 goto error_ct_unsol_exit;
972 list_for_each_entry(iocbq, &head, list) {
974 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
975 bdeBuf1 = iocbq->cmd_dmabuf;
976 bdeBuf2 = iocbq->bpl_dmabuf;
978 if (phba->sli_rev == LPFC_SLI_REV4)
979 bde_count = iocbq->wcqe_cmpl.word3;
981 bde_count = iocbq->iocb.ulpBdeCount;
982 for (i = 0; i < bde_count; i++) {
983 if (phba->sli3_options &
984 LPFC_SLI3_HBQ_ENABLED) {
986 size = iocbq->wqe.gen_req.bde.tus.f.bdeSize;
989 size = iocbq->unsol_rcv_len;
992 if ((offset + size) > evt_dat->len)
993 size = evt_dat->len - offset;
995 size = iocbq->iocb.un.cont64[i].
997 bde = &iocbq->iocb.un.cont64[i];
998 dma_addr = getPaddr(bde->addrHigh,
1000 dmabuf = lpfc_sli_ringpostbuf_get(phba,
1004 lpfc_printf_log(phba, KERN_ERR,
1005 LOG_LIBDFC, "2616 No dmabuf "
1006 "found for iocbq x%px\n",
1008 kfree(evt_dat->data);
1010 spin_lock_irqsave(&phba->ct_ev_lock,
1012 lpfc_bsg_event_unref(evt);
1013 spin_unlock_irqrestore(
1014 &phba->ct_ev_lock, flags);
1015 goto error_ct_unsol_exit;
1017 memcpy((char *)(evt_dat->data) + offset,
1018 dmabuf->virt, size);
1020 if (evt_req_id != SLI_CT_ELX_LOOPBACK &&
1021 !(phba->sli3_options &
1022 LPFC_SLI3_HBQ_ENABLED)) {
1023 lpfc_sli_ringpostbuf_put(phba, pring,
1027 case ELX_LOOPBACK_DATA:
1030 diag_cmd_data_free(phba,
1031 (struct lpfc_dmabufext
1034 case ELX_LOOPBACK_XRI_SETUP:
1035 if ((phba->sli_rev ==
1037 (phba->sli3_options &
1038 LPFC_SLI3_HBQ_ENABLED
1040 lpfc_in_buf_free(phba,
1043 lpfc_sli3_post_buffer(phba,
1049 if (!(phba->sli3_options &
1050 LPFC_SLI3_HBQ_ENABLED))
1051 lpfc_sli3_post_buffer(phba,
1060 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1061 if (phba->sli_rev == LPFC_SLI_REV4) {
1062 evt_dat->immed_dat = phba->ctx_idx;
1063 phba->ctx_idx = (phba->ctx_idx + 1) % LPFC_CT_CTX_MAX;
1064 /* Provide warning for over-run of the ct_ctx array */
1065 if (phba->ct_ctx[evt_dat->immed_dat].valid ==
1067 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
1068 "2717 CT context array entry "
1069 "[%d] over-run: oxid:x%x, "
1070 "sid:x%x\n", phba->ctx_idx,
1072 evt_dat->immed_dat].oxid,
1074 evt_dat->immed_dat].SID);
1075 phba->ct_ctx[evt_dat->immed_dat].rxid =
1076 get_job_ulpcontext(phba, piocbq);
1077 phba->ct_ctx[evt_dat->immed_dat].oxid =
1078 get_job_rcvoxid(phba, piocbq);
1079 phba->ct_ctx[evt_dat->immed_dat].SID =
1081 &piocbq->wqe.xmit_els_rsp.wqe_dest);
1082 phba->ct_ctx[evt_dat->immed_dat].valid = UNSOL_VALID;
1084 evt_dat->immed_dat = get_job_ulpcontext(phba, piocbq);
1086 evt_dat->type = FC_REG_CT_EVENT;
1087 list_add(&evt_dat->node, &evt->events_to_see);
1088 if (evt_req_id == SLI_CT_ELX_LOOPBACK) {
1089 wake_up_interruptible(&evt->wq);
1090 lpfc_bsg_event_unref(evt);
1094 list_move(evt->events_to_see.prev, &evt->events_to_get);
1096 dd_data = (struct bsg_job_data *)evt->dd_data;
1097 job = dd_data->set_job;
1098 dd_data->set_job = NULL;
1099 lpfc_bsg_event_unref(evt);
1101 bsg_reply = job->reply;
1102 bsg_reply->reply_payload_rcv_len = size;
1103 /* make error code available to userspace */
1104 bsg_reply->result = 0;
1105 job->dd_data = NULL;
1106 /* complete the job back to userspace */
1107 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1108 bsg_job_done(job, bsg_reply->result,
1109 bsg_reply->reply_payload_rcv_len);
1110 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1113 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1115 error_ct_unsol_exit:
1116 if (!list_empty(&head))
1118 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1119 (evt_req_id == SLI_CT_ELX_LOOPBACK))
1125 * lpfc_bsg_ct_unsol_abort - handler ct abort to management plane
1126 * @phba: Pointer to HBA context object.
1127 * @dmabuf: pointer to a dmabuf that describes the FC sequence
1129 * This function handles abort to the CT command toward management plane
1132 * If the pending context of a CT command to management plane present, clears
1133 * such context and returns 1 for handled; otherwise, it returns 0 indicating
1134 * no context exists.
1137 lpfc_bsg_ct_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
1139 struct fc_frame_header fc_hdr;
1140 struct fc_frame_header *fc_hdr_ptr = &fc_hdr;
1141 int ctx_idx, handled = 0;
1142 uint16_t oxid, rxid;
1145 memcpy(fc_hdr_ptr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
1146 sid = sli4_sid_from_fc_hdr(fc_hdr_ptr);
1147 oxid = be16_to_cpu(fc_hdr_ptr->fh_ox_id);
1148 rxid = be16_to_cpu(fc_hdr_ptr->fh_rx_id);
1150 for (ctx_idx = 0; ctx_idx < LPFC_CT_CTX_MAX; ctx_idx++) {
1151 if (phba->ct_ctx[ctx_idx].valid != UNSOL_VALID)
1153 if (phba->ct_ctx[ctx_idx].rxid != rxid)
1155 if (phba->ct_ctx[ctx_idx].oxid != oxid)
1157 if (phba->ct_ctx[ctx_idx].SID != sid)
1159 phba->ct_ctx[ctx_idx].valid = UNSOL_INVALID;
1166 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1167 * @job: SET_EVENT fc_bsg_job
1170 lpfc_bsg_hba_set_event(struct bsg_job *job)
1172 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
1173 struct lpfc_hba *phba = vport->phba;
1174 struct fc_bsg_request *bsg_request = job->request;
1175 struct set_ct_event *event_req;
1176 struct lpfc_bsg_event *evt;
1178 struct bsg_job_data *dd_data = NULL;
1180 unsigned long flags;
1182 if (job->request_len <
1183 sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) {
1184 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1185 "2612 Received SET_CT_EVENT below minimum "
1191 event_req = (struct set_ct_event *)
1192 bsg_request->rqst_data.h_vendor.vendor_cmd;
1193 ev_mask = ((uint32_t)(unsigned long)event_req->type_mask &
1195 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1196 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
1197 if (evt->reg_id == event_req->ev_reg_id) {
1198 lpfc_bsg_event_ref(evt);
1199 evt->wait_time_stamp = jiffies;
1200 dd_data = (struct bsg_job_data *)evt->dd_data;
1204 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1206 if (&evt->node == &phba->ct_ev_waiters) {
1207 /* no event waiting struct yet - first call */
1208 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
1209 if (dd_data == NULL) {
1210 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1211 "2734 Failed allocation of dd_data\n");
1215 evt = lpfc_bsg_event_new(ev_mask, event_req->ev_reg_id,
1216 event_req->ev_req_id);
1218 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1219 "2617 Failed allocation of event "
1224 dd_data->type = TYPE_EVT;
1225 dd_data->set_job = NULL;
1226 dd_data->context_un.evt = evt;
1227 evt->dd_data = (void *)dd_data;
1228 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1229 list_add(&evt->node, &phba->ct_ev_waiters);
1230 lpfc_bsg_event_ref(evt);
1231 evt->wait_time_stamp = jiffies;
1232 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1235 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1237 dd_data->set_job = job; /* for unsolicited command */
1238 job->dd_data = dd_data; /* for fc transport timeout callback*/
1239 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1240 return 0; /* call job done later */
1244 job->dd_data = NULL;
1249 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1250 * @job: GET_EVENT fc_bsg_job
1253 lpfc_bsg_hba_get_event(struct bsg_job *job)
1255 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
1256 struct lpfc_hba *phba = vport->phba;
1257 struct fc_bsg_request *bsg_request = job->request;
1258 struct fc_bsg_reply *bsg_reply = job->reply;
1259 struct get_ct_event *event_req;
1260 struct get_ct_event_reply *event_reply;
1261 struct lpfc_bsg_event *evt, *evt_next;
1262 struct event_data *evt_dat = NULL;
1263 unsigned long flags;
1266 if (job->request_len <
1267 sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) {
1268 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1269 "2613 Received GET_CT_EVENT request below "
1275 event_req = (struct get_ct_event *)
1276 bsg_request->rqst_data.h_vendor.vendor_cmd;
1278 event_reply = (struct get_ct_event_reply *)
1279 bsg_reply->reply_data.vendor_reply.vendor_rsp;
1280 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1281 list_for_each_entry_safe(evt, evt_next, &phba->ct_ev_waiters, node) {
1282 if (evt->reg_id == event_req->ev_reg_id) {
1283 if (list_empty(&evt->events_to_get))
1285 lpfc_bsg_event_ref(evt);
1286 evt->wait_time_stamp = jiffies;
1287 evt_dat = list_entry(evt->events_to_get.prev,
1288 struct event_data, node);
1289 list_del(&evt_dat->node);
1293 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1295 /* The app may continue to ask for event data until it gets
1296 * an error indicating that there isn't anymore
1298 if (evt_dat == NULL) {
1299 bsg_reply->reply_payload_rcv_len = 0;
1304 if (evt_dat->len > job->request_payload.payload_len) {
1305 evt_dat->len = job->request_payload.payload_len;
1306 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1307 "2618 Truncated event data at %d "
1309 job->request_payload.payload_len);
1312 event_reply->type = evt_dat->type;
1313 event_reply->immed_data = evt_dat->immed_dat;
1314 if (evt_dat->len > 0)
1315 bsg_reply->reply_payload_rcv_len =
1316 sg_copy_from_buffer(job->request_payload.sg_list,
1317 job->request_payload.sg_cnt,
1318 evt_dat->data, evt_dat->len);
1320 bsg_reply->reply_payload_rcv_len = 0;
1323 kfree(evt_dat->data);
1327 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1328 lpfc_bsg_event_unref(evt);
1329 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1330 job->dd_data = NULL;
1331 bsg_reply->result = 0;
1332 bsg_job_done(job, bsg_reply->result,
1333 bsg_reply->reply_payload_rcv_len);
1337 job->dd_data = NULL;
1338 bsg_reply->result = rc;
1343 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1344 * @phba: Pointer to HBA context object.
1345 * @cmdiocbq: Pointer to command iocb.
1346 * @rspiocbq: Pointer to response iocb.
1348 * This function is the completion handler for iocbs issued using
1349 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1350 * ring event handler function without any lock held. This function
1351 * can be called from both worker thread context and interrupt
1352 * context. This function also can be called from other thread which
1353 * cleans up the SLI layer objects.
1354 * This function copy the contents of the response iocb to the
1355 * response iocb memory object provided by the caller of
1356 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1357 * sleeps for the iocb completion.
1360 lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba,
1361 struct lpfc_iocbq *cmdiocbq,
1362 struct lpfc_iocbq *rspiocbq)
1364 struct bsg_job_data *dd_data;
1365 struct bsg_job *job;
1366 struct fc_bsg_reply *bsg_reply;
1367 struct lpfc_dmabuf *bmp, *cmp;
1368 struct lpfc_nodelist *ndlp;
1369 unsigned long flags;
1371 u32 ulp_status, ulp_word4;
1373 dd_data = cmdiocbq->context_un.dd_data;
1375 /* Determine if job has been aborted */
1376 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1377 job = dd_data->set_job;
1379 /* Prevent timeout handling from trying to abort job */
1380 job->dd_data = NULL;
1382 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1384 /* Close the timeout handler abort window */
1385 spin_lock_irqsave(&phba->hbalock, flags);
1386 cmdiocbq->cmd_flag &= ~LPFC_IO_CMD_OUTSTANDING;
1387 spin_unlock_irqrestore(&phba->hbalock, flags);
1389 ndlp = dd_data->context_un.iocb.ndlp;
1390 cmp = cmdiocbq->cmd_dmabuf;
1391 bmp = cmdiocbq->bpl_dmabuf;
1393 ulp_status = get_job_ulpstatus(phba, rspiocbq);
1394 ulp_word4 = get_job_word4(phba, rspiocbq);
1396 /* Copy the completed job data or set the error status */
1399 bsg_reply = job->reply;
1401 if (ulp_status == IOSTAT_LOCAL_REJECT) {
1402 switch (ulp_word4 & IOERR_PARAM_MASK) {
1403 case IOERR_SEQUENCE_TIMEOUT:
1406 case IOERR_INVALID_RPI:
1417 bsg_reply->reply_payload_rcv_len = 0;
1421 lpfc_free_bsg_buffers(phba, cmp);
1422 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1424 lpfc_sli_release_iocbq(phba, cmdiocbq);
1428 /* Complete the job if the job is still active */
1431 bsg_reply->result = rc;
1432 bsg_job_done(job, bsg_reply->result,
1433 bsg_reply->reply_payload_rcv_len);
1439 * lpfc_issue_ct_rsp - issue a ct response
1440 * @phba: Pointer to HBA context object.
1441 * @job: Pointer to the job object.
1442 * @tag: tag index value into the ports context exchange array.
1443 * @cmp: Pointer to a cmp dma buffer descriptor.
1444 * @bmp: Pointer to a bmp dma buffer descriptor.
1445 * @num_entry: Number of enties in the bde.
1448 lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct bsg_job *job, uint32_t tag,
1449 struct lpfc_dmabuf *cmp, struct lpfc_dmabuf *bmp,
1452 struct lpfc_iocbq *ctiocb = NULL;
1454 struct lpfc_nodelist *ndlp = NULL;
1455 struct bsg_job_data *dd_data;
1456 unsigned long flags;
1458 u16 ulp_context, iotag;
1460 ndlp = lpfc_findnode_did(phba->pport, phba->ct_ctx[tag].SID);
1462 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
1463 "2721 ndlp null for oxid %x SID %x\n",
1464 phba->ct_ctx[tag].rxid,
1465 phba->ct_ctx[tag].SID);
1469 /* allocate our bsg tracking structure */
1470 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
1472 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1473 "2736 Failed allocation of dd_data\n");
1478 /* Allocate buffer for command iocb */
1479 ctiocb = lpfc_sli_get_iocbq(phba);
1485 if (phba->sli_rev == LPFC_SLI_REV4) {
1486 /* Do not issue unsol response if oxid not marked as valid */
1487 if (phba->ct_ctx[tag].valid != UNSOL_VALID) {
1489 goto issue_ct_rsp_exit;
1492 lpfc_sli_prep_xmit_seq64(phba, ctiocb, bmp,
1493 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
1494 phba->ct_ctx[tag].oxid, num_entry,
1495 FC_RCTL_DD_SOL_CTL, 1,
1496 CMD_XMIT_SEQUENCE64_WQE);
1498 /* The exchange is done, mark the entry as invalid */
1499 phba->ct_ctx[tag].valid = UNSOL_INVALID;
1500 iotag = get_wqe_reqtag(ctiocb);
1502 lpfc_sli_prep_xmit_seq64(phba, ctiocb, bmp, 0, tag, num_entry,
1503 FC_RCTL_DD_SOL_CTL, 1,
1504 CMD_XMIT_SEQUENCE64_CX);
1505 ctiocb->num_bdes = num_entry;
1506 iotag = ctiocb->iocb.ulpIoTag;
1509 ulp_context = get_job_ulpcontext(phba, ctiocb);
1511 /* Xmit CT response on exchange <xid> */
1512 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1513 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1514 ulp_context, iotag, tag, phba->link_state);
1516 ctiocb->cmd_flag |= LPFC_IO_LIBDFC;
1517 ctiocb->vport = phba->pport;
1518 ctiocb->context_un.dd_data = dd_data;
1519 ctiocb->cmd_dmabuf = cmp;
1520 ctiocb->bpl_dmabuf = bmp;
1521 ctiocb->ndlp = ndlp;
1522 ctiocb->cmd_cmpl = lpfc_issue_ct_rsp_cmp;
1524 dd_data->type = TYPE_IOCB;
1525 dd_data->set_job = job;
1526 dd_data->context_un.iocb.cmdiocbq = ctiocb;
1527 dd_data->context_un.iocb.ndlp = lpfc_nlp_get(ndlp);
1528 if (!dd_data->context_un.iocb.ndlp) {
1530 goto issue_ct_rsp_exit;
1532 dd_data->context_un.iocb.rmp = NULL;
1533 job->dd_data = dd_data;
1535 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1536 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1538 goto issue_ct_rsp_exit;
1540 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1541 writel(creg_val, phba->HCregaddr);
1542 readl(phba->HCregaddr); /* flush */
1545 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
1546 if (rc == IOCB_SUCCESS) {
1547 spin_lock_irqsave(&phba->hbalock, flags);
1548 /* make sure the I/O had not been completed/released */
1549 if (ctiocb->cmd_flag & LPFC_IO_LIBDFC) {
1550 /* open up abort window to timeout handler */
1551 ctiocb->cmd_flag |= LPFC_IO_CMD_OUTSTANDING;
1553 spin_unlock_irqrestore(&phba->hbalock, flags);
1554 return 0; /* done for now */
1557 /* iocb failed so cleanup */
1558 job->dd_data = NULL;
1562 lpfc_sli_release_iocbq(phba, ctiocb);
1570 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1571 * @job: SEND_MGMT_RESP fc_bsg_job
1574 lpfc_bsg_send_mgmt_rsp(struct bsg_job *job)
1576 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
1577 struct lpfc_hba *phba = vport->phba;
1578 struct fc_bsg_request *bsg_request = job->request;
1579 struct fc_bsg_reply *bsg_reply = job->reply;
1580 struct send_mgmt_resp *mgmt_resp = (struct send_mgmt_resp *)
1581 bsg_request->rqst_data.h_vendor.vendor_cmd;
1582 struct ulp_bde64 *bpl;
1583 struct lpfc_dmabuf *bmp = NULL, *cmp = NULL;
1585 uint32_t tag = mgmt_resp->tag;
1586 unsigned long reqbfrcnt =
1587 (unsigned long)job->request_payload.payload_len;
1590 /* in case no data is transferred */
1591 bsg_reply->reply_payload_rcv_len = 0;
1593 if (!reqbfrcnt || (reqbfrcnt > (80 * BUF_SZ_4K))) {
1595 goto send_mgmt_rsp_exit;
1598 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1601 goto send_mgmt_rsp_exit;
1604 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
1607 goto send_mgmt_rsp_free_bmp;
1610 INIT_LIST_HEAD(&bmp->list);
1611 bpl = (struct ulp_bde64 *) bmp->virt;
1612 bpl_entries = (LPFC_BPL_SIZE/sizeof(struct ulp_bde64));
1613 cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len,
1614 1, bpl, &bpl_entries);
1617 goto send_mgmt_rsp_free_bmp;
1619 lpfc_bsg_copy_data(cmp, &job->request_payload,
1620 job->request_payload.payload_len, 1);
1622 rc = lpfc_issue_ct_rsp(phba, job, tag, cmp, bmp, bpl_entries);
1624 if (rc == IOCB_SUCCESS)
1625 return 0; /* done for now */
1629 lpfc_free_bsg_buffers(phba, cmp);
1631 send_mgmt_rsp_free_bmp:
1633 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1636 /* make error code available to userspace */
1637 bsg_reply->result = rc;
1638 job->dd_data = NULL;
1643 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1644 * @phba: Pointer to HBA context object.
1646 * This function is responsible for preparing driver for diag loopback
1650 lpfc_bsg_diag_mode_enter(struct lpfc_hba *phba)
1652 struct lpfc_vport **vports;
1653 struct Scsi_Host *shost;
1654 struct lpfc_sli *psli;
1655 struct lpfc_queue *qp = NULL;
1656 struct lpfc_sli_ring *pring;
1664 if ((phba->link_state == LPFC_HBA_ERROR) ||
1665 (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
1666 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
1669 vports = lpfc_create_vport_work_array(phba);
1671 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1672 shost = lpfc_shost_from_vport(vports[i]);
1673 scsi_block_requests(shost);
1675 lpfc_destroy_vport_work_array(phba, vports);
1677 shost = lpfc_shost_from_vport(phba->pport);
1678 scsi_block_requests(shost);
1681 if (phba->sli_rev != LPFC_SLI_REV4) {
1682 pring = &psli->sli3_ring[LPFC_FCP_RING];
1683 lpfc_emptyq_wait(phba, &pring->txcmplq, &phba->hbalock);
1686 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1688 if (!pring || (pring->ringno != LPFC_FCP_RING))
1690 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1698 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1699 * @phba: Pointer to HBA context object.
1701 * This function is responsible for driver exit processing of setting up
1702 * diag loopback mode on device.
1705 lpfc_bsg_diag_mode_exit(struct lpfc_hba *phba)
1707 struct Scsi_Host *shost;
1708 struct lpfc_vport **vports;
1711 vports = lpfc_create_vport_work_array(phba);
1713 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1714 shost = lpfc_shost_from_vport(vports[i]);
1715 scsi_unblock_requests(shost);
1717 lpfc_destroy_vport_work_array(phba, vports);
1719 shost = lpfc_shost_from_vport(phba->pport);
1720 scsi_unblock_requests(shost);
1726 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1727 * @phba: Pointer to HBA context object.
1728 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1730 * This function is responsible for placing an sli3 port into diagnostic
1731 * loopback mode in order to perform a diagnostic loopback test.
1732 * All new scsi requests are blocked, a small delay is used to allow the
1733 * scsi requests to complete then the link is brought down. If the link is
1734 * is placed in loopback mode then scsi requests are again allowed
1735 * so the scsi mid-layer doesn't give up on the port.
1736 * All of this is done in-line.
1739 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct bsg_job *job)
1741 struct fc_bsg_request *bsg_request = job->request;
1742 struct fc_bsg_reply *bsg_reply = job->reply;
1743 struct diag_mode_set *loopback_mode;
1744 uint32_t link_flags;
1746 LPFC_MBOXQ_t *pmboxq = NULL;
1747 int mbxstatus = MBX_SUCCESS;
1751 /* no data to return just the return code */
1752 bsg_reply->reply_payload_rcv_len = 0;
1754 if (job->request_len < sizeof(struct fc_bsg_request) +
1755 sizeof(struct diag_mode_set)) {
1756 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1757 "2738 Received DIAG MODE request size:%d "
1758 "below the minimum size:%d\n",
1760 (int)(sizeof(struct fc_bsg_request) +
1761 sizeof(struct diag_mode_set)));
1766 rc = lpfc_bsg_diag_mode_enter(phba);
1770 /* bring the link to diagnostic mode */
1771 loopback_mode = (struct diag_mode_set *)
1772 bsg_request->rqst_data.h_vendor.vendor_cmd;
1773 link_flags = loopback_mode->type;
1774 timeout = loopback_mode->timeout * 100;
1776 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1779 goto loopback_mode_exit;
1781 memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1782 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1783 pmboxq->u.mb.mbxOwner = OWN_HOST;
1785 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
1787 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) {
1788 /* wait for link down before proceeding */
1790 while (phba->link_state != LPFC_LINK_DOWN) {
1791 if (i++ > timeout) {
1793 goto loopback_mode_exit;
1798 memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1799 if (link_flags == INTERNAL_LOOP_BACK)
1800 pmboxq->u.mb.un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
1802 pmboxq->u.mb.un.varInitLnk.link_flags =
1803 FLAGS_TOPOLOGY_MODE_LOOP;
1805 pmboxq->u.mb.mbxCommand = MBX_INIT_LINK;
1806 pmboxq->u.mb.mbxOwner = OWN_HOST;
1808 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1811 if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus))
1814 spin_lock_irq(&phba->hbalock);
1815 phba->link_flag |= LS_LOOPBACK_MODE;
1816 spin_unlock_irq(&phba->hbalock);
1817 /* wait for the link attention interrupt */
1821 while (phba->link_state != LPFC_HBA_READY) {
1822 if (i++ > timeout) {
1835 lpfc_bsg_diag_mode_exit(phba);
1838 * Let SLI layer release mboxq if mbox command completed after timeout.
1840 if (pmboxq && mbxstatus != MBX_TIMEOUT)
1841 mempool_free(pmboxq, phba->mbox_mem_pool);
1844 /* make error code available to userspace */
1845 bsg_reply->result = rc;
1846 /* complete the job back to userspace if no error */
1848 bsg_job_done(job, bsg_reply->result,
1849 bsg_reply->reply_payload_rcv_len);
1854 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1855 * @phba: Pointer to HBA context object.
1856 * @diag: Flag for set link to diag or nomral operation state.
1858 * This function is responsible for issuing a sli4 mailbox command for setting
1859 * link to either diag state or normal operation state.
1862 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba *phba, uint32_t diag)
1864 LPFC_MBOXQ_t *pmboxq;
1865 struct lpfc_mbx_set_link_diag_state *link_diag_state;
1866 uint32_t req_len, alloc_len;
1867 int mbxstatus = MBX_SUCCESS, rc;
1869 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1873 req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) -
1874 sizeof(struct lpfc_sli4_cfg_mhdr));
1875 alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1876 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE,
1877 req_len, LPFC_SLI4_MBX_EMBED);
1878 if (alloc_len != req_len) {
1880 goto link_diag_state_set_out;
1882 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
1883 "3128 Set link to diagnostic state:x%x (x%x/x%x)\n",
1884 diag, phba->sli4_hba.lnk_info.lnk_tp,
1885 phba->sli4_hba.lnk_info.lnk_no);
1887 link_diag_state = &pmboxq->u.mqe.un.link_diag_state;
1888 bf_set(lpfc_mbx_set_diag_state_diag_bit_valid, &link_diag_state->u.req,
1889 LPFC_DIAG_STATE_DIAG_BIT_VALID_CHANGE);
1890 bf_set(lpfc_mbx_set_diag_state_link_num, &link_diag_state->u.req,
1891 phba->sli4_hba.lnk_info.lnk_no);
1892 bf_set(lpfc_mbx_set_diag_state_link_type, &link_diag_state->u.req,
1893 phba->sli4_hba.lnk_info.lnk_tp);
1895 bf_set(lpfc_mbx_set_diag_state_diag,
1896 &link_diag_state->u.req, 1);
1898 bf_set(lpfc_mbx_set_diag_state_diag,
1899 &link_diag_state->u.req, 0);
1901 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
1903 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0))
1908 link_diag_state_set_out:
1909 if (pmboxq && (mbxstatus != MBX_TIMEOUT))
1910 mempool_free(pmboxq, phba->mbox_mem_pool);
1916 * lpfc_sli4_bsg_set_loopback_mode - set sli4 internal loopback diagnostic
1917 * @phba: Pointer to HBA context object.
1918 * @mode: loopback mode to set
1919 * @link_no: link number for loopback mode to set
1921 * This function is responsible for issuing a sli4 mailbox command for setting
1922 * up loopback diagnostic for a link.
1925 lpfc_sli4_bsg_set_loopback_mode(struct lpfc_hba *phba, int mode,
1928 LPFC_MBOXQ_t *pmboxq;
1929 uint32_t req_len, alloc_len;
1930 struct lpfc_mbx_set_link_diag_loopback *link_diag_loopback;
1931 int mbxstatus = MBX_SUCCESS, rc = 0;
1933 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1936 req_len = (sizeof(struct lpfc_mbx_set_link_diag_loopback) -
1937 sizeof(struct lpfc_sli4_cfg_mhdr));
1938 alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1939 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK,
1940 req_len, LPFC_SLI4_MBX_EMBED);
1941 if (alloc_len != req_len) {
1942 mempool_free(pmboxq, phba->mbox_mem_pool);
1945 link_diag_loopback = &pmboxq->u.mqe.un.link_diag_loopback;
1946 bf_set(lpfc_mbx_set_diag_state_link_num,
1947 &link_diag_loopback->u.req, link_no);
1949 if (phba->sli4_hba.conf_trunk & (1 << link_no)) {
1950 bf_set(lpfc_mbx_set_diag_state_link_type,
1951 &link_diag_loopback->u.req, LPFC_LNK_FC_TRUNKED);
1953 bf_set(lpfc_mbx_set_diag_state_link_type,
1954 &link_diag_loopback->u.req,
1955 phba->sli4_hba.lnk_info.lnk_tp);
1958 bf_set(lpfc_mbx_set_diag_lpbk_type, &link_diag_loopback->u.req,
1961 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
1962 if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus)) {
1963 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1964 "3127 Failed setup loopback mode mailbox "
1965 "command, rc:x%x, status:x%x\n", mbxstatus,
1966 pmboxq->u.mb.mbxStatus);
1969 if (pmboxq && (mbxstatus != MBX_TIMEOUT))
1970 mempool_free(pmboxq, phba->mbox_mem_pool);
1975 * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic
1976 * @phba: Pointer to HBA context object.
1978 * This function set up SLI4 FC port registrations for diagnostic run, which
1979 * includes all the rpis, vfi, and also vpi.
1982 lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba *phba)
1984 if (test_bit(FC_VFI_REGISTERED, &phba->pport->fc_flag)) {
1985 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1986 "3136 Port still had vfi registered: "
1987 "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
1988 phba->pport->fc_myDID, phba->fcf.fcfi,
1989 phba->sli4_hba.vfi_ids[phba->pport->vfi],
1990 phba->vpi_ids[phba->pport->vpi]);
1993 return lpfc_issue_reg_vfi(phba->pport);
1997 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
1998 * @phba: Pointer to HBA context object.
1999 * @job: LPFC_BSG_VENDOR_DIAG_MODE
2001 * This function is responsible for placing an sli4 port into diagnostic
2002 * loopback mode in order to perform a diagnostic loopback test.
2005 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct bsg_job *job)
2007 struct fc_bsg_request *bsg_request = job->request;
2008 struct fc_bsg_reply *bsg_reply = job->reply;
2009 struct diag_mode_set *loopback_mode;
2010 uint32_t link_flags, timeout, link_no;
2013 /* no data to return just the return code */
2014 bsg_reply->reply_payload_rcv_len = 0;
2016 if (job->request_len < sizeof(struct fc_bsg_request) +
2017 sizeof(struct diag_mode_set)) {
2018 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2019 "3011 Received DIAG MODE request size:%d "
2020 "below the minimum size:%d\n",
2022 (int)(sizeof(struct fc_bsg_request) +
2023 sizeof(struct diag_mode_set)));
2028 loopback_mode = (struct diag_mode_set *)
2029 bsg_request->rqst_data.h_vendor.vendor_cmd;
2030 link_flags = loopback_mode->type;
2031 timeout = loopback_mode->timeout * 100;
2033 if (loopback_mode->physical_link == -1)
2034 link_no = phba->sli4_hba.lnk_info.lnk_no;
2036 link_no = loopback_mode->physical_link;
2038 if (link_flags == DISABLE_LOOP_BACK) {
2039 rc = lpfc_sli4_bsg_set_loopback_mode(phba,
2040 LPFC_DIAG_LOOPBACK_TYPE_DISABLE,
2043 /* Unset the need disable bit */
2044 phba->sli4_hba.conf_trunk &= ~((1 << link_no) << 4);
2048 /* Check if we need to disable the loopback state */
2049 if (phba->sli4_hba.conf_trunk & ((1 << link_no) << 4)) {
2055 rc = lpfc_bsg_diag_mode_enter(phba);
2059 /* indicate we are in loobpack diagnostic mode */
2060 spin_lock_irq(&phba->hbalock);
2061 phba->link_flag |= LS_LOOPBACK_MODE;
2062 spin_unlock_irq(&phba->hbalock);
2064 /* reset port to start frome scratch */
2065 rc = lpfc_selective_reset(phba);
2069 /* bring the link to diagnostic mode */
2070 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2071 "3129 Bring link to diagnostic state.\n");
2073 rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1);
2075 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2076 "3130 Failed to bring link to diagnostic "
2077 "state, rc:x%x\n", rc);
2078 goto loopback_mode_exit;
2081 /* wait for link down before proceeding */
2083 while (phba->link_state != LPFC_LINK_DOWN) {
2084 if (i++ > timeout) {
2086 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2087 "3131 Timeout waiting for link to "
2088 "diagnostic mode, timeout:%d ms\n",
2090 goto loopback_mode_exit;
2095 /* set up loopback mode */
2096 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2097 "3132 Set up loopback mode:x%x\n", link_flags);
2099 switch (link_flags) {
2100 case INTERNAL_LOOP_BACK:
2101 if (phba->sli4_hba.conf_trunk & (1 << link_no)) {
2102 rc = lpfc_sli4_bsg_set_loopback_mode(phba,
2103 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL,
2106 /* Trunk is configured, but link is not in this trunk */
2107 if (phba->sli4_hba.conf_trunk) {
2109 goto loopback_mode_exit;
2112 rc = lpfc_sli4_bsg_set_loopback_mode(phba,
2113 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL,
2118 /* Set the need disable bit */
2119 phba->sli4_hba.conf_trunk |= (1 << link_no) << 4;
2123 case EXTERNAL_LOOP_BACK:
2124 if (phba->sli4_hba.conf_trunk & (1 << link_no)) {
2125 rc = lpfc_sli4_bsg_set_loopback_mode(phba,
2126 LPFC_DIAG_LOOPBACK_TYPE_EXTERNAL_TRUNKED,
2129 /* Trunk is configured, but link is not in this trunk */
2130 if (phba->sli4_hba.conf_trunk) {
2132 goto loopback_mode_exit;
2135 rc = lpfc_sli4_bsg_set_loopback_mode(phba,
2136 LPFC_DIAG_LOOPBACK_TYPE_SERDES,
2141 /* Set the need disable bit */
2142 phba->sli4_hba.conf_trunk |= (1 << link_no) << 4;
2148 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
2149 "3141 Loopback mode:x%x not supported\n",
2151 goto loopback_mode_exit;
2155 /* wait for the link attention interrupt */
2158 while (phba->link_state < LPFC_LINK_UP) {
2159 if (i++ > timeout) {
2161 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2162 "3137 Timeout waiting for link up "
2163 "in loopback mode, timeout:%d ms\n",
2171 /* port resource registration setup for loopback diagnostic */
2173 /* set up a none zero myDID for loopback test */
2174 phba->pport->fc_myDID = 1;
2175 rc = lpfc_sli4_diag_fcport_reg_setup(phba);
2177 goto loopback_mode_exit;
2180 /* wait for the port ready */
2183 while (phba->link_state != LPFC_HBA_READY) {
2184 if (i++ > timeout) {
2186 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2187 "3133 Timeout waiting for port "
2188 "loopback mode ready, timeout:%d ms\n",
2197 /* clear loopback diagnostic mode */
2199 spin_lock_irq(&phba->hbalock);
2200 phba->link_flag &= ~LS_LOOPBACK_MODE;
2201 spin_unlock_irq(&phba->hbalock);
2203 lpfc_bsg_diag_mode_exit(phba);
2206 /* make error code available to userspace */
2207 bsg_reply->result = rc;
2208 /* complete the job back to userspace if no error */
2210 bsg_job_done(job, bsg_reply->result,
2211 bsg_reply->reply_payload_rcv_len);
2216 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
2217 * @job: LPFC_BSG_VENDOR_DIAG_MODE
2219 * This function is responsible for responding to check and dispatch bsg diag
2220 * command from the user to proper driver action routines.
2223 lpfc_bsg_diag_loopback_mode(struct bsg_job *job)
2225 struct Scsi_Host *shost;
2226 struct lpfc_vport *vport;
2227 struct lpfc_hba *phba;
2230 shost = fc_bsg_to_shost(job);
2233 vport = shost_priv(shost);
2240 if (phba->sli_rev < LPFC_SLI_REV4)
2241 rc = lpfc_sli3_bsg_diag_loopback_mode(phba, job);
2242 else if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
2243 LPFC_SLI_INTF_IF_TYPE_2)
2244 rc = lpfc_sli4_bsg_diag_loopback_mode(phba, job);
2252 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
2253 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
2255 * This function is responsible for responding to check and dispatch bsg diag
2256 * command from the user to proper driver action routines.
2259 lpfc_sli4_bsg_diag_mode_end(struct bsg_job *job)
2261 struct fc_bsg_request *bsg_request = job->request;
2262 struct fc_bsg_reply *bsg_reply = job->reply;
2263 struct Scsi_Host *shost;
2264 struct lpfc_vport *vport;
2265 struct lpfc_hba *phba;
2266 struct diag_mode_set *loopback_mode_end_cmd;
2270 shost = fc_bsg_to_shost(job);
2273 vport = shost_priv(shost);
2280 if (phba->sli_rev < LPFC_SLI_REV4)
2282 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
2283 LPFC_SLI_INTF_IF_TYPE_2)
2286 /* clear loopback diagnostic mode */
2287 spin_lock_irq(&phba->hbalock);
2288 phba->link_flag &= ~LS_LOOPBACK_MODE;
2289 spin_unlock_irq(&phba->hbalock);
2290 loopback_mode_end_cmd = (struct diag_mode_set *)
2291 bsg_request->rqst_data.h_vendor.vendor_cmd;
2292 timeout = loopback_mode_end_cmd->timeout * 100;
2294 rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0);
2296 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2297 "3139 Failed to bring link to diagnostic "
2298 "state, rc:x%x\n", rc);
2299 goto loopback_mode_end_exit;
2302 /* wait for link down before proceeding */
2304 while (phba->link_state != LPFC_LINK_DOWN) {
2305 if (i++ > timeout) {
2306 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2307 "3140 Timeout waiting for link to "
2308 "diagnostic mode_end, timeout:%d ms\n",
2310 /* there is nothing much we can do here */
2316 /* reset port resource registrations */
2317 rc = lpfc_selective_reset(phba);
2318 phba->pport->fc_myDID = 0;
2320 loopback_mode_end_exit:
2321 /* make return code available to userspace */
2322 bsg_reply->result = rc;
2323 /* complete the job back to userspace if no error */
2325 bsg_job_done(job, bsg_reply->result,
2326 bsg_reply->reply_payload_rcv_len);
2331 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
2332 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
2334 * This function is to perform SLI4 diag link test request from the user
2338 lpfc_sli4_bsg_link_diag_test(struct bsg_job *job)
2340 struct fc_bsg_request *bsg_request = job->request;
2341 struct fc_bsg_reply *bsg_reply = job->reply;
2342 struct Scsi_Host *shost;
2343 struct lpfc_vport *vport;
2344 struct lpfc_hba *phba;
2345 LPFC_MBOXQ_t *pmboxq;
2346 struct sli4_link_diag *link_diag_test_cmd;
2347 uint32_t req_len, alloc_len;
2348 struct lpfc_mbx_run_link_diag_test *run_link_diag_test;
2349 union lpfc_sli4_cfg_shdr *shdr;
2350 uint32_t shdr_status, shdr_add_status;
2351 struct diag_status *diag_status_reply;
2352 int mbxstatus, rc = -ENODEV, rc1 = 0;
2354 shost = fc_bsg_to_shost(job);
2358 vport = shost_priv(shost);
2367 if (phba->sli_rev < LPFC_SLI_REV4)
2370 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
2371 LPFC_SLI_INTF_IF_TYPE_2)
2374 if (job->request_len < sizeof(struct fc_bsg_request) +
2375 sizeof(struct sli4_link_diag)) {
2376 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2377 "3013 Received LINK DIAG TEST request "
2378 " size:%d below the minimum size:%d\n",
2380 (int)(sizeof(struct fc_bsg_request) +
2381 sizeof(struct sli4_link_diag)));
2386 rc = lpfc_bsg_diag_mode_enter(phba);
2390 link_diag_test_cmd = (struct sli4_link_diag *)
2391 bsg_request->rqst_data.h_vendor.vendor_cmd;
2393 rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1);
2398 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2401 goto link_diag_test_exit;
2404 req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) -
2405 sizeof(struct lpfc_sli4_cfg_mhdr));
2406 alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2407 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE,
2408 req_len, LPFC_SLI4_MBX_EMBED);
2409 if (alloc_len != req_len) {
2411 goto link_diag_test_exit;
2414 run_link_diag_test = &pmboxq->u.mqe.un.link_diag_test;
2415 bf_set(lpfc_mbx_run_diag_test_link_num, &run_link_diag_test->u.req,
2416 phba->sli4_hba.lnk_info.lnk_no);
2417 bf_set(lpfc_mbx_run_diag_test_link_type, &run_link_diag_test->u.req,
2418 phba->sli4_hba.lnk_info.lnk_tp);
2419 bf_set(lpfc_mbx_run_diag_test_test_id, &run_link_diag_test->u.req,
2420 link_diag_test_cmd->test_id);
2421 bf_set(lpfc_mbx_run_diag_test_loops, &run_link_diag_test->u.req,
2422 link_diag_test_cmd->loops);
2423 bf_set(lpfc_mbx_run_diag_test_test_ver, &run_link_diag_test->u.req,
2424 link_diag_test_cmd->test_version);
2425 bf_set(lpfc_mbx_run_diag_test_err_act, &run_link_diag_test->u.req,
2426 link_diag_test_cmd->error_action);
2428 mbxstatus = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2430 shdr = (union lpfc_sli4_cfg_shdr *)
2431 &pmboxq->u.mqe.un.sli4_config.header.cfg_shdr;
2432 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2433 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2434 if (shdr_status || shdr_add_status || mbxstatus) {
2435 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
2436 "3010 Run link diag test mailbox failed with "
2437 "mbx_status x%x status x%x, add_status x%x\n",
2438 mbxstatus, shdr_status, shdr_add_status);
2441 diag_status_reply = (struct diag_status *)
2442 bsg_reply->reply_data.vendor_reply.vendor_rsp;
2444 if (job->reply_len < sizeof(*bsg_reply) + sizeof(*diag_status_reply)) {
2445 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2446 "3012 Received Run link diag test reply "
2447 "below minimum size (%d): reply_len:%d\n",
2448 (int)(sizeof(*bsg_reply) +
2449 sizeof(*diag_status_reply)),
2455 diag_status_reply->mbox_status = mbxstatus;
2456 diag_status_reply->shdr_status = shdr_status;
2457 diag_status_reply->shdr_add_status = shdr_add_status;
2459 link_diag_test_exit:
2460 rc1 = lpfc_sli4_bsg_set_link_diag_state(phba, 0);
2463 mempool_free(pmboxq, phba->mbox_mem_pool);
2465 lpfc_bsg_diag_mode_exit(phba);
2468 /* make error code available to userspace */
2471 bsg_reply->result = rc;
2472 /* complete the job back to userspace if no error */
2474 bsg_job_done(job, bsg_reply->result,
2475 bsg_reply->reply_payload_rcv_len);
2480 * lpfcdiag_loop_self_reg - obtains a remote port login id
2481 * @phba: Pointer to HBA context object
2482 * @rpi: Pointer to a remote port login id
2484 * This function obtains a remote port login id so the diag loopback test
2485 * can send and receive its own unsolicited CT command.
2487 static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t *rpi)
2490 struct lpfc_dmabuf *dmabuff;
2493 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2497 if (phba->sli_rev < LPFC_SLI_REV4)
2498 status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID,
2499 (uint8_t *)&phba->pport->fc_sparam,
2502 *rpi = lpfc_sli4_alloc_rpi(phba);
2503 if (*rpi == LPFC_RPI_ALLOC_ERROR) {
2504 mempool_free(mbox, phba->mbox_mem_pool);
2507 status = lpfc_reg_rpi(phba, phba->pport->vpi,
2508 phba->pport->fc_myDID,
2509 (uint8_t *)&phba->pport->fc_sparam,
2514 mempool_free(mbox, phba->mbox_mem_pool);
2515 if (phba->sli_rev == LPFC_SLI_REV4)
2516 lpfc_sli4_free_rpi(phba, *rpi);
2520 dmabuff = mbox->ctx_buf;
2521 mbox->ctx_buf = NULL;
2522 mbox->ctx_ndlp = NULL;
2523 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
2525 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
2526 lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
2528 if (status != MBX_TIMEOUT)
2529 mempool_free(mbox, phba->mbox_mem_pool);
2530 if (phba->sli_rev == LPFC_SLI_REV4)
2531 lpfc_sli4_free_rpi(phba, *rpi);
2535 if (phba->sli_rev < LPFC_SLI_REV4)
2536 *rpi = mbox->u.mb.un.varWords[0];
2538 lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
2540 mempool_free(mbox, phba->mbox_mem_pool);
2545 * lpfcdiag_loop_self_unreg - unregs from the rpi
2546 * @phba: Pointer to HBA context object
2547 * @rpi: Remote port login id
2549 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2551 static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi)
2556 /* Allocate mboxq structure */
2557 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2561 if (phba->sli_rev < LPFC_SLI_REV4)
2562 lpfc_unreg_login(phba, 0, rpi, mbox);
2564 lpfc_unreg_login(phba, phba->pport->vpi,
2565 phba->sli4_hba.rpi_ids[rpi], mbox);
2567 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
2569 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
2570 if (status != MBX_TIMEOUT)
2571 mempool_free(mbox, phba->mbox_mem_pool);
2574 mempool_free(mbox, phba->mbox_mem_pool);
2575 if (phba->sli_rev == LPFC_SLI_REV4)
2576 lpfc_sli4_free_rpi(phba, rpi);
2581 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2582 * @phba: Pointer to HBA context object
2583 * @rpi: Remote port login id
2584 * @txxri: Pointer to transmit exchange id
2585 * @rxxri: Pointer to response exchabge id
2587 * This function obtains the transmit and receive ids required to send
2588 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2589 * flags are used to the unsolicited response handler is able to process
2590 * the ct command sent on the same port.
2592 static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
2593 uint16_t *txxri, uint16_t * rxxri)
2595 struct lpfc_bsg_event *evt;
2596 struct lpfc_iocbq *cmdiocbq, *rspiocbq;
2597 struct lpfc_dmabuf *dmabuf;
2598 struct ulp_bde64 *bpl = NULL;
2599 struct lpfc_sli_ct_request *ctreq = NULL;
2602 int iocb_stat = IOCB_SUCCESS;
2603 unsigned long flags;
2608 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
2609 SLI_CT_ELX_LOOPBACK);
2613 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2614 list_add(&evt->node, &phba->ct_ev_waiters);
2615 lpfc_bsg_event_ref(evt);
2616 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2618 cmdiocbq = lpfc_sli_get_iocbq(phba);
2619 rspiocbq = lpfc_sli_get_iocbq(phba);
2621 dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2623 dmabuf->virt = lpfc_mbuf_alloc(phba, 0, &dmabuf->phys);
2625 INIT_LIST_HEAD(&dmabuf->list);
2626 bpl = (struct ulp_bde64 *) dmabuf->virt;
2627 memset(bpl, 0, sizeof(*bpl));
2628 ctreq = (struct lpfc_sli_ct_request *)(bpl + 1);
2630 le32_to_cpu(putPaddrHigh(dmabuf->phys +
2633 le32_to_cpu(putPaddrLow(dmabuf->phys +
2635 bpl->tus.f.bdeFlags = 0;
2636 bpl->tus.f.bdeSize = ELX_LOOPBACK_HEADER_SZ;
2637 bpl->tus.w = le32_to_cpu(bpl->tus.w);
2641 if (cmdiocbq == NULL || rspiocbq == NULL ||
2642 dmabuf == NULL || bpl == NULL || ctreq == NULL ||
2643 dmabuf->virt == NULL) {
2645 goto err_get_xri_exit;
2648 memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
2650 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
2651 ctreq->RevisionId.bits.InId = 0;
2652 ctreq->FsType = SLI_CT_ELX_LOOPBACK;
2653 ctreq->FsSubType = 0;
2654 ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_XRI_SETUP;
2655 ctreq->CommandResponse.bits.Size = 0;
2657 cmdiocbq->bpl_dmabuf = dmabuf;
2658 cmdiocbq->cmd_flag |= LPFC_IO_LIBDFC;
2659 cmdiocbq->vport = phba->pport;
2660 cmdiocbq->cmd_cmpl = NULL;
2662 lpfc_sli_prep_xmit_seq64(phba, cmdiocbq, dmabuf, rpi, 0, 1,
2663 FC_RCTL_DD_SOL_CTL, 0, CMD_XMIT_SEQUENCE64_CR);
2665 iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
2666 rspiocbq, (phba->fc_ratov * 2)
2667 + LPFC_DRVR_TIMEOUT);
2669 status = get_job_ulpstatus(phba, rspiocbq);
2670 if (iocb_stat != IOCB_SUCCESS || status != IOCB_SUCCESS) {
2672 goto err_get_xri_exit;
2674 *txxri = get_job_ulpcontext(phba, rspiocbq);
2677 evt->wait_time_stamp = jiffies;
2678 time_left = wait_event_interruptible_timeout(
2679 evt->wq, !list_empty(&evt->events_to_see),
2680 msecs_to_jiffies(1000 *
2681 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT)));
2682 if (list_empty(&evt->events_to_see))
2683 ret_val = (time_left) ? -EINTR : -ETIMEDOUT;
2685 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2686 list_move(evt->events_to_see.prev, &evt->events_to_get);
2687 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2688 *rxxri = (list_entry(evt->events_to_get.prev,
2689 typeof(struct event_data),
2695 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2696 lpfc_bsg_event_unref(evt); /* release ref */
2697 lpfc_bsg_event_unref(evt); /* delete */
2698 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2702 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2706 if (cmdiocbq && (iocb_stat != IOCB_TIMEDOUT))
2707 lpfc_sli_release_iocbq(phba, cmdiocbq);
2709 lpfc_sli_release_iocbq(phba, rspiocbq);
2714 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2715 * @phba: Pointer to HBA context object
2717 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and
2718 * returns the pointer to the buffer.
2720 static struct lpfc_dmabuf *
2721 lpfc_bsg_dma_page_alloc(struct lpfc_hba *phba)
2723 struct lpfc_dmabuf *dmabuf;
2724 struct pci_dev *pcidev = phba->pcidev;
2726 /* allocate dma buffer struct */
2727 dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2731 INIT_LIST_HEAD(&dmabuf->list);
2733 /* now, allocate dma buffer */
2734 dmabuf->virt = dma_alloc_coherent(&pcidev->dev, BSG_MBOX_SIZE,
2735 &(dmabuf->phys), GFP_KERNEL);
2737 if (!dmabuf->virt) {
2746 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2747 * @phba: Pointer to HBA context object.
2748 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2750 * This routine just simply frees a dma buffer and its associated buffer
2751 * descriptor referred by @dmabuf.
2754 lpfc_bsg_dma_page_free(struct lpfc_hba *phba, struct lpfc_dmabuf *dmabuf)
2756 struct pci_dev *pcidev = phba->pcidev;
2762 dma_free_coherent(&pcidev->dev, BSG_MBOX_SIZE,
2763 dmabuf->virt, dmabuf->phys);
2769 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2770 * @phba: Pointer to HBA context object.
2771 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2773 * This routine just simply frees all dma buffers and their associated buffer
2774 * descriptors referred by @dmabuf_list.
2777 lpfc_bsg_dma_page_list_free(struct lpfc_hba *phba,
2778 struct list_head *dmabuf_list)
2780 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
2782 if (list_empty(dmabuf_list))
2785 list_for_each_entry_safe(dmabuf, next_dmabuf, dmabuf_list, list) {
2786 list_del_init(&dmabuf->list);
2787 lpfc_bsg_dma_page_free(phba, dmabuf);
2793 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2794 * @phba: Pointer to HBA context object
2795 * @bpl: Pointer to 64 bit bde structure
2796 * @size: Number of bytes to process
2797 * @nocopydata: Flag to copy user data into the allocated buffer
2799 * This function allocates page size buffers and populates an lpfc_dmabufext.
2800 * If allowed the user data pointed to with indataptr is copied into the kernel
2801 * memory. The chained list of page size buffers is returned.
2803 static struct lpfc_dmabufext *
2804 diag_cmd_data_alloc(struct lpfc_hba *phba,
2805 struct ulp_bde64 *bpl, uint32_t size,
2808 struct lpfc_dmabufext *mlist = NULL;
2809 struct lpfc_dmabufext *dmp;
2810 int cnt, offset = 0, i = 0;
2811 struct pci_dev *pcidev;
2813 pcidev = phba->pcidev;
2816 /* We get chunks of 4K */
2817 if (size > BUF_SZ_4K)
2822 /* allocate struct lpfc_dmabufext buffer header */
2823 dmp = kmalloc(sizeof(struct lpfc_dmabufext), GFP_KERNEL);
2827 INIT_LIST_HEAD(&dmp->dma.list);
2829 /* Queue it to a linked list */
2831 list_add_tail(&dmp->dma.list, &mlist->dma.list);
2835 /* allocate buffer */
2836 dmp->dma.virt = dma_alloc_coherent(&pcidev->dev,
2847 bpl->tus.f.bdeFlags = 0;
2849 memset((uint8_t *)dmp->dma.virt, 0, cnt);
2850 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
2853 /* build buffer ptr list for IOCB */
2854 bpl->addrLow = le32_to_cpu(putPaddrLow(dmp->dma.phys));
2855 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dmp->dma.phys));
2856 bpl->tus.f.bdeSize = (ushort) cnt;
2857 bpl->tus.w = le32_to_cpu(bpl->tus.w);
2870 diag_cmd_data_free(phba, mlist);
2875 * lpfcdiag_sli3_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2876 * @phba: Pointer to HBA context object
2877 * @rxxri: Receive exchange id
2878 * @len: Number of data bytes
2880 * This function allocates and posts a data buffer of sufficient size to receive
2881 * an unsolicited CT command.
2883 static int lpfcdiag_sli3_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
2886 struct lpfc_sli_ring *pring;
2887 struct lpfc_iocbq *cmdiocbq;
2889 struct list_head head, *curr, *next;
2890 struct lpfc_dmabuf *rxbmp;
2891 struct lpfc_dmabuf *dmp;
2892 struct lpfc_dmabuf *mp[2] = {NULL, NULL};
2893 struct ulp_bde64 *rxbpl = NULL;
2895 struct lpfc_dmabufext *rxbuffer = NULL;
2900 pring = lpfc_phba_elsring(phba);
2902 cmdiocbq = lpfc_sli_get_iocbq(phba);
2903 rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2904 if (rxbmp != NULL) {
2905 rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys);
2907 INIT_LIST_HEAD(&rxbmp->list);
2908 rxbpl = (struct ulp_bde64 *) rxbmp->virt;
2909 rxbuffer = diag_cmd_data_alloc(phba, rxbpl, len, 0);
2913 if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer || !pring) {
2915 goto err_post_rxbufs_exit;
2918 /* Queue buffers for the receive exchange */
2919 num_bde = (uint32_t)rxbuffer->flag;
2920 dmp = &rxbuffer->dma;
2921 cmd = &cmdiocbq->iocb;
2924 INIT_LIST_HEAD(&head);
2925 list_add_tail(&head, &dmp->list);
2926 list_for_each_safe(curr, next, &head) {
2927 mp[i] = list_entry(curr, struct lpfc_dmabuf, list);
2930 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2931 mp[i]->buffer_tag = lpfc_sli_get_buffer_tag(phba);
2932 cmd->un.quexri64cx.buff.bde.addrHigh =
2933 putPaddrHigh(mp[i]->phys);
2934 cmd->un.quexri64cx.buff.bde.addrLow =
2935 putPaddrLow(mp[i]->phys);
2936 cmd->un.quexri64cx.buff.bde.tus.f.bdeSize =
2937 ((struct lpfc_dmabufext *)mp[i])->size;
2938 cmd->un.quexri64cx.buff.buffer_tag = mp[i]->buffer_tag;
2939 cmd->ulpCommand = CMD_QUE_XRI64_CX;
2942 cmd->ulpBdeCount = 1;
2943 cmd->unsli3.que_xri64cx_ext_words.ebde_count = 0;
2946 cmd->un.cont64[i].addrHigh = putPaddrHigh(mp[i]->phys);
2947 cmd->un.cont64[i].addrLow = putPaddrLow(mp[i]->phys);
2948 cmd->un.cont64[i].tus.f.bdeSize =
2949 ((struct lpfc_dmabufext *)mp[i])->size;
2950 cmd->ulpBdeCount = ++i;
2952 if ((--num_bde > 0) && (i < 2))
2955 cmd->ulpCommand = CMD_QUE_XRI_BUF64_CX;
2959 cmd->ulpClass = CLASS3;
2960 cmd->ulpContext = rxxri;
2962 iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq,
2964 if (iocb_stat == IOCB_ERROR) {
2965 diag_cmd_data_free(phba,
2966 (struct lpfc_dmabufext *)mp[0]);
2968 diag_cmd_data_free(phba,
2969 (struct lpfc_dmabufext *)mp[1]);
2970 dmp = list_entry(next, struct lpfc_dmabuf, list);
2972 goto err_post_rxbufs_exit;
2975 lpfc_sli_ringpostbuf_put(phba, pring, mp[0]);
2977 lpfc_sli_ringpostbuf_put(phba, pring, mp[1]);
2981 /* The iocb was freed by lpfc_sli_issue_iocb */
2982 cmdiocbq = lpfc_sli_get_iocbq(phba);
2984 dmp = list_entry(next, struct lpfc_dmabuf, list);
2986 goto err_post_rxbufs_exit;
2988 cmd = &cmdiocbq->iocb;
2993 err_post_rxbufs_exit:
2997 lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys);
3002 lpfc_sli_release_iocbq(phba, cmdiocbq);
3007 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
3008 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
3010 * This function receives a user data buffer to be transmitted and received on
3011 * the same port, the link must be up and in loopback mode prior
3013 * 1. A kernel buffer is allocated to copy the user data into.
3014 * 2. The port registers with "itself".
3015 * 3. The transmit and receive exchange ids are obtained.
3016 * 4. The receive exchange id is posted.
3017 * 5. A new els loopback event is created.
3018 * 6. The command and response iocbs are allocated.
3019 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
3021 * This function is meant to be called n times while the port is in loopback
3022 * so it is the apps responsibility to issue a reset to take the port out
3026 lpfc_bsg_diag_loopback_run(struct bsg_job *job)
3028 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
3029 struct fc_bsg_reply *bsg_reply = job->reply;
3030 struct lpfc_hba *phba = vport->phba;
3031 struct lpfc_bsg_event *evt;
3032 struct event_data *evdat;
3033 struct lpfc_sli *psli = &phba->sli;
3036 size_t segment_len = 0, segment_offset = 0, current_offset = 0;
3038 struct lpfc_iocbq *cmdiocbq, *rspiocbq = NULL;
3039 union lpfc_wqe128 *cmdwqe, *rspwqe;
3040 struct lpfc_sli_ct_request *ctreq;
3041 struct lpfc_dmabuf *txbmp;
3042 struct ulp_bde64 *txbpl = NULL;
3043 struct lpfc_dmabufext *txbuffer = NULL;
3044 struct list_head head;
3045 struct lpfc_dmabuf *curr;
3046 uint16_t txxri = 0, rxxri;
3048 uint8_t *ptr = NULL, *rx_databuf = NULL;
3051 int iocb_stat = IOCB_SUCCESS;
3052 unsigned long flags;
3053 void *dataout = NULL;
3056 /* in case no data is returned return just the return code */
3057 bsg_reply->reply_payload_rcv_len = 0;
3059 if (job->request_len <
3060 sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_test)) {
3061 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3062 "2739 Received DIAG TEST request below minimum "
3065 goto loopback_test_exit;
3068 if (job->request_payload.payload_len !=
3069 job->reply_payload.payload_len) {
3071 goto loopback_test_exit;
3074 if ((phba->link_state == LPFC_HBA_ERROR) ||
3075 (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
3076 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
3078 goto loopback_test_exit;
3081 if (!lpfc_is_link_up(phba) || !(phba->link_flag & LS_LOOPBACK_MODE)) {
3083 goto loopback_test_exit;
3086 size = job->request_payload.payload_len;
3087 full_size = size + ELX_LOOPBACK_HEADER_SZ; /* plus the header */
3089 if ((size == 0) || (size > 80 * BUF_SZ_4K)) {
3091 goto loopback_test_exit;
3094 if (full_size >= BUF_SZ_4K) {
3096 * Allocate memory for ioctl data. If buffer is bigger than 64k,
3097 * then we allocate 64k and re-use that buffer over and over to
3098 * xfer the whole block. This is because Linux kernel has a
3099 * problem allocating more than 120k of kernel space memory. Saw
3100 * problem with GET_FCPTARGETMAPPING...
3102 if (size <= (64 * 1024))
3103 total_mem = full_size;
3105 total_mem = 64 * 1024;
3107 /* Allocate memory for ioctl data */
3108 total_mem = BUF_SZ_4K;
3110 dataout = kmalloc(total_mem, GFP_KERNEL);
3111 if (dataout == NULL) {
3113 goto loopback_test_exit;
3117 ptr += ELX_LOOPBACK_HEADER_SZ;
3118 sg_copy_to_buffer(job->request_payload.sg_list,
3119 job->request_payload.sg_cnt,
3121 rc = lpfcdiag_loop_self_reg(phba, &rpi);
3123 goto loopback_test_exit;
3125 if (phba->sli_rev < LPFC_SLI_REV4) {
3126 rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri);
3128 lpfcdiag_loop_self_unreg(phba, rpi);
3129 goto loopback_test_exit;
3132 rc = lpfcdiag_sli3_loop_post_rxbufs(phba, rxxri, full_size);
3134 lpfcdiag_loop_self_unreg(phba, rpi);
3135 goto loopback_test_exit;
3138 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
3139 SLI_CT_ELX_LOOPBACK);
3141 lpfcdiag_loop_self_unreg(phba, rpi);
3143 goto loopback_test_exit;
3146 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3147 list_add(&evt->node, &phba->ct_ev_waiters);
3148 lpfc_bsg_event_ref(evt);
3149 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3151 cmdiocbq = lpfc_sli_get_iocbq(phba);
3152 if (phba->sli_rev < LPFC_SLI_REV4)
3153 rspiocbq = lpfc_sli_get_iocbq(phba);
3154 txbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3157 txbmp->virt = lpfc_mbuf_alloc(phba, 0, &txbmp->phys);
3159 INIT_LIST_HEAD(&txbmp->list);
3160 txbpl = (struct ulp_bde64 *) txbmp->virt;
3161 txbuffer = diag_cmd_data_alloc(phba,
3162 txbpl, full_size, 0);
3166 if (!cmdiocbq || !txbmp || !txbpl || !txbuffer || !txbmp->virt) {
3168 goto err_loopback_test_exit;
3170 if ((phba->sli_rev < LPFC_SLI_REV4) && !rspiocbq) {
3172 goto err_loopback_test_exit;
3175 cmdwqe = &cmdiocbq->wqe;
3176 memset(cmdwqe, 0, sizeof(*cmdwqe));
3177 if (phba->sli_rev < LPFC_SLI_REV4) {
3178 rspwqe = &rspiocbq->wqe;
3179 memset(rspwqe, 0, sizeof(*rspwqe));
3182 INIT_LIST_HEAD(&head);
3183 list_add_tail(&head, &txbuffer->dma.list);
3184 list_for_each_entry(curr, &head, list) {
3185 segment_len = ((struct lpfc_dmabufext *)curr)->size;
3186 if (current_offset == 0) {
3188 memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
3189 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
3190 ctreq->RevisionId.bits.InId = 0;
3191 ctreq->FsType = SLI_CT_ELX_LOOPBACK;
3192 ctreq->FsSubType = 0;
3193 ctreq->CommandResponse.bits.CmdRsp = cpu_to_be16(ELX_LOOPBACK_DATA);
3194 ctreq->CommandResponse.bits.Size = cpu_to_be16(size);
3195 segment_offset = ELX_LOOPBACK_HEADER_SZ;
3199 BUG_ON(segment_offset >= segment_len);
3200 memcpy(curr->virt + segment_offset,
3201 ptr + current_offset,
3202 segment_len - segment_offset);
3204 current_offset += segment_len - segment_offset;
3205 BUG_ON(current_offset > size);
3209 /* Build the XMIT_SEQUENCE iocb */
3210 num_bde = (uint32_t)txbuffer->flag;
3212 cmdiocbq->num_bdes = num_bde;
3213 cmdiocbq->cmd_flag |= LPFC_IO_LIBDFC;
3214 cmdiocbq->cmd_flag |= LPFC_IO_LOOPBACK;
3215 if (phba->cfg_vmid_app_header)
3216 cmdiocbq->cmd_flag |= LPFC_IO_VMID;
3218 cmdiocbq->vport = phba->pport;
3219 cmdiocbq->cmd_cmpl = NULL;
3220 cmdiocbq->bpl_dmabuf = txbmp;
3222 if (phba->sli_rev < LPFC_SLI_REV4) {
3223 lpfc_sli_prep_xmit_seq64(phba, cmdiocbq, txbmp, 0, txxri,
3224 num_bde, FC_RCTL_DD_UNSOL_CTL, 1,
3225 CMD_XMIT_SEQUENCE64_CX);
3228 lpfc_sli_prep_xmit_seq64(phba, cmdiocbq, txbmp,
3229 phba->sli4_hba.rpi_ids[rpi], 0xffff,
3230 full_size, FC_RCTL_DD_UNSOL_CTL, 1,
3231 CMD_XMIT_SEQUENCE64_WQE);
3232 cmdiocbq->sli4_xritag = NO_XRI;
3235 iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
3236 rspiocbq, (phba->fc_ratov * 2) +
3238 if (iocb_stat != IOCB_SUCCESS ||
3239 (phba->sli_rev < LPFC_SLI_REV4 &&
3240 (get_job_ulpstatus(phba, rspiocbq) != IOSTAT_SUCCESS))) {
3241 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3242 "3126 Failed loopback test issue iocb: "
3243 "iocb_stat:x%x\n", iocb_stat);
3245 goto err_loopback_test_exit;
3249 time_left = wait_event_interruptible_timeout(
3250 evt->wq, !list_empty(&evt->events_to_see),
3251 msecs_to_jiffies(1000 *
3252 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT)));
3254 if (list_empty(&evt->events_to_see)) {
3255 rc = (time_left) ? -EINTR : -ETIMEDOUT;
3256 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3257 "3125 Not receiving unsolicited event, "
3260 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3261 list_move(evt->events_to_see.prev, &evt->events_to_get);
3262 evdat = list_entry(evt->events_to_get.prev,
3263 typeof(*evdat), node);
3264 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3265 rx_databuf = evdat->data;
3266 if (evdat->len != full_size) {
3267 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3268 "1603 Loopback test did not receive expected "
3269 "data length. actual length 0x%x expected "
3271 evdat->len, full_size);
3273 } else if (rx_databuf == NULL)
3277 /* skip over elx loopback header */
3278 rx_databuf += ELX_LOOPBACK_HEADER_SZ;
3279 bsg_reply->reply_payload_rcv_len =
3280 sg_copy_from_buffer(job->reply_payload.sg_list,
3281 job->reply_payload.sg_cnt,
3283 bsg_reply->reply_payload_rcv_len = size;
3287 err_loopback_test_exit:
3288 lpfcdiag_loop_self_unreg(phba, rpi);
3290 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3291 lpfc_bsg_event_unref(evt); /* release ref */
3292 lpfc_bsg_event_unref(evt); /* delete */
3293 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3295 if ((cmdiocbq != NULL) && (iocb_stat != IOCB_TIMEDOUT))
3296 lpfc_sli_release_iocbq(phba, cmdiocbq);
3298 if (rspiocbq != NULL)
3299 lpfc_sli_release_iocbq(phba, rspiocbq);
3301 if (txbmp != NULL) {
3302 if (txbpl != NULL) {
3303 if (txbuffer != NULL)
3304 diag_cmd_data_free(phba, txbuffer);
3305 lpfc_mbuf_free(phba, txbmp->virt, txbmp->phys);
3312 /* make error code available to userspace */
3313 bsg_reply->result = rc;
3314 job->dd_data = NULL;
3315 /* complete the job back to userspace if no error */
3316 if (rc == IOCB_SUCCESS)
3317 bsg_job_done(job, bsg_reply->result,
3318 bsg_reply->reply_payload_rcv_len);
3323 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
3324 * @job: GET_DFC_REV fc_bsg_job
3327 lpfc_bsg_get_dfc_rev(struct bsg_job *job)
3329 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
3330 struct fc_bsg_reply *bsg_reply = job->reply;
3331 struct lpfc_hba *phba = vport->phba;
3332 struct get_mgmt_rev_reply *event_reply;
3335 if (job->request_len <
3336 sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev)) {
3337 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3338 "2740 Received GET_DFC_REV request below "
3344 event_reply = (struct get_mgmt_rev_reply *)
3345 bsg_reply->reply_data.vendor_reply.vendor_rsp;
3347 if (job->reply_len < sizeof(*bsg_reply) + sizeof(*event_reply)) {
3348 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3349 "2741 Received GET_DFC_REV reply below "
3355 event_reply->info.a_Major = MANAGEMENT_MAJOR_REV;
3356 event_reply->info.a_Minor = MANAGEMENT_MINOR_REV;
3358 bsg_reply->result = rc;
3360 bsg_job_done(job, bsg_reply->result,
3361 bsg_reply->reply_payload_rcv_len);
3366 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
3367 * @phba: Pointer to HBA context object.
3368 * @pmboxq: Pointer to mailbox command.
3370 * This is completion handler function for mailbox commands issued from
3371 * lpfc_bsg_issue_mbox function. This function is called by the
3372 * mailbox event handler function with no lock held. This function
3373 * will wake up thread waiting on the wait queue pointed by dd_data
3377 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3379 struct bsg_job_data *dd_data;
3380 struct fc_bsg_reply *bsg_reply;
3381 struct bsg_job *job;
3383 unsigned long flags;
3384 uint8_t *pmb, *pmb_buf;
3386 dd_data = pmboxq->ctx_u.dd_data;
3389 * The outgoing buffer is readily referred from the dma buffer,
3390 * just need to get header part from mailboxq structure.
3392 pmb = (uint8_t *)&pmboxq->u.mb;
3393 pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb;
3394 memcpy(pmb_buf, pmb, sizeof(MAILBOX_t));
3396 /* Determine if job has been aborted */
3398 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3399 job = dd_data->set_job;
3401 /* Prevent timeout handling from trying to abort job */
3402 job->dd_data = NULL;
3404 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3406 /* Copy the mailbox data to the job if it is still active */
3409 bsg_reply = job->reply;
3410 size = job->reply_payload.payload_len;
3411 bsg_reply->reply_payload_rcv_len =
3412 sg_copy_from_buffer(job->reply_payload.sg_list,
3413 job->reply_payload.sg_cnt,
3417 dd_data->set_job = NULL;
3418 mempool_free(dd_data->context_un.mbox.pmboxq, phba->mbox_mem_pool);
3419 lpfc_bsg_dma_page_free(phba, dd_data->context_un.mbox.dmabuffers);
3422 /* Complete the job if the job is still active */
3425 bsg_reply->result = 0;
3426 bsg_job_done(job, bsg_reply->result,
3427 bsg_reply->reply_payload_rcv_len);
3433 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3434 * @phba: Pointer to HBA context object.
3435 * @mb: Pointer to a mailbox object.
3436 * @vport: Pointer to a vport object.
3438 * Some commands require the port to be offline, some may not be called from
3441 static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba,
3442 MAILBOX_t *mb, struct lpfc_vport *vport)
3444 /* return negative error values for bsg job */
3445 switch (mb->mbxCommand) {
3449 case MBX_CONFIG_LINK:
3450 case MBX_CONFIG_RING:
3451 case MBX_RESET_RING:
3452 case MBX_UNREG_LOGIN:
3454 case MBX_DUMP_CONTEXT:
3458 if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
3459 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3460 "2743 Command 0x%x is illegal in on-line "
3467 case MBX_WRITE_VPARMS:
3470 case MBX_READ_CONFIG:
3471 case MBX_READ_RCONFIG:
3472 case MBX_READ_STATUS:
3475 case MBX_READ_LNK_STAT:
3476 case MBX_DUMP_MEMORY:
3478 case MBX_UPDATE_CFG:
3479 case MBX_KILL_BOARD:
3480 case MBX_READ_TOPOLOGY:
3482 case MBX_LOAD_EXP_ROM:
3484 case MBX_DEL_LD_ENTRY:
3487 case MBX_SLI4_CONFIG:
3488 case MBX_READ_EVENT_LOG:
3489 case MBX_READ_EVENT_LOG_STATUS:
3490 case MBX_WRITE_EVENT_LOG:
3491 case MBX_PORT_CAPABILITIES:
3492 case MBX_PORT_IOV_CONTROL:
3493 case MBX_RUN_BIU_DIAG64:
3495 case MBX_SET_VARIABLE:
3496 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3497 "1226 mbox: set_variable 0x%x, 0x%x\n",
3499 mb->un.varWords[1]);
3501 case MBX_READ_SPARM64:
3503 case MBX_REG_LOGIN64:
3504 case MBX_CONFIG_PORT:
3505 case MBX_RUN_BIU_DIAG:
3507 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3508 "2742 Unknown Command 0x%x\n",
3517 * lpfc_bsg_mbox_ext_session_reset - clean up context of multi-buffer mbox session
3518 * @phba: Pointer to HBA context object.
3520 * This is routine clean up and reset BSG handling of multi-buffer mbox
3524 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba *phba)
3526 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE)
3529 /* free all memory, including dma buffers */
3530 lpfc_bsg_dma_page_list_free(phba,
3531 &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3532 lpfc_bsg_dma_page_free(phba, phba->mbox_ext_buf_ctx.mbx_dmabuf);
3533 /* multi-buffer write mailbox command pass-through complete */
3534 memset((char *)&phba->mbox_ext_buf_ctx, 0,
3535 sizeof(struct lpfc_mbox_ext_buf_ctx));
3536 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3542 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3543 * @phba: Pointer to HBA context object.
3544 * @pmboxq: Pointer to mailbox command.
3546 * This is routine handles BSG job for mailbox commands completions with
3547 * multiple external buffers.
3549 static struct bsg_job *
3550 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3552 struct bsg_job_data *dd_data;
3553 struct bsg_job *job;
3554 struct fc_bsg_reply *bsg_reply;
3555 uint8_t *pmb, *pmb_buf;
3556 unsigned long flags;
3559 struct lpfc_dmabuf *dmabuf;
3560 struct lpfc_sli_config_mbox *sli_cfg_mbx;
3563 dd_data = pmboxq->ctx_u.dd_data;
3565 /* Determine if job has been aborted */
3566 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3567 job = dd_data->set_job;
3569 bsg_reply = job->reply;
3570 /* Prevent timeout handling from trying to abort job */
3571 job->dd_data = NULL;
3573 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3576 * The outgoing buffer is readily referred from the dma buffer,
3577 * just need to get header part from mailboxq structure.
3580 pmb = (uint8_t *)&pmboxq->u.mb;
3581 pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb;
3582 /* Copy the byte swapped response mailbox back to the user */
3583 memcpy(pmb_buf, pmb, sizeof(MAILBOX_t));
3584 /* if there is any non-embedded extended data copy that too */
3585 dmabuf = phba->mbox_ext_buf_ctx.mbx_dmabuf;
3586 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
3587 if (!bsg_bf_get(lpfc_mbox_hdr_emb,
3588 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) {
3589 pmbx = (uint8_t *)dmabuf->virt;
3590 /* byte swap the extended data following the mailbox command */
3591 lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)],
3592 &pmbx[sizeof(MAILBOX_t)],
3593 sli_cfg_mbx->un.sli_config_emb0_subsys.mse[0].buf_len);
3596 /* Complete the job if the job is still active */
3599 size = job->reply_payload.payload_len;
3600 bsg_reply->reply_payload_rcv_len =
3601 sg_copy_from_buffer(job->reply_payload.sg_list,
3602 job->reply_payload.sg_cnt,
3605 /* result for successful */
3606 bsg_reply->result = 0;
3608 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3609 "2937 SLI_CONFIG ext-buffer mailbox command "
3610 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3611 phba->mbox_ext_buf_ctx.nembType,
3612 phba->mbox_ext_buf_ctx.mboxType, size);
3613 lpfc_idiag_mbxacc_dump_bsg_mbox(phba,
3614 phba->mbox_ext_buf_ctx.nembType,
3615 phba->mbox_ext_buf_ctx.mboxType,
3616 dma_ebuf, sta_pos_addr,
3617 phba->mbox_ext_buf_ctx.mbx_dmabuf, 0);
3619 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3620 "2938 SLI_CONFIG ext-buffer mailbox "
3621 "command (x%x/x%x) failure, rc:x%x\n",
3622 phba->mbox_ext_buf_ctx.nembType,
3623 phba->mbox_ext_buf_ctx.mboxType, rc);
3628 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_DONE;
3634 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3635 * @phba: Pointer to HBA context object.
3636 * @pmboxq: Pointer to mailbox command.
3638 * This is completion handler function for mailbox read commands with multiple
3642 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3644 struct bsg_job *job;
3645 struct fc_bsg_reply *bsg_reply;
3647 job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq);
3649 /* handle the BSG job with mailbox command */
3651 pmboxq->u.mb.mbxStatus = MBXERR_ERROR;
3653 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3654 "2939 SLI_CONFIG ext-buffer rd mailbox command "
3655 "complete, ctxState:x%x, mbxStatus:x%x\n",
3656 phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus);
3658 if (pmboxq->u.mb.mbxStatus || phba->mbox_ext_buf_ctx.numBuf == 1)
3659 lpfc_bsg_mbox_ext_session_reset(phba);
3661 /* free base driver mailbox structure memory */
3662 mempool_free(pmboxq, phba->mbox_mem_pool);
3664 /* if the job is still active, call job done */
3666 bsg_reply = job->reply;
3667 bsg_job_done(job, bsg_reply->result,
3668 bsg_reply->reply_payload_rcv_len);
3674 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3675 * @phba: Pointer to HBA context object.
3676 * @pmboxq: Pointer to mailbox command.
3678 * This is completion handler function for mailbox write commands with multiple
3682 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3684 struct bsg_job *job;
3685 struct fc_bsg_reply *bsg_reply;
3687 job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq);
3689 /* handle the BSG job with the mailbox command */
3691 pmboxq->u.mb.mbxStatus = MBXERR_ERROR;
3693 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3694 "2940 SLI_CONFIG ext-buffer wr mailbox command "
3695 "complete, ctxState:x%x, mbxStatus:x%x\n",
3696 phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus);
3698 /* free all memory, including dma buffers */
3699 mempool_free(pmboxq, phba->mbox_mem_pool);
3700 lpfc_bsg_mbox_ext_session_reset(phba);
3702 /* if the job is still active, call job done */
3704 bsg_reply = job->reply;
3705 bsg_job_done(job, bsg_reply->result,
3706 bsg_reply->reply_payload_rcv_len);
3713 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3714 uint32_t index, struct lpfc_dmabuf *mbx_dmabuf,
3715 struct lpfc_dmabuf *ext_dmabuf)
3717 struct lpfc_sli_config_mbox *sli_cfg_mbx;
3719 /* pointer to the start of mailbox command */
3720 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)mbx_dmabuf->virt;
3722 if (nemb_tp == nemb_mse) {
3724 sli_cfg_mbx->un.sli_config_emb0_subsys.
3726 putPaddrHigh(mbx_dmabuf->phys +
3728 sli_cfg_mbx->un.sli_config_emb0_subsys.
3730 putPaddrLow(mbx_dmabuf->phys +
3732 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3733 "2943 SLI_CONFIG(mse)[%d], "
3734 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3736 sli_cfg_mbx->un.sli_config_emb0_subsys.
3738 sli_cfg_mbx->un.sli_config_emb0_subsys.
3740 sli_cfg_mbx->un.sli_config_emb0_subsys.
3743 sli_cfg_mbx->un.sli_config_emb0_subsys.
3745 putPaddrHigh(ext_dmabuf->phys);
3746 sli_cfg_mbx->un.sli_config_emb0_subsys.
3748 putPaddrLow(ext_dmabuf->phys);
3749 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3750 "2944 SLI_CONFIG(mse)[%d], "
3751 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3753 sli_cfg_mbx->un.sli_config_emb0_subsys.
3755 sli_cfg_mbx->un.sli_config_emb0_subsys.
3757 sli_cfg_mbx->un.sli_config_emb0_subsys.
3762 sli_cfg_mbx->un.sli_config_emb1_subsys.
3764 putPaddrHigh(mbx_dmabuf->phys +
3766 sli_cfg_mbx->un.sli_config_emb1_subsys.
3768 putPaddrLow(mbx_dmabuf->phys +
3770 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3771 "3007 SLI_CONFIG(hbd)[%d], "
3772 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3774 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
3776 sli_config_emb1_subsys.hbd[index]),
3777 sli_cfg_mbx->un.sli_config_emb1_subsys.
3779 sli_cfg_mbx->un.sli_config_emb1_subsys.
3783 sli_cfg_mbx->un.sli_config_emb1_subsys.
3785 putPaddrHigh(ext_dmabuf->phys);
3786 sli_cfg_mbx->un.sli_config_emb1_subsys.
3788 putPaddrLow(ext_dmabuf->phys);
3789 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3790 "3008 SLI_CONFIG(hbd)[%d], "
3791 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3793 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
3795 sli_config_emb1_subsys.hbd[index]),
3796 sli_cfg_mbx->un.sli_config_emb1_subsys.
3798 sli_cfg_mbx->un.sli_config_emb1_subsys.
3806 * lpfc_bsg_sli_cfg_read_cmd_ext - sli_config non-embedded mailbox cmd read
3807 * @phba: Pointer to HBA context object.
3808 * @job: Pointer to the job object.
3809 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3810 * @dmabuf: Pointer to a DMA buffer descriptor.
3812 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3813 * non-embedded external buffers.
3816 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba *phba, struct bsg_job *job,
3817 enum nemb_type nemb_tp,
3818 struct lpfc_dmabuf *dmabuf)
3820 struct fc_bsg_request *bsg_request = job->request;
3821 struct lpfc_sli_config_mbox *sli_cfg_mbx;
3822 struct dfc_mbox_req *mbox_req;
3823 struct lpfc_dmabuf *curr_dmabuf, *next_dmabuf;
3824 uint32_t ext_buf_cnt, ext_buf_index;
3825 struct lpfc_dmabuf *ext_dmabuf = NULL;
3826 struct bsg_job_data *dd_data = NULL;
3827 LPFC_MBOXQ_t *pmboxq = NULL;
3833 (struct dfc_mbox_req *)bsg_request->rqst_data.h_vendor.vendor_cmd;
3835 /* pointer to the start of mailbox command */
3836 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
3838 if (nemb_tp == nemb_mse) {
3839 ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt,
3840 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr);
3841 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) {
3842 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3843 "2945 Handled SLI_CONFIG(mse) rd, "
3844 "ext_buf_cnt(%d) out of range(%d)\n",
3846 LPFC_MBX_SLI_CONFIG_MAX_MSE);
3850 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3851 "2941 Handled SLI_CONFIG(mse) rd, "
3852 "ext_buf_cnt:%d\n", ext_buf_cnt);
3854 /* sanity check on interface type for support */
3855 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
3856 LPFC_SLI_INTF_IF_TYPE_2) {
3860 /* nemb_tp == nemb_hbd */
3861 ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count;
3862 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) {
3863 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3864 "2946 Handled SLI_CONFIG(hbd) rd, "
3865 "ext_buf_cnt(%d) out of range(%d)\n",
3867 LPFC_MBX_SLI_CONFIG_MAX_HBD);
3871 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3872 "2942 Handled SLI_CONFIG(hbd) rd, "
3873 "ext_buf_cnt:%d\n", ext_buf_cnt);
3876 /* before dma descriptor setup */
3877 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox,
3878 sta_pre_addr, dmabuf, ext_buf_cnt);
3880 /* reject non-embedded mailbox command with none external buffer */
3881 if (ext_buf_cnt == 0) {
3884 } else if (ext_buf_cnt > 1) {
3885 /* additional external read buffers */
3886 for (i = 1; i < ext_buf_cnt; i++) {
3887 ext_dmabuf = lpfc_bsg_dma_page_alloc(phba);
3892 list_add_tail(&ext_dmabuf->list,
3893 &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3897 /* bsg tracking structure */
3898 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
3904 /* mailbox command structure for base driver */
3905 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3910 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3912 /* for the first external buffer */
3913 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf);
3915 /* for the rest of external buffer descriptors if any */
3916 if (ext_buf_cnt > 1) {
3918 list_for_each_entry_safe(curr_dmabuf, next_dmabuf,
3919 &phba->mbox_ext_buf_ctx.ext_dmabuf_list, list) {
3920 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp,
3921 ext_buf_index, dmabuf,
3927 /* after dma descriptor setup */
3928 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox,
3929 sta_pos_addr, dmabuf, ext_buf_cnt);
3931 /* construct base driver mbox command */
3932 pmb = &pmboxq->u.mb;
3933 pmbx = (uint8_t *)dmabuf->virt;
3934 memcpy(pmb, pmbx, sizeof(*pmb));
3935 pmb->mbxOwner = OWN_HOST;
3936 pmboxq->vport = phba->pport;
3938 /* multi-buffer handling context */
3939 phba->mbox_ext_buf_ctx.nembType = nemb_tp;
3940 phba->mbox_ext_buf_ctx.mboxType = mbox_rd;
3941 phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt;
3942 phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag;
3943 phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum;
3944 phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf;
3946 /* callback for multi-buffer read mailbox command */
3947 pmboxq->mbox_cmpl = lpfc_bsg_issue_read_mbox_ext_cmpl;
3949 /* context fields to callback function */
3950 pmboxq->ctx_u.dd_data = dd_data;
3951 dd_data->type = TYPE_MBOX;
3952 dd_data->set_job = job;
3953 dd_data->context_un.mbox.pmboxq = pmboxq;
3954 dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx;
3955 job->dd_data = dd_data;
3958 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
3961 * Non-embedded mailbox subcommand data gets byte swapped here because
3962 * the lower level driver code only does the first 64 mailbox words.
3964 if ((!bsg_bf_get(lpfc_mbox_hdr_emb,
3965 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) &&
3966 (nemb_tp == nemb_mse))
3967 lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)],
3968 &pmbx[sizeof(MAILBOX_t)],
3969 sli_cfg_mbx->un.sli_config_emb0_subsys.
3972 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3973 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
3974 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3975 "2947 Issued SLI_CONFIG ext-buffer "
3976 "mailbox command, rc:x%x\n", rc);
3977 return SLI_CONFIG_HANDLED;
3979 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3980 "2948 Failed to issue SLI_CONFIG ext-buffer "
3981 "mailbox command, rc:x%x\n", rc);
3986 mempool_free(pmboxq, phba->mbox_mem_pool);
3987 lpfc_bsg_dma_page_list_free(phba,
3988 &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3990 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE;
3995 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
3996 * @phba: Pointer to HBA context object.
3997 * @job: Pointer to the job object.
3998 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3999 * @dmabuf: Pointer to a DMA buffer descriptor.
4001 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
4002 * non-embedded external buffers.
4005 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba *phba, struct bsg_job *job,
4006 enum nemb_type nemb_tp,
4007 struct lpfc_dmabuf *dmabuf)
4009 struct fc_bsg_request *bsg_request = job->request;
4010 struct fc_bsg_reply *bsg_reply = job->reply;
4011 struct dfc_mbox_req *mbox_req;
4012 struct lpfc_sli_config_mbox *sli_cfg_mbx;
4013 uint32_t ext_buf_cnt;
4014 struct bsg_job_data *dd_data = NULL;
4015 LPFC_MBOXQ_t *pmboxq = NULL;
4018 int rc = SLI_CONFIG_NOT_HANDLED, i;
4021 (struct dfc_mbox_req *)bsg_request->rqst_data.h_vendor.vendor_cmd;
4023 /* pointer to the start of mailbox command */
4024 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
4026 if (nemb_tp == nemb_mse) {
4027 ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt,
4028 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr);
4029 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) {
4030 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4031 "2953 Failed SLI_CONFIG(mse) wr, "
4032 "ext_buf_cnt(%d) out of range(%d)\n",
4034 LPFC_MBX_SLI_CONFIG_MAX_MSE);
4037 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4038 "2949 Handled SLI_CONFIG(mse) wr, "
4039 "ext_buf_cnt:%d\n", ext_buf_cnt);
4041 /* sanity check on interface type for support */
4042 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
4043 LPFC_SLI_INTF_IF_TYPE_2)
4045 /* nemb_tp == nemb_hbd */
4046 ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count;
4047 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) {
4048 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4049 "2954 Failed SLI_CONFIG(hbd) wr, "
4050 "ext_buf_cnt(%d) out of range(%d)\n",
4052 LPFC_MBX_SLI_CONFIG_MAX_HBD);
4055 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4056 "2950 Handled SLI_CONFIG(hbd) wr, "
4057 "ext_buf_cnt:%d\n", ext_buf_cnt);
4060 /* before dma buffer descriptor setup */
4061 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox,
4062 sta_pre_addr, dmabuf, ext_buf_cnt);
4064 if (ext_buf_cnt == 0)
4067 /* for the first external buffer */
4068 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf);
4070 /* after dma descriptor setup */
4071 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox,
4072 sta_pos_addr, dmabuf, ext_buf_cnt);
4074 /* log for looking forward */
4075 for (i = 1; i < ext_buf_cnt; i++) {
4076 if (nemb_tp == nemb_mse)
4077 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4078 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
4079 i, sli_cfg_mbx->un.sli_config_emb0_subsys.
4082 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4083 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
4084 i, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
4085 &sli_cfg_mbx->un.sli_config_emb1_subsys.
4089 /* multi-buffer handling context */
4090 phba->mbox_ext_buf_ctx.nembType = nemb_tp;
4091 phba->mbox_ext_buf_ctx.mboxType = mbox_wr;
4092 phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt;
4093 phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag;
4094 phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum;
4095 phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf;
4097 if (ext_buf_cnt == 1) {
4098 /* bsg tracking structure */
4099 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
4105 /* mailbox command structure for base driver */
4106 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4111 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4112 pmb = &pmboxq->u.mb;
4113 mbx = (uint8_t *)dmabuf->virt;
4114 memcpy(pmb, mbx, sizeof(*pmb));
4115 pmb->mbxOwner = OWN_HOST;
4116 pmboxq->vport = phba->pport;
4118 /* callback for multi-buffer read mailbox command */
4119 pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl;
4121 /* context fields to callback function */
4122 pmboxq->ctx_u.dd_data = dd_data;
4123 dd_data->type = TYPE_MBOX;
4124 dd_data->set_job = job;
4125 dd_data->context_un.mbox.pmboxq = pmboxq;
4126 dd_data->context_un.mbox.mb = (MAILBOX_t *)mbx;
4127 job->dd_data = dd_data;
4131 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
4132 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
4133 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
4134 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4135 "2955 Issued SLI_CONFIG ext-buffer "
4136 "mailbox command, rc:x%x\n", rc);
4137 return SLI_CONFIG_HANDLED;
4139 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4140 "2956 Failed to issue SLI_CONFIG ext-buffer "
4141 "mailbox command, rc:x%x\n", rc);
4146 /* wait for additional external buffers */
4148 bsg_reply->result = 0;
4149 bsg_job_done(job, bsg_reply->result,
4150 bsg_reply->reply_payload_rcv_len);
4151 return SLI_CONFIG_HANDLED;
4155 mempool_free(pmboxq, phba->mbox_mem_pool);
4162 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
4163 * @phba: Pointer to HBA context object.
4164 * @job: Pointer to the job object.
4165 * @dmabuf: Pointer to a DMA buffer descriptor.
4167 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
4168 * external buffers, including both 0x9B with non-embedded MSEs and 0x9B
4169 * with embedded subsystem 0x1 and opcodes with external HBDs.
4172 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba *phba, struct bsg_job *job,
4173 struct lpfc_dmabuf *dmabuf)
4175 struct lpfc_sli_config_mbox *sli_cfg_mbx;
4178 int rc = SLI_CONFIG_NOT_HANDLED;
4180 /* state change on new multi-buffer pass-through mailbox command */
4181 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_HOST;
4183 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
4185 if (!bsg_bf_get(lpfc_mbox_hdr_emb,
4186 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) {
4187 subsys = bsg_bf_get(lpfc_emb0_subcmnd_subsys,
4188 &sli_cfg_mbx->un.sli_config_emb0_subsys);
4189 opcode = bsg_bf_get(lpfc_emb0_subcmnd_opcode,
4190 &sli_cfg_mbx->un.sli_config_emb0_subsys);
4191 if (subsys == SLI_CONFIG_SUBSYS_FCOE) {
4193 case FCOE_OPCODE_READ_FCF:
4194 case FCOE_OPCODE_GET_DPORT_RESULTS:
4195 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4196 "2957 Handled SLI_CONFIG "
4197 "subsys_fcoe, opcode:x%x\n",
4199 rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
4202 case FCOE_OPCODE_ADD_FCF:
4203 case FCOE_OPCODE_SET_DPORT_MODE:
4204 case LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE:
4205 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4206 "2958 Handled SLI_CONFIG "
4207 "subsys_fcoe, opcode:x%x\n",
4209 rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job,
4213 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4214 "2959 Reject SLI_CONFIG "
4215 "subsys_fcoe, opcode:x%x\n",
4220 } else if (subsys == SLI_CONFIG_SUBSYS_COMN) {
4222 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES:
4223 case COMN_OPCODE_GET_CNTL_ATTRIBUTES:
4224 case COMN_OPCODE_GET_PROFILE_CONFIG:
4225 case COMN_OPCODE_SET_FEATURES:
4226 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4227 "3106 Handled SLI_CONFIG "
4228 "subsys_comn, opcode:x%x\n",
4230 rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
4234 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4235 "3107 Reject SLI_CONFIG "
4236 "subsys_comn, opcode:x%x\n",
4242 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4243 "2977 Reject SLI_CONFIG "
4244 "subsys:x%d, opcode:x%x\n",
4249 subsys = bsg_bf_get(lpfc_emb1_subcmnd_subsys,
4250 &sli_cfg_mbx->un.sli_config_emb1_subsys);
4251 opcode = bsg_bf_get(lpfc_emb1_subcmnd_opcode,
4252 &sli_cfg_mbx->un.sli_config_emb1_subsys);
4253 if (subsys == SLI_CONFIG_SUBSYS_COMN) {
4255 case COMN_OPCODE_READ_OBJECT:
4256 case COMN_OPCODE_READ_OBJECT_LIST:
4257 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4258 "2960 Handled SLI_CONFIG "
4259 "subsys_comn, opcode:x%x\n",
4261 rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
4264 case COMN_OPCODE_WRITE_OBJECT:
4265 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4266 "2961 Handled SLI_CONFIG "
4267 "subsys_comn, opcode:x%x\n",
4269 rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job,
4273 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4274 "2962 Not handled SLI_CONFIG "
4275 "subsys_comn, opcode:x%x\n",
4277 rc = SLI_CONFIG_NOT_HANDLED;
4281 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4282 "2978 Not handled SLI_CONFIG "
4283 "subsys:x%d, opcode:x%x\n",
4285 rc = SLI_CONFIG_NOT_HANDLED;
4289 /* state reset on not handled new multi-buffer mailbox command */
4290 if (rc != SLI_CONFIG_HANDLED)
4291 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE;
4297 * lpfc_bsg_mbox_ext_abort - request to abort mbox command with ext buffers
4298 * @phba: Pointer to HBA context object.
4300 * This routine is for requesting to abort a pass-through mailbox command with
4301 * multiple external buffers due to error condition.
4304 lpfc_bsg_mbox_ext_abort(struct lpfc_hba *phba)
4306 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT)
4307 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS;
4309 lpfc_bsg_mbox_ext_session_reset(phba);
4314 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
4315 * @phba: Pointer to HBA context object.
4316 * @job: Pointer to the job object.
4318 * This routine extracts the next mailbox read external buffer back to
4319 * user space through BSG.
4322 lpfc_bsg_read_ebuf_get(struct lpfc_hba *phba, struct bsg_job *job)
4324 struct fc_bsg_reply *bsg_reply = job->reply;
4325 struct lpfc_sli_config_mbox *sli_cfg_mbx;
4326 struct lpfc_dmabuf *dmabuf;
4331 index = phba->mbox_ext_buf_ctx.seqNum;
4332 phba->mbox_ext_buf_ctx.seqNum++;
4334 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)
4335 phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
4337 if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) {
4338 size = bsg_bf_get(lpfc_mbox_sli_config_mse_len,
4339 &sli_cfg_mbx->un.sli_config_emb0_subsys.mse[index]);
4340 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4341 "2963 SLI_CONFIG (mse) ext-buffer rd get "
4342 "buffer[%d], size:%d\n", index, size);
4344 size = bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
4345 &sli_cfg_mbx->un.sli_config_emb1_subsys.hbd[index]);
4346 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4347 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
4348 "buffer[%d], size:%d\n", index, size);
4350 if (list_empty(&phba->mbox_ext_buf_ctx.ext_dmabuf_list))
4352 dmabuf = list_first_entry(&phba->mbox_ext_buf_ctx.ext_dmabuf_list,
4353 struct lpfc_dmabuf, list);
4354 list_del_init(&dmabuf->list);
4356 /* after dma buffer descriptor setup */
4357 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType,
4358 mbox_rd, dma_ebuf, sta_pos_addr,
4361 pbuf = (uint8_t *)dmabuf->virt;
4362 bsg_reply->reply_payload_rcv_len =
4363 sg_copy_from_buffer(job->reply_payload.sg_list,
4364 job->reply_payload.sg_cnt,
4367 lpfc_bsg_dma_page_free(phba, dmabuf);
4369 if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) {
4370 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4371 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
4372 "command session done\n");
4373 lpfc_bsg_mbox_ext_session_reset(phba);
4376 bsg_reply->result = 0;
4377 bsg_job_done(job, bsg_reply->result,
4378 bsg_reply->reply_payload_rcv_len);
4380 return SLI_CONFIG_HANDLED;
4384 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
4385 * @phba: Pointer to HBA context object.
4386 * @job: Pointer to the job object.
4387 * @dmabuf: Pointer to a DMA buffer descriptor.
4389 * This routine sets up the next mailbox read external buffer obtained
4390 * from user space through BSG.
4393 lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct bsg_job *job,
4394 struct lpfc_dmabuf *dmabuf)
4396 struct fc_bsg_reply *bsg_reply = job->reply;
4397 struct bsg_job_data *dd_data = NULL;
4398 LPFC_MBOXQ_t *pmboxq = NULL;
4400 enum nemb_type nemb_tp;
4406 index = phba->mbox_ext_buf_ctx.seqNum;
4407 phba->mbox_ext_buf_ctx.seqNum++;
4408 nemb_tp = phba->mbox_ext_buf_ctx.nembType;
4410 pbuf = (uint8_t *)dmabuf->virt;
4411 size = job->request_payload.payload_len;
4412 sg_copy_to_buffer(job->request_payload.sg_list,
4413 job->request_payload.sg_cnt,
4416 if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) {
4417 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4418 "2966 SLI_CONFIG (mse) ext-buffer wr set "
4419 "buffer[%d], size:%d\n",
4420 phba->mbox_ext_buf_ctx.seqNum, size);
4423 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4424 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
4425 "buffer[%d], size:%d\n",
4426 phba->mbox_ext_buf_ctx.seqNum, size);
4430 /* set up external buffer descriptor and add to external buffer list */
4431 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, index,
4432 phba->mbox_ext_buf_ctx.mbx_dmabuf,
4434 list_add_tail(&dmabuf->list, &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4436 /* after write dma buffer */
4437 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType,
4438 mbox_wr, dma_ebuf, sta_pos_addr,
4441 if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) {
4442 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4443 "2968 SLI_CONFIG ext-buffer wr all %d "
4444 "ebuffers received\n",
4445 phba->mbox_ext_buf_ctx.numBuf);
4447 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
4453 /* mailbox command structure for base driver */
4454 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4459 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4460 pbuf = (uint8_t *)phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
4461 pmb = &pmboxq->u.mb;
4462 memcpy(pmb, pbuf, sizeof(*pmb));
4463 pmb->mbxOwner = OWN_HOST;
4464 pmboxq->vport = phba->pport;
4466 /* callback for multi-buffer write mailbox command */
4467 pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl;
4469 /* context fields to callback function */
4470 pmboxq->ctx_u.dd_data = dd_data;
4471 dd_data->type = TYPE_MBOX;
4472 dd_data->set_job = job;
4473 dd_data->context_un.mbox.pmboxq = pmboxq;
4474 dd_data->context_un.mbox.mb = (MAILBOX_t *)pbuf;
4475 job->dd_data = dd_data;
4478 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
4480 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
4481 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
4482 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4483 "2969 Issued SLI_CONFIG ext-buffer "
4484 "mailbox command, rc:x%x\n", rc);
4485 return SLI_CONFIG_HANDLED;
4487 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4488 "2970 Failed to issue SLI_CONFIG ext-buffer "
4489 "mailbox command, rc:x%x\n", rc);
4494 /* wait for additional external buffers */
4495 bsg_reply->result = 0;
4496 bsg_job_done(job, bsg_reply->result,
4497 bsg_reply->reply_payload_rcv_len);
4498 return SLI_CONFIG_HANDLED;
4502 mempool_free(pmboxq, phba->mbox_mem_pool);
4503 lpfc_bsg_dma_page_free(phba, dmabuf);
4510 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4511 * @phba: Pointer to HBA context object.
4512 * @job: Pointer to the job object.
4513 * @dmabuf: Pointer to a DMA buffer descriptor.
4515 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4516 * command with multiple non-embedded external buffers.
4519 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba *phba, struct bsg_job *job,
4520 struct lpfc_dmabuf *dmabuf)
4524 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4525 "2971 SLI_CONFIG buffer (type:x%x)\n",
4526 phba->mbox_ext_buf_ctx.mboxType);
4528 if (phba->mbox_ext_buf_ctx.mboxType == mbox_rd) {
4529 if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_DONE) {
4530 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4531 "2972 SLI_CONFIG rd buffer state "
4533 phba->mbox_ext_buf_ctx.state);
4534 lpfc_bsg_mbox_ext_abort(phba);
4537 rc = lpfc_bsg_read_ebuf_get(phba, job);
4538 if (rc == SLI_CONFIG_HANDLED)
4539 lpfc_bsg_dma_page_free(phba, dmabuf);
4540 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4541 if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_HOST) {
4542 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4543 "2973 SLI_CONFIG wr buffer state "
4545 phba->mbox_ext_buf_ctx.state);
4546 lpfc_bsg_mbox_ext_abort(phba);
4549 rc = lpfc_bsg_write_ebuf_set(phba, job, dmabuf);
4555 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4556 * @phba: Pointer to HBA context object.
4557 * @job: Pointer to the job object.
4558 * @dmabuf: Pointer to a DMA buffer descriptor.
4560 * This routine checks and handles non-embedded multi-buffer SLI_CONFIG
4561 * (0x9B) mailbox commands and external buffers.
4564 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba *phba, struct bsg_job *job,
4565 struct lpfc_dmabuf *dmabuf)
4567 struct fc_bsg_request *bsg_request = job->request;
4568 struct dfc_mbox_req *mbox_req;
4569 int rc = SLI_CONFIG_NOT_HANDLED;
4572 (struct dfc_mbox_req *)bsg_request->rqst_data.h_vendor.vendor_cmd;
4574 /* mbox command with/without single external buffer */
4575 if (mbox_req->extMboxTag == 0 && mbox_req->extSeqNum == 0)
4578 /* mbox command and first external buffer */
4579 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE) {
4580 if (mbox_req->extSeqNum == 1) {
4581 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4582 "2974 SLI_CONFIG mailbox: tag:%d, "
4583 "seq:%d\n", mbox_req->extMboxTag,
4584 mbox_req->extSeqNum);
4585 rc = lpfc_bsg_handle_sli_cfg_mbox(phba, job, dmabuf);
4588 goto sli_cfg_ext_error;
4592 * handle additional external buffers
4595 /* check broken pipe conditions */
4596 if (mbox_req->extMboxTag != phba->mbox_ext_buf_ctx.mbxTag)
4597 goto sli_cfg_ext_error;
4598 if (mbox_req->extSeqNum > phba->mbox_ext_buf_ctx.numBuf)
4599 goto sli_cfg_ext_error;
4600 if (mbox_req->extSeqNum != phba->mbox_ext_buf_ctx.seqNum + 1)
4601 goto sli_cfg_ext_error;
4603 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4604 "2975 SLI_CONFIG mailbox external buffer: "
4605 "extSta:x%x, tag:%d, seq:%d\n",
4606 phba->mbox_ext_buf_ctx.state, mbox_req->extMboxTag,
4607 mbox_req->extSeqNum);
4608 rc = lpfc_bsg_handle_sli_cfg_ebuf(phba, job, dmabuf);
4612 /* all other cases, broken pipe */
4613 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4614 "2976 SLI_CONFIG mailbox broken pipe: "
4615 "ctxSta:x%x, ctxNumBuf:%d "
4616 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4617 phba->mbox_ext_buf_ctx.state,
4618 phba->mbox_ext_buf_ctx.numBuf,
4619 phba->mbox_ext_buf_ctx.mbxTag,
4620 phba->mbox_ext_buf_ctx.seqNum,
4621 mbox_req->extMboxTag, mbox_req->extSeqNum);
4623 lpfc_bsg_mbox_ext_session_reset(phba);
4629 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4630 * @phba: Pointer to HBA context object.
4631 * @job: Pointer to the job object.
4632 * @vport: Pointer to a vport object.
4634 * Allocate a tracking object, mailbox command memory, get a mailbox
4635 * from the mailbox pool, copy the caller mailbox command.
4637 * If offline and the sli is active we need to poll for the command (port is
4638 * being reset) and complete the job, otherwise issue the mailbox command and
4639 * let our completion handler finish the command.
4642 lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct bsg_job *job,
4643 struct lpfc_vport *vport)
4645 struct fc_bsg_request *bsg_request = job->request;
4646 struct fc_bsg_reply *bsg_reply = job->reply;
4647 LPFC_MBOXQ_t *pmboxq = NULL; /* internal mailbox queue */
4648 MAILBOX_t *pmb; /* shortcut to the pmboxq mailbox */
4649 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4650 uint8_t *pmbx = NULL;
4651 struct bsg_job_data *dd_data = NULL; /* bsg data tracking structure */
4652 struct lpfc_dmabuf *dmabuf = NULL;
4653 struct dfc_mbox_req *mbox_req;
4654 struct READ_EVENT_LOG_VAR *rdEventLog;
4655 uint32_t transmit_length, receive_length, mode;
4656 struct lpfc_mbx_sli4_config *sli4_config;
4657 struct lpfc_mbx_nembed_cmd *nembed_sge;
4658 struct ulp_bde64 *bde;
4659 uint8_t *ext = NULL;
4664 /* in case no data is transferred */
4665 bsg_reply->reply_payload_rcv_len = 0;
4667 /* sanity check to protect driver */
4668 if (job->reply_payload.payload_len > BSG_MBOX_SIZE ||
4669 job->request_payload.payload_len > BSG_MBOX_SIZE) {
4675 * Don't allow mailbox commands to be sent when blocked or when in
4676 * the middle of discovery
4678 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
4684 (struct dfc_mbox_req *)bsg_request->rqst_data.h_vendor.vendor_cmd;
4686 /* check if requested extended data lengths are valid */
4687 if ((mbox_req->inExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t)) ||
4688 (mbox_req->outExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t))) {
4693 dmabuf = lpfc_bsg_dma_page_alloc(phba);
4694 if (!dmabuf || !dmabuf->virt) {
4699 /* Get the mailbox command or external buffer from BSG */
4700 pmbx = (uint8_t *)dmabuf->virt;
4701 size = job->request_payload.payload_len;
4702 sg_copy_to_buffer(job->request_payload.sg_list,
4703 job->request_payload.sg_cnt, pmbx, size);
4705 /* Handle possible SLI_CONFIG with non-embedded payloads */
4706 if (phba->sli_rev == LPFC_SLI_REV4) {
4707 rc = lpfc_bsg_handle_sli_cfg_ext(phba, job, dmabuf);
4708 if (rc == SLI_CONFIG_HANDLED)
4712 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4715 rc = lpfc_bsg_check_cmd_access(phba, (MAILBOX_t *)pmbx, vport);
4717 goto job_done; /* must be negative */
4719 /* allocate our bsg tracking structure */
4720 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
4722 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
4723 "2727 Failed allocation of dd_data\n");
4728 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4733 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4735 pmb = &pmboxq->u.mb;
4736 memcpy(pmb, pmbx, sizeof(*pmb));
4737 pmb->mbxOwner = OWN_HOST;
4738 pmboxq->vport = vport;
4740 /* If HBA encountered an error attention, allow only DUMP
4741 * or RESTART mailbox commands until the HBA is restarted.
4743 if (phba->pport->stopped &&
4744 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4745 pmb->mbxCommand != MBX_RESTART &&
4746 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4747 pmb->mbxCommand != MBX_WRITE_WWN)
4748 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4749 "2797 mbox: Issued mailbox cmd "
4750 "0x%x while in stopped state.\n",
4753 /* extended mailbox commands will need an extended buffer */
4754 if (mbox_req->inExtWLen || mbox_req->outExtWLen) {
4756 ext = from + sizeof(MAILBOX_t);
4757 pmboxq->ext_buf = ext;
4758 pmboxq->in_ext_byte_len =
4759 mbox_req->inExtWLen * sizeof(uint32_t);
4760 pmboxq->out_ext_byte_len =
4761 mbox_req->outExtWLen * sizeof(uint32_t);
4762 pmboxq->mbox_offset_word = mbox_req->mbOffset;
4765 /* biu diag will need a kernel buffer to transfer the data
4766 * allocate our own buffer and setup the mailbox command to
4769 if (pmb->mbxCommand == MBX_RUN_BIU_DIAG64) {
4770 transmit_length = pmb->un.varWords[1];
4771 receive_length = pmb->un.varWords[4];
4772 /* transmit length cannot be greater than receive length or
4773 * mailbox extension size
4775 if ((transmit_length > receive_length) ||
4776 (transmit_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t))) {
4780 pmb->un.varBIUdiag.un.s2.xmit_bde64.addrHigh =
4781 putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t));
4782 pmb->un.varBIUdiag.un.s2.xmit_bde64.addrLow =
4783 putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t));
4785 pmb->un.varBIUdiag.un.s2.rcv_bde64.addrHigh =
4786 putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t)
4787 + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize);
4788 pmb->un.varBIUdiag.un.s2.rcv_bde64.addrLow =
4789 putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t)
4790 + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize);
4791 } else if (pmb->mbxCommand == MBX_READ_EVENT_LOG) {
4792 rdEventLog = &pmb->un.varRdEventLog;
4793 receive_length = rdEventLog->rcv_bde64.tus.f.bdeSize;
4794 mode = bf_get(lpfc_event_log, rdEventLog);
4796 /* receive length cannot be greater than mailbox
4799 if (receive_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t)) {
4804 /* mode zero uses a bde like biu diags command */
4806 pmb->un.varWords[3] = putPaddrLow(dmabuf->phys
4807 + sizeof(MAILBOX_t));
4808 pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys
4809 + sizeof(MAILBOX_t));
4811 } else if (phba->sli_rev == LPFC_SLI_REV4) {
4812 /* Let type 4 (well known data) through because the data is
4813 * returned in varwords[4-8]
4814 * otherwise check the recieve length and fetch the buffer addr
4816 if ((pmb->mbxCommand == MBX_DUMP_MEMORY) &&
4817 (pmb->un.varDmp.type != DMP_WELL_KNOWN)) {
4818 /* rebuild the command for sli4 using our own buffers
4819 * like we do for biu diags
4821 receive_length = pmb->un.varWords[2];
4822 /* receive length cannot be greater than mailbox
4825 if (receive_length == 0) {
4829 pmb->un.varWords[3] = putPaddrLow(dmabuf->phys
4830 + sizeof(MAILBOX_t));
4831 pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys
4832 + sizeof(MAILBOX_t));
4833 } else if ((pmb->mbxCommand == MBX_UPDATE_CFG) &&
4834 pmb->un.varUpdateCfg.co) {
4835 bde = (struct ulp_bde64 *)&pmb->un.varWords[4];
4837 /* bde size cannot be greater than mailbox ext size */
4838 if (bde->tus.f.bdeSize >
4839 BSG_MBOX_SIZE - sizeof(MAILBOX_t)) {
4843 bde->addrHigh = putPaddrHigh(dmabuf->phys
4844 + sizeof(MAILBOX_t));
4845 bde->addrLow = putPaddrLow(dmabuf->phys
4846 + sizeof(MAILBOX_t));
4847 } else if (pmb->mbxCommand == MBX_SLI4_CONFIG) {
4848 /* Handling non-embedded SLI_CONFIG mailbox command */
4849 sli4_config = &pmboxq->u.mqe.un.sli4_config;
4850 if (!bf_get(lpfc_mbox_hdr_emb,
4851 &sli4_config->header.cfg_mhdr)) {
4852 /* rebuild the command for sli4 using our
4853 * own buffers like we do for biu diags
4855 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
4856 &pmb->un.varWords[0];
4857 receive_length = nembed_sge->sge[0].length;
4859 /* receive length cannot be greater than
4860 * mailbox extension size
4862 if ((receive_length == 0) ||
4864 BSG_MBOX_SIZE - sizeof(MAILBOX_t))) {
4869 nembed_sge->sge[0].pa_hi =
4870 putPaddrHigh(dmabuf->phys
4871 + sizeof(MAILBOX_t));
4872 nembed_sge->sge[0].pa_lo =
4873 putPaddrLow(dmabuf->phys
4874 + sizeof(MAILBOX_t));
4879 dd_data->context_un.mbox.dmabuffers = dmabuf;
4881 /* setup wake call as IOCB callback */
4882 pmboxq->mbox_cmpl = lpfc_bsg_issue_mbox_cmpl;
4884 /* setup context field to pass wait_queue pointer to wake function */
4885 pmboxq->ctx_u.dd_data = dd_data;
4886 dd_data->type = TYPE_MBOX;
4887 dd_data->set_job = job;
4888 dd_data->context_un.mbox.pmboxq = pmboxq;
4889 dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx;
4890 dd_data->context_un.mbox.ext = ext;
4891 dd_data->context_un.mbox.mbOffset = mbox_req->mbOffset;
4892 dd_data->context_un.mbox.inExtWLen = mbox_req->inExtWLen;
4893 dd_data->context_un.mbox.outExtWLen = mbox_req->outExtWLen;
4894 job->dd_data = dd_data;
4896 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
4897 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
4898 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4899 if (rc != MBX_SUCCESS) {
4900 rc = (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
4904 /* job finished, copy the data */
4905 memcpy(pmbx, pmb, sizeof(*pmb));
4906 bsg_reply->reply_payload_rcv_len =
4907 sg_copy_from_buffer(job->reply_payload.sg_list,
4908 job->reply_payload.sg_cnt,
4910 /* not waiting mbox already done */
4915 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
4916 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY))
4917 return 1; /* job started */
4920 /* common exit for error or job completed inline */
4922 mempool_free(pmboxq, phba->mbox_mem_pool);
4923 lpfc_bsg_dma_page_free(phba, dmabuf);
4931 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
4932 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
4935 lpfc_bsg_mbox_cmd(struct bsg_job *job)
4937 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
4938 struct fc_bsg_request *bsg_request = job->request;
4939 struct fc_bsg_reply *bsg_reply = job->reply;
4940 struct lpfc_hba *phba = vport->phba;
4941 struct dfc_mbox_req *mbox_req;
4944 /* mix-and-match backward compatibility */
4945 bsg_reply->reply_payload_rcv_len = 0;
4946 if (job->request_len <
4947 sizeof(struct fc_bsg_request) + sizeof(struct dfc_mbox_req)) {
4948 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4949 "2737 Mix-and-match backward compatibility "
4950 "between MBOX_REQ old size:%d and "
4951 "new request size:%d\n",
4952 (int)(job->request_len -
4953 sizeof(struct fc_bsg_request)),
4954 (int)sizeof(struct dfc_mbox_req));
4955 mbox_req = (struct dfc_mbox_req *)
4956 bsg_request->rqst_data.h_vendor.vendor_cmd;
4957 mbox_req->extMboxTag = 0;
4958 mbox_req->extSeqNum = 0;
4961 rc = lpfc_bsg_issue_mbox(phba, job, vport);
4965 bsg_reply->result = 0;
4966 job->dd_data = NULL;
4967 bsg_job_done(job, bsg_reply->result,
4968 bsg_reply->reply_payload_rcv_len);
4970 /* job submitted, will complete later*/
4971 rc = 0; /* return zero, no error */
4973 /* some error occurred */
4974 bsg_reply->result = rc;
4975 job->dd_data = NULL;
4982 lpfc_forced_link_speed(struct bsg_job *job)
4984 struct Scsi_Host *shost = fc_bsg_to_shost(job);
4985 struct lpfc_vport *vport = shost_priv(shost);
4986 struct lpfc_hba *phba = vport->phba;
4987 struct fc_bsg_reply *bsg_reply = job->reply;
4988 struct forced_link_speed_support_reply *forced_reply;
4991 if (job->request_len <
4992 sizeof(struct fc_bsg_request) +
4993 sizeof(struct get_forced_link_speed_support)) {
4994 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
4995 "0048 Received FORCED_LINK_SPEED request "
4996 "below minimum size\n");
5001 forced_reply = (struct forced_link_speed_support_reply *)
5002 bsg_reply->reply_data.vendor_reply.vendor_rsp;
5004 if (job->reply_len < sizeof(*bsg_reply) + sizeof(*forced_reply)) {
5005 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
5006 "0049 Received FORCED_LINK_SPEED reply below "
5012 forced_reply->supported = test_bit(HBA_FORCED_LINK_SPEED,
5014 ? LPFC_FORCED_LINK_SPEED_SUPPORTED
5015 : LPFC_FORCED_LINK_SPEED_NOT_SUPPORTED;
5017 bsg_reply->result = rc;
5019 bsg_job_done(job, bsg_reply->result,
5020 bsg_reply->reply_payload_rcv_len);
5025 * lpfc_check_fwlog_support: Check FW log support on the adapter
5026 * @phba: Pointer to HBA context object.
5028 * Check if FW Logging support by the adapter
5031 lpfc_check_fwlog_support(struct lpfc_hba *phba)
5033 struct lpfc_ras_fwlog *ras_fwlog = NULL;
5035 ras_fwlog = &phba->ras_fwlog;
5037 if (!ras_fwlog->ras_hwsupport)
5039 else if (!ras_fwlog->ras_enabled)
5046 * lpfc_bsg_get_ras_config: Get RAS configuration settings
5047 * @job: fc_bsg_job to handle
5049 * Get RAS configuration values set.
5052 lpfc_bsg_get_ras_config(struct bsg_job *job)
5054 struct Scsi_Host *shost = fc_bsg_to_shost(job);
5055 struct lpfc_vport *vport = shost_priv(shost);
5056 struct fc_bsg_reply *bsg_reply = job->reply;
5057 struct lpfc_hba *phba = vport->phba;
5058 struct lpfc_bsg_get_ras_config_reply *ras_reply;
5059 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
5062 if (job->request_len <
5063 sizeof(struct fc_bsg_request) +
5064 sizeof(struct lpfc_bsg_ras_req)) {
5065 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
5066 "6192 FW_LOG request received "
5067 "below minimum size\n");
5072 /* Check FW log status */
5073 rc = lpfc_check_fwlog_support(phba);
5077 ras_reply = (struct lpfc_bsg_get_ras_config_reply *)
5078 bsg_reply->reply_data.vendor_reply.vendor_rsp;
5080 /* Current logging state */
5081 spin_lock_irq(&phba->ras_fwlog_lock);
5082 if (ras_fwlog->state == ACTIVE)
5083 ras_reply->state = LPFC_RASLOG_STATE_RUNNING;
5085 ras_reply->state = LPFC_RASLOG_STATE_STOPPED;
5086 spin_unlock_irq(&phba->ras_fwlog_lock);
5088 ras_reply->log_level = phba->ras_fwlog.fw_loglevel;
5089 ras_reply->log_buff_sz = phba->cfg_ras_fwlog_buffsize;
5092 /* make error code available to userspace */
5093 bsg_reply->result = rc;
5095 /* complete the job back to userspace */
5097 bsg_job_done(job, bsg_reply->result,
5098 bsg_reply->reply_payload_rcv_len);
5103 * lpfc_bsg_set_ras_config: Set FW logging parameters
5104 * @job: fc_bsg_job to handle
5106 * Set log-level parameters for FW-logging in host memory
5109 lpfc_bsg_set_ras_config(struct bsg_job *job)
5111 struct Scsi_Host *shost = fc_bsg_to_shost(job);
5112 struct lpfc_vport *vport = shost_priv(shost);
5113 struct lpfc_hba *phba = vport->phba;
5114 struct lpfc_bsg_set_ras_config_req *ras_req;
5115 struct fc_bsg_request *bsg_request = job->request;
5116 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
5117 struct fc_bsg_reply *bsg_reply = job->reply;
5118 uint8_t action = 0, log_level = 0;
5119 int rc = 0, action_status = 0;
5121 if (job->request_len <
5122 sizeof(struct fc_bsg_request) +
5123 sizeof(struct lpfc_bsg_set_ras_config_req)) {
5124 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
5125 "6182 Received RAS_LOG request "
5126 "below minimum size\n");
5131 /* Check FW log status */
5132 rc = lpfc_check_fwlog_support(phba);
5136 ras_req = (struct lpfc_bsg_set_ras_config_req *)
5137 bsg_request->rqst_data.h_vendor.vendor_cmd;
5138 action = ras_req->action;
5139 log_level = ras_req->log_level;
5141 if (action == LPFC_RASACTION_STOP_LOGGING) {
5142 /* Check if already disabled */
5143 spin_lock_irq(&phba->ras_fwlog_lock);
5144 if (ras_fwlog->state != ACTIVE) {
5145 spin_unlock_irq(&phba->ras_fwlog_lock);
5149 spin_unlock_irq(&phba->ras_fwlog_lock);
5151 /* Disable logging */
5152 lpfc_ras_stop_fwlog(phba);
5154 /*action = LPFC_RASACTION_START_LOGGING*/
5156 /* Even though FW-logging is active re-initialize
5157 * FW-logging with new log-level. Return status
5158 * "Logging already Running" to caller.
5160 spin_lock_irq(&phba->ras_fwlog_lock);
5161 if (ras_fwlog->state != INACTIVE)
5162 action_status = -EINPROGRESS;
5163 spin_unlock_irq(&phba->ras_fwlog_lock);
5165 /* Enable logging */
5166 rc = lpfc_sli4_ras_fwlog_init(phba, log_level,
5167 LPFC_RAS_ENABLE_LOGGING);
5173 /* Check if FW-logging is re-initialized */
5174 if (action_status == -EINPROGRESS)
5178 /* make error code available to userspace */
5179 bsg_reply->result = rc;
5181 /* complete the job back to userspace */
5183 bsg_job_done(job, bsg_reply->result,
5184 bsg_reply->reply_payload_rcv_len);
5190 * lpfc_bsg_get_ras_lwpd: Get log write position data
5191 * @job: fc_bsg_job to handle
5193 * Get Offset/Wrap count of the log message written
5197 lpfc_bsg_get_ras_lwpd(struct bsg_job *job)
5199 struct Scsi_Host *shost = fc_bsg_to_shost(job);
5200 struct lpfc_vport *vport = shost_priv(shost);
5201 struct lpfc_bsg_get_ras_lwpd *ras_reply;
5202 struct lpfc_hba *phba = vport->phba;
5203 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
5204 struct fc_bsg_reply *bsg_reply = job->reply;
5205 u32 *lwpd_ptr = NULL;
5208 rc = lpfc_check_fwlog_support(phba);
5212 if (job->request_len <
5213 sizeof(struct fc_bsg_request) +
5214 sizeof(struct lpfc_bsg_ras_req)) {
5215 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
5216 "6183 Received RAS_LOG request "
5217 "below minimum size\n");
5222 ras_reply = (struct lpfc_bsg_get_ras_lwpd *)
5223 bsg_reply->reply_data.vendor_reply.vendor_rsp;
5225 if (!ras_fwlog->lwpd.virt) {
5226 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
5227 "6193 Restart FW Logging\n");
5232 /* Get lwpd offset */
5233 lwpd_ptr = (uint32_t *)(ras_fwlog->lwpd.virt);
5234 ras_reply->offset = be32_to_cpu(*lwpd_ptr & 0xffffffff);
5236 /* Get wrap count */
5237 ras_reply->wrap_count = be32_to_cpu(*(++lwpd_ptr) & 0xffffffff);
5240 /* make error code available to userspace */
5241 bsg_reply->result = rc;
5243 /* complete the job back to userspace */
5245 bsg_job_done(job, bsg_reply->result,
5246 bsg_reply->reply_payload_rcv_len);
5252 * lpfc_bsg_get_ras_fwlog: Read FW log
5253 * @job: fc_bsg_job to handle
5255 * Copy the FW log into the passed buffer.
5258 lpfc_bsg_get_ras_fwlog(struct bsg_job *job)
5260 struct Scsi_Host *shost = fc_bsg_to_shost(job);
5261 struct lpfc_vport *vport = shost_priv(shost);
5262 struct lpfc_hba *phba = vport->phba;
5263 struct fc_bsg_request *bsg_request = job->request;
5264 struct fc_bsg_reply *bsg_reply = job->reply;
5265 struct lpfc_bsg_get_fwlog_req *ras_req;
5266 u32 rd_offset, rd_index, offset;
5267 void *src, *fwlog_buff;
5268 struct lpfc_ras_fwlog *ras_fwlog = NULL;
5269 struct lpfc_dmabuf *dmabuf, *next;
5272 ras_fwlog = &phba->ras_fwlog;
5274 rc = lpfc_check_fwlog_support(phba);
5278 /* Logging to be stopped before reading */
5279 spin_lock_irq(&phba->ras_fwlog_lock);
5280 if (ras_fwlog->state == ACTIVE) {
5281 spin_unlock_irq(&phba->ras_fwlog_lock);
5285 spin_unlock_irq(&phba->ras_fwlog_lock);
5287 if (job->request_len <
5288 sizeof(struct fc_bsg_request) +
5289 sizeof(struct lpfc_bsg_get_fwlog_req)) {
5290 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
5291 "6184 Received RAS_LOG request "
5292 "below minimum size\n");
5297 ras_req = (struct lpfc_bsg_get_fwlog_req *)
5298 bsg_request->rqst_data.h_vendor.vendor_cmd;
5299 rd_offset = ras_req->read_offset;
5301 /* Allocate memory to read fw log*/
5302 fwlog_buff = vmalloc(ras_req->read_size);
5308 rd_index = (rd_offset / LPFC_RAS_MAX_ENTRY_SIZE);
5309 offset = (rd_offset % LPFC_RAS_MAX_ENTRY_SIZE);
5311 list_for_each_entry_safe(dmabuf, next,
5312 &ras_fwlog->fwlog_buff_list, list) {
5314 if (dmabuf->buffer_tag < rd_index)
5317 src = dmabuf->virt + offset;
5318 memcpy(fwlog_buff, src, ras_req->read_size);
5322 bsg_reply->reply_payload_rcv_len =
5323 sg_copy_from_buffer(job->reply_payload.sg_list,
5324 job->reply_payload.sg_cnt,
5325 fwlog_buff, ras_req->read_size);
5330 bsg_reply->result = rc;
5332 bsg_job_done(job, bsg_reply->result,
5333 bsg_reply->reply_payload_rcv_len);
5339 lpfc_get_trunk_info(struct bsg_job *job)
5341 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
5342 struct lpfc_hba *phba = vport->phba;
5343 struct fc_bsg_reply *bsg_reply = job->reply;
5344 struct lpfc_trunk_info *event_reply;
5347 if (job->request_len <
5348 sizeof(struct fc_bsg_request) + sizeof(struct get_trunk_info_req)) {
5349 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
5350 "2744 Received GET TRUNK _INFO request below "
5356 event_reply = (struct lpfc_trunk_info *)
5357 bsg_reply->reply_data.vendor_reply.vendor_rsp;
5359 if (job->reply_len < sizeof(*bsg_reply) + sizeof(*event_reply)) {
5360 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
5361 "2728 Received GET TRUNK _INFO reply below "
5366 if (event_reply == NULL) {
5371 bsg_bf_set(lpfc_trunk_info_link_status, event_reply,
5372 (phba->link_state >= LPFC_LINK_UP) ? 1 : 0);
5374 bsg_bf_set(lpfc_trunk_info_trunk_active0, event_reply,
5375 (phba->trunk_link.link0.state == LPFC_LINK_UP) ? 1 : 0);
5377 bsg_bf_set(lpfc_trunk_info_trunk_active1, event_reply,
5378 (phba->trunk_link.link1.state == LPFC_LINK_UP) ? 1 : 0);
5380 bsg_bf_set(lpfc_trunk_info_trunk_active2, event_reply,
5381 (phba->trunk_link.link2.state == LPFC_LINK_UP) ? 1 : 0);
5383 bsg_bf_set(lpfc_trunk_info_trunk_active3, event_reply,
5384 (phba->trunk_link.link3.state == LPFC_LINK_UP) ? 1 : 0);
5386 bsg_bf_set(lpfc_trunk_info_trunk_config0, event_reply,
5387 bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba));
5389 bsg_bf_set(lpfc_trunk_info_trunk_config1, event_reply,
5390 bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba));
5392 bsg_bf_set(lpfc_trunk_info_trunk_config2, event_reply,
5393 bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba));
5395 bsg_bf_set(lpfc_trunk_info_trunk_config3, event_reply,
5396 bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba));
5398 event_reply->port_speed = phba->sli4_hba.link_state.speed / 1000;
5399 event_reply->logical_speed =
5400 phba->sli4_hba.link_state.logical_speed / 1000;
5402 bsg_reply->result = rc;
5404 bsg_job_done(job, bsg_reply->result,
5405 bsg_reply->reply_payload_rcv_len);
5411 lpfc_get_cgnbuf_info(struct bsg_job *job)
5413 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
5414 struct lpfc_hba *phba = vport->phba;
5415 struct fc_bsg_request *bsg_request = job->request;
5416 struct fc_bsg_reply *bsg_reply = job->reply;
5417 struct get_cgnbuf_info_req *cgnbuf_req;
5418 struct lpfc_cgn_info *cp;
5420 size_t size, cinfosz;
5423 if (job->request_len < sizeof(struct fc_bsg_request) +
5424 sizeof(struct get_cgnbuf_info_req)) {
5429 if (!phba->sli4_hba.pc_sli4_params.cmf) {
5434 if (!phba->cgn_i || !phba->cgn_i->virt) {
5439 cp = phba->cgn_i->virt;
5440 if (cp->cgn_info_version < LPFC_CGN_INFO_V3) {
5445 cgnbuf_req = (struct get_cgnbuf_info_req *)
5446 bsg_request->rqst_data.h_vendor.vendor_cmd;
5448 /* For reset or size == 0 */
5449 bsg_reply->reply_payload_rcv_len = 0;
5451 if (cgnbuf_req->reset == LPFC_BSG_CGN_RESET_STAT) {
5452 lpfc_init_congestion_stat(phba);
5456 /* We don't want to include the CRC at the end */
5457 cinfosz = sizeof(struct lpfc_cgn_info) - sizeof(uint32_t);
5459 size = cgnbuf_req->read_size;
5463 if (size < cinfosz) {
5464 /* Just copy back what we can */
5469 /* Allocate memory to read congestion info */
5470 cgn_buff = vmalloc(cinfosz);
5476 memcpy(cgn_buff, cp, cinfosz);
5478 bsg_reply->reply_payload_rcv_len =
5479 sg_copy_from_buffer(job->reply_payload.sg_list,
5480 job->reply_payload.sg_cnt,
5486 bsg_reply->result = rc;
5488 bsg_job_done(job, bsg_reply->result,
5489 bsg_reply->reply_payload_rcv_len);
5491 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
5492 "2724 GET CGNBUF error: %d\n", rc);
5497 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
5498 * @job: fc_bsg_job to handle
5501 lpfc_bsg_hst_vendor(struct bsg_job *job)
5503 struct fc_bsg_request *bsg_request = job->request;
5504 struct fc_bsg_reply *bsg_reply = job->reply;
5505 int command = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
5509 case LPFC_BSG_VENDOR_SET_CT_EVENT:
5510 rc = lpfc_bsg_hba_set_event(job);
5512 case LPFC_BSG_VENDOR_GET_CT_EVENT:
5513 rc = lpfc_bsg_hba_get_event(job);
5515 case LPFC_BSG_VENDOR_SEND_MGMT_RESP:
5516 rc = lpfc_bsg_send_mgmt_rsp(job);
5518 case LPFC_BSG_VENDOR_DIAG_MODE:
5519 rc = lpfc_bsg_diag_loopback_mode(job);
5521 case LPFC_BSG_VENDOR_DIAG_MODE_END:
5522 rc = lpfc_sli4_bsg_diag_mode_end(job);
5524 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK:
5525 rc = lpfc_bsg_diag_loopback_run(job);
5527 case LPFC_BSG_VENDOR_LINK_DIAG_TEST:
5528 rc = lpfc_sli4_bsg_link_diag_test(job);
5530 case LPFC_BSG_VENDOR_GET_MGMT_REV:
5531 rc = lpfc_bsg_get_dfc_rev(job);
5533 case LPFC_BSG_VENDOR_MBOX:
5534 rc = lpfc_bsg_mbox_cmd(job);
5536 case LPFC_BSG_VENDOR_FORCED_LINK_SPEED:
5537 rc = lpfc_forced_link_speed(job);
5539 case LPFC_BSG_VENDOR_RAS_GET_LWPD:
5540 rc = lpfc_bsg_get_ras_lwpd(job);
5542 case LPFC_BSG_VENDOR_RAS_GET_FWLOG:
5543 rc = lpfc_bsg_get_ras_fwlog(job);
5545 case LPFC_BSG_VENDOR_RAS_GET_CONFIG:
5546 rc = lpfc_bsg_get_ras_config(job);
5548 case LPFC_BSG_VENDOR_RAS_SET_CONFIG:
5549 rc = lpfc_bsg_set_ras_config(job);
5551 case LPFC_BSG_VENDOR_GET_TRUNK_INFO:
5552 rc = lpfc_get_trunk_info(job);
5554 case LPFC_BSG_VENDOR_GET_CGNBUF_INFO:
5555 rc = lpfc_get_cgnbuf_info(job);
5559 bsg_reply->reply_payload_rcv_len = 0;
5560 /* make error code available to userspace */
5561 bsg_reply->result = rc;
5569 * lpfc_bsg_request - handle a bsg request from the FC transport
5570 * @job: bsg_job to handle
5573 lpfc_bsg_request(struct bsg_job *job)
5575 struct fc_bsg_request *bsg_request = job->request;
5576 struct fc_bsg_reply *bsg_reply = job->reply;
5580 msgcode = bsg_request->msgcode;
5582 case FC_BSG_HST_VENDOR:
5583 rc = lpfc_bsg_hst_vendor(job);
5585 case FC_BSG_RPT_ELS:
5586 rc = lpfc_bsg_rport_els(job);
5589 rc = lpfc_bsg_send_mgmt_cmd(job);
5593 bsg_reply->reply_payload_rcv_len = 0;
5594 /* make error code available to userspace */
5595 bsg_reply->result = rc;
5603 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
5604 * @job: bsg_job that has timed out
5606 * This function just aborts the job's IOCB. The aborted IOCB will return to
5607 * the waiting function which will handle passing the error back to userspace
5610 lpfc_bsg_timeout(struct bsg_job *job)
5612 struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
5613 struct lpfc_hba *phba = vport->phba;
5614 struct lpfc_iocbq *cmdiocb;
5615 struct lpfc_sli_ring *pring;
5616 struct bsg_job_data *dd_data;
5617 unsigned long flags;
5619 LIST_HEAD(completions);
5620 struct lpfc_iocbq *check_iocb, *next_iocb;
5622 pring = lpfc_phba_elsring(phba);
5623 if (unlikely(!pring))
5626 /* if job's driver data is NULL, the command completed or is in the
5627 * the process of completing. In this case, return status to request
5628 * so the timeout is retried. This avoids double completion issues
5629 * and the request will be pulled off the timer queue when the
5630 * command's completion handler executes. Otherwise, prevent the
5631 * command's completion handler from executing the job done callback
5632 * and continue processing to abort the outstanding the command.
5635 spin_lock_irqsave(&phba->ct_ev_lock, flags);
5636 dd_data = (struct bsg_job_data *)job->dd_data;
5638 dd_data->set_job = NULL;
5639 job->dd_data = NULL;
5641 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5645 switch (dd_data->type) {
5647 /* Check to see if IOCB was issued to the port or not. If not,
5648 * remove it from the txq queue and call cancel iocbs.
5649 * Otherwise, call abort iotag
5651 cmdiocb = dd_data->context_un.iocb.cmdiocbq;
5652 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5654 spin_lock_irqsave(&phba->hbalock, flags);
5655 /* make sure the I/O abort window is still open */
5656 if (!(cmdiocb->cmd_flag & LPFC_IO_CMD_OUTSTANDING)) {
5657 spin_unlock_irqrestore(&phba->hbalock, flags);
5660 list_for_each_entry_safe(check_iocb, next_iocb, &pring->txq,
5662 if (check_iocb == cmdiocb) {
5663 list_move_tail(&check_iocb->list, &completions);
5667 if (list_empty(&completions))
5668 lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb, NULL);
5669 spin_unlock_irqrestore(&phba->hbalock, flags);
5670 if (!list_empty(&completions)) {
5671 lpfc_sli_cancel_iocbs(phba, &completions,
5672 IOSTAT_LOCAL_REJECT,
5678 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5682 /* Update the ext buf ctx state if needed */
5684 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT)
5685 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS;
5686 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5689 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5693 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
5694 * otherwise an error message will be displayed on the console
5695 * so always return success (zero)