1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009-2013 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
21 #include <linux/interrupt.h>
22 #include <linux/mempool.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
26 #include <linux/list.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
31 #include <scsi/scsi_bsg_fc.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_debugfs.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_version.h"
49 struct lpfc_bsg_event {
50 struct list_head node;
54 /* Event type and waiter identifiers */
59 /* next two flags are here for the auto-delete logic */
60 unsigned long wait_time_stamp;
63 /* seen and not seen events */
64 struct list_head events_to_get;
65 struct list_head events_to_see;
67 /* driver data associated with the job */
71 struct lpfc_bsg_iocb {
72 struct lpfc_iocbq *cmdiocbq;
73 struct lpfc_dmabuf *rmp;
74 struct lpfc_nodelist *ndlp;
77 struct lpfc_bsg_mbox {
80 struct lpfc_dmabuf *dmabuffers; /* for BIU diags */
81 uint8_t *ext; /* extended mailbox data */
82 uint32_t mbOffset; /* from app */
83 uint32_t inExtWLen; /* from app */
84 uint32_t outExtWLen; /* from app */
87 #define MENLO_DID 0x0000FC0E
89 struct lpfc_bsg_menlo {
90 struct lpfc_iocbq *cmdiocbq;
91 struct lpfc_dmabuf *rmp;
100 struct fc_bsg_job *set_job; /* job waiting for this iocb to finish */
102 struct lpfc_bsg_event *evt;
103 struct lpfc_bsg_iocb iocb;
104 struct lpfc_bsg_mbox mbox;
105 struct lpfc_bsg_menlo menlo;
110 struct list_head node;
117 #define BUF_SZ_4K 4096
118 #define SLI_CT_ELX_LOOPBACK 0x10
120 enum ELX_LOOPBACK_CMD {
121 ELX_LOOPBACK_XRI_SETUP,
125 #define ELX_LOOPBACK_HEADER_SZ \
126 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
128 struct lpfc_dmabufext {
129 struct lpfc_dmabuf dma;
135 lpfc_free_bsg_buffers(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
137 struct lpfc_dmabuf *mlast, *next_mlast;
140 list_for_each_entry_safe(mlast, next_mlast, &mlist->list,
142 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
143 list_del(&mlast->list);
146 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
152 static struct lpfc_dmabuf *
153 lpfc_alloc_bsg_buffers(struct lpfc_hba *phba, unsigned int size,
154 int outbound_buffers, struct ulp_bde64 *bpl,
157 struct lpfc_dmabuf *mlist = NULL;
158 struct lpfc_dmabuf *mp;
159 unsigned int bytes_left = size;
161 /* Verify we can support the size specified */
162 if (!size || (size > (*bpl_entries * LPFC_BPL_SIZE)))
165 /* Determine the number of dma buffers to allocate */
166 *bpl_entries = (size % LPFC_BPL_SIZE ? size/LPFC_BPL_SIZE + 1 :
169 /* Allocate dma buffer and place in BPL passed */
171 /* Allocate dma buffer */
172 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
175 lpfc_free_bsg_buffers(phba, mlist);
179 INIT_LIST_HEAD(&mp->list);
180 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
185 lpfc_free_bsg_buffers(phba, mlist);
189 /* Queue it to a linked list */
193 list_add_tail(&mp->list, &mlist->list);
195 /* Add buffer to buffer pointer list */
196 if (outbound_buffers)
197 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
199 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
200 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
201 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
202 bpl->tus.f.bdeSize = (uint16_t)
203 (bytes_left >= LPFC_BPL_SIZE ? LPFC_BPL_SIZE :
205 bytes_left -= bpl->tus.f.bdeSize;
206 bpl->tus.w = le32_to_cpu(bpl->tus.w);
213 lpfc_bsg_copy_data(struct lpfc_dmabuf *dma_buffers,
214 struct fc_bsg_buffer *bsg_buffers,
215 unsigned int bytes_to_transfer, int to_buffers)
218 struct lpfc_dmabuf *mp;
219 unsigned int transfer_bytes, bytes_copied = 0;
220 unsigned int sg_offset, dma_offset;
221 unsigned char *dma_address, *sg_address;
222 LIST_HEAD(temp_list);
223 struct sg_mapping_iter miter;
225 unsigned int sg_flags = SG_MITER_ATOMIC;
228 list_splice_init(&dma_buffers->list, &temp_list);
229 list_add(&dma_buffers->list, &temp_list);
232 sg_flags |= SG_MITER_FROM_SG;
234 sg_flags |= SG_MITER_TO_SG;
235 sg_miter_start(&miter, bsg_buffers->sg_list, bsg_buffers->sg_cnt,
237 local_irq_save(flags);
238 sg_valid = sg_miter_next(&miter);
239 list_for_each_entry(mp, &temp_list, list) {
241 while (bytes_to_transfer && sg_valid &&
242 (dma_offset < LPFC_BPL_SIZE)) {
243 dma_address = mp->virt + dma_offset;
245 /* Continue previous partial transfer of sg */
246 sg_address = miter.addr + sg_offset;
247 transfer_bytes = miter.length - sg_offset;
249 sg_address = miter.addr;
250 transfer_bytes = miter.length;
252 if (bytes_to_transfer < transfer_bytes)
253 transfer_bytes = bytes_to_transfer;
254 if (transfer_bytes > (LPFC_BPL_SIZE - dma_offset))
255 transfer_bytes = LPFC_BPL_SIZE - dma_offset;
257 memcpy(dma_address, sg_address, transfer_bytes);
259 memcpy(sg_address, dma_address, transfer_bytes);
260 dma_offset += transfer_bytes;
261 sg_offset += transfer_bytes;
262 bytes_to_transfer -= transfer_bytes;
263 bytes_copied += transfer_bytes;
264 if (sg_offset >= miter.length) {
266 sg_valid = sg_miter_next(&miter);
270 sg_miter_stop(&miter);
271 local_irq_restore(flags);
272 list_del_init(&dma_buffers->list);
273 list_splice(&temp_list, &dma_buffers->list);
278 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
279 * @phba: Pointer to HBA context object.
280 * @cmdiocbq: Pointer to command iocb.
281 * @rspiocbq: Pointer to response iocb.
283 * This function is the completion handler for iocbs issued using
284 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
285 * ring event handler function without any lock held. This function
286 * can be called from both worker thread context and interrupt
287 * context. This function also can be called from another thread which
288 * cleans up the SLI layer objects.
289 * This function copies the contents of the response iocb to the
290 * response iocb memory object provided by the caller of
291 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
292 * sleeps for the iocb completion.
295 lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
296 struct lpfc_iocbq *cmdiocbq,
297 struct lpfc_iocbq *rspiocbq)
299 struct bsg_job_data *dd_data;
300 struct fc_bsg_job *job;
302 struct lpfc_dmabuf *bmp, *cmp, *rmp;
303 struct lpfc_nodelist *ndlp;
304 struct lpfc_bsg_iocb *iocb;
306 unsigned int rsp_size;
309 dd_data = cmdiocbq->context1;
311 /* Determine if job has been aborted */
312 spin_lock_irqsave(&phba->ct_ev_lock, flags);
313 job = dd_data->set_job;
315 /* Prevent timeout handling from trying to abort job */
318 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
320 iocb = &dd_data->context_un.iocb;
323 cmp = cmdiocbq->context2;
324 bmp = cmdiocbq->context3;
325 rsp = &rspiocbq->iocb;
327 /* Copy the completed data or set the error status */
330 if (rsp->ulpStatus) {
331 if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
332 switch (rsp->un.ulpWord[4] & IOERR_PARAM_MASK) {
333 case IOERR_SEQUENCE_TIMEOUT:
336 case IOERR_INVALID_RPI:
347 rsp_size = rsp->un.genreq64.bdl.bdeSize;
348 job->reply->reply_payload_rcv_len =
349 lpfc_bsg_copy_data(rmp, &job->reply_payload,
354 lpfc_free_bsg_buffers(phba, cmp);
355 lpfc_free_bsg_buffers(phba, rmp);
356 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
358 lpfc_sli_release_iocbq(phba, cmdiocbq);
362 /* Complete the job if the job is still active */
365 job->reply->result = rc;
372 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
373 * @job: fc_bsg_job to handle
376 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
378 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
379 struct lpfc_hba *phba = vport->phba;
380 struct lpfc_rport_data *rdata = job->rport->dd_data;
381 struct lpfc_nodelist *ndlp = rdata->pnode;
382 struct ulp_bde64 *bpl = NULL;
384 struct lpfc_iocbq *cmdiocbq = NULL;
386 struct lpfc_dmabuf *bmp = NULL, *cmp = NULL, *rmp = NULL;
389 struct bsg_job_data *dd_data;
394 /* in case no data is transferred */
395 job->reply->reply_payload_rcv_len = 0;
397 /* allocate our bsg tracking structure */
398 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
400 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
401 "2733 Failed allocation of dd_data\n");
406 if (!lpfc_nlp_get(ndlp)) {
411 if (ndlp->nlp_flag & NLP_ELS_SND_MASK) {
416 cmdiocbq = lpfc_sli_get_iocbq(phba);
422 cmd = &cmdiocbq->iocb;
424 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
429 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
435 INIT_LIST_HEAD(&bmp->list);
437 bpl = (struct ulp_bde64 *) bmp->virt;
438 request_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64);
439 cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len,
440 1, bpl, &request_nseg);
445 lpfc_bsg_copy_data(cmp, &job->request_payload,
446 job->request_payload.payload_len, 1);
449 reply_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64) - request_nseg;
450 rmp = lpfc_alloc_bsg_buffers(phba, job->reply_payload.payload_len, 0,
457 cmd->un.genreq64.bdl.ulpIoTag32 = 0;
458 cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
459 cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
460 cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
461 cmd->un.genreq64.bdl.bdeSize =
462 (request_nseg + reply_nseg) * sizeof(struct ulp_bde64);
463 cmd->ulpCommand = CMD_GEN_REQUEST64_CR;
464 cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
465 cmd->un.genreq64.w5.hcsw.Dfctl = 0;
466 cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
467 cmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
468 cmd->ulpBdeCount = 1;
470 cmd->ulpClass = CLASS3;
471 cmd->ulpContext = ndlp->nlp_rpi;
472 if (phba->sli_rev == LPFC_SLI_REV4)
473 cmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
474 cmd->ulpOwner = OWN_CHIP;
475 cmdiocbq->vport = phba->pport;
476 cmdiocbq->context3 = bmp;
477 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
478 timeout = phba->fc_ratov * 2;
479 cmd->ulpTimeout = timeout;
481 cmdiocbq->iocb_cmpl = lpfc_bsg_send_mgmt_cmd_cmp;
482 cmdiocbq->context1 = dd_data;
483 cmdiocbq->context2 = cmp;
484 cmdiocbq->context3 = bmp;
485 cmdiocbq->context_un.ndlp = ndlp;
486 dd_data->type = TYPE_IOCB;
487 dd_data->set_job = job;
488 dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
489 dd_data->context_un.iocb.ndlp = ndlp;
490 dd_data->context_un.iocb.rmp = rmp;
491 job->dd_data = dd_data;
493 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
494 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
498 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
499 writel(creg_val, phba->HCregaddr);
500 readl(phba->HCregaddr); /* flush */
503 iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
504 if (iocb_stat == IOCB_SUCCESS)
505 return 0; /* done for now */
506 else if (iocb_stat == IOCB_BUSY)
511 /* iocb failed so cleanup */
514 lpfc_free_bsg_buffers(phba, rmp);
516 lpfc_free_bsg_buffers(phba, cmp);
519 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
522 lpfc_sli_release_iocbq(phba, cmdiocbq);
528 /* make error code available to userspace */
529 job->reply->result = rc;
535 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
536 * @phba: Pointer to HBA context object.
537 * @cmdiocbq: Pointer to command iocb.
538 * @rspiocbq: Pointer to response iocb.
540 * This function is the completion handler for iocbs issued using
541 * lpfc_bsg_rport_els_cmp function. This function is called by the
542 * ring event handler function without any lock held. This function
543 * can be called from both worker thread context and interrupt
544 * context. This function also can be called from other thread which
545 * cleans up the SLI layer objects.
546 * This function copies the contents of the response iocb to the
547 * response iocb memory object provided by the caller of
548 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
549 * sleeps for the iocb completion.
552 lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
553 struct lpfc_iocbq *cmdiocbq,
554 struct lpfc_iocbq *rspiocbq)
556 struct bsg_job_data *dd_data;
557 struct fc_bsg_job *job;
559 struct lpfc_nodelist *ndlp;
560 struct lpfc_dmabuf *pcmd = NULL, *prsp = NULL;
561 struct fc_bsg_ctels_reply *els_reply;
564 unsigned int rsp_size;
567 dd_data = cmdiocbq->context1;
568 ndlp = dd_data->context_un.iocb.ndlp;
569 cmdiocbq->context1 = ndlp;
571 /* Determine if job has been aborted */
572 spin_lock_irqsave(&phba->ct_ev_lock, flags);
573 job = dd_data->set_job;
575 /* Prevent timeout handling from trying to abort job */
578 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
580 rsp = &rspiocbq->iocb;
581 pcmd = (struct lpfc_dmabuf *)cmdiocbq->context2;
582 prsp = (struct lpfc_dmabuf *)pcmd->list.next;
584 /* Copy the completed job data or determine the job status if job is
589 if (rsp->ulpStatus == IOSTAT_SUCCESS) {
590 rsp_size = rsp->un.elsreq64.bdl.bdeSize;
591 job->reply->reply_payload_rcv_len =
592 sg_copy_from_buffer(job->reply_payload.sg_list,
593 job->reply_payload.sg_cnt,
596 } else if (rsp->ulpStatus == IOSTAT_LS_RJT) {
597 job->reply->reply_payload_rcv_len =
598 sizeof(struct fc_bsg_ctels_reply);
599 /* LS_RJT data returned in word 4 */
600 rjt_data = (uint8_t *)&rsp->un.ulpWord[4];
601 els_reply = &job->reply->reply_data.ctels_reply;
602 els_reply->status = FC_CTELS_STATUS_REJECT;
603 els_reply->rjt_data.action = rjt_data[3];
604 els_reply->rjt_data.reason_code = rjt_data[2];
605 els_reply->rjt_data.reason_explanation = rjt_data[1];
606 els_reply->rjt_data.vendor_unique = rjt_data[0];
613 lpfc_els_free_iocb(phba, cmdiocbq);
616 /* Complete the job if the job is still active */
619 job->reply->result = rc;
626 * lpfc_bsg_rport_els - send an ELS command from a bsg request
627 * @job: fc_bsg_job to handle
630 lpfc_bsg_rport_els(struct fc_bsg_job *job)
632 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
634 struct lpfc_rport_data *rdata = job->rport->dd_data;
635 struct lpfc_nodelist *ndlp = rdata->pnode;
639 struct lpfc_iocbq *cmdiocbq;
641 struct bsg_job_data *dd_data;
645 /* in case no data is transferred */
646 job->reply->reply_payload_rcv_len = 0;
648 /* verify the els command is not greater than the
649 * maximum ELS transfer size.
652 if (job->request_payload.payload_len > FCELSSIZE) {
657 /* allocate our bsg tracking structure */
658 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
660 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
661 "2735 Failed allocation of dd_data\n");
666 elscmd = job->request->rqst_data.r_els.els_code;
667 cmdsize = job->request_payload.payload_len;
668 rspsize = job->reply_payload.payload_len;
670 if (!lpfc_nlp_get(ndlp)) {
675 /* We will use the allocated dma buffers by prep els iocb for command
676 * and response to ensure if the job times out and the request is freed,
677 * we won't be dma into memory that is no longer allocated to for the
681 cmdiocbq = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp,
682 ndlp->nlp_DID, elscmd);
690 /* Transfer the request payload to allocated command dma buffer */
692 sg_copy_to_buffer(job->request_payload.sg_list,
693 job->request_payload.sg_cnt,
694 ((struct lpfc_dmabuf *)cmdiocbq->context2)->virt,
697 if (phba->sli_rev == LPFC_SLI_REV4)
698 cmdiocbq->iocb.ulpContext = phba->sli4_hba.rpi_ids[rpi];
700 cmdiocbq->iocb.ulpContext = rpi;
701 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
702 cmdiocbq->context1 = dd_data;
703 cmdiocbq->context_un.ndlp = ndlp;
704 cmdiocbq->iocb_cmpl = lpfc_bsg_rport_els_cmp;
705 dd_data->type = TYPE_IOCB;
706 dd_data->set_job = job;
707 dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
708 dd_data->context_un.iocb.ndlp = ndlp;
709 dd_data->context_un.iocb.rmp = NULL;
710 job->dd_data = dd_data;
712 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
713 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
717 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
718 writel(creg_val, phba->HCregaddr);
719 readl(phba->HCregaddr); /* flush */
722 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
724 if (rc == IOCB_SUCCESS)
725 return 0; /* done for now */
726 else if (rc == IOCB_BUSY)
733 cmdiocbq->context1 = ndlp;
734 lpfc_els_free_iocb(phba, cmdiocbq);
743 /* make error code available to userspace */
744 job->reply->result = rc;
750 * lpfc_bsg_event_free - frees an allocated event structure
751 * @kref: Pointer to a kref.
753 * Called from kref_put. Back cast the kref into an event structure address.
754 * Free any events to get, delete associated nodes, free any events to see,
755 * free any data then free the event itself.
758 lpfc_bsg_event_free(struct kref *kref)
760 struct lpfc_bsg_event *evt = container_of(kref, struct lpfc_bsg_event,
762 struct event_data *ed;
764 list_del(&evt->node);
766 while (!list_empty(&evt->events_to_get)) {
767 ed = list_entry(evt->events_to_get.next, typeof(*ed), node);
773 while (!list_empty(&evt->events_to_see)) {
774 ed = list_entry(evt->events_to_see.next, typeof(*ed), node);
785 * lpfc_bsg_event_ref - increments the kref for an event
786 * @evt: Pointer to an event structure.
789 lpfc_bsg_event_ref(struct lpfc_bsg_event *evt)
791 kref_get(&evt->kref);
795 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
796 * @evt: Pointer to an event structure.
799 lpfc_bsg_event_unref(struct lpfc_bsg_event *evt)
801 kref_put(&evt->kref, lpfc_bsg_event_free);
805 * lpfc_bsg_event_new - allocate and initialize a event structure
806 * @ev_mask: Mask of events.
807 * @ev_reg_id: Event reg id.
808 * @ev_req_id: Event request id.
810 static struct lpfc_bsg_event *
811 lpfc_bsg_event_new(uint32_t ev_mask, int ev_reg_id, uint32_t ev_req_id)
813 struct lpfc_bsg_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL);
818 INIT_LIST_HEAD(&evt->events_to_get);
819 INIT_LIST_HEAD(&evt->events_to_see);
820 evt->type_mask = ev_mask;
821 evt->req_id = ev_req_id;
822 evt->reg_id = ev_reg_id;
823 evt->wait_time_stamp = jiffies;
825 init_waitqueue_head(&evt->wq);
826 kref_init(&evt->kref);
831 * diag_cmd_data_free - Frees an lpfc dma buffer extension
832 * @phba: Pointer to HBA context object.
833 * @mlist: Pointer to an lpfc dma buffer extension.
836 diag_cmd_data_free(struct lpfc_hba *phba, struct lpfc_dmabufext *mlist)
838 struct lpfc_dmabufext *mlast;
839 struct pci_dev *pcidev;
840 struct list_head head, *curr, *next;
842 if ((!mlist) || (!lpfc_is_link_up(phba) &&
843 (phba->link_flag & LS_LOOPBACK_MODE))) {
847 pcidev = phba->pcidev;
848 list_add_tail(&head, &mlist->dma.list);
850 list_for_each_safe(curr, next, &head) {
851 mlast = list_entry(curr, struct lpfc_dmabufext , dma.list);
853 dma_free_coherent(&pcidev->dev,
863 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
868 * This function is called when an unsolicited CT command is received. It
869 * forwards the event to any processes registered to receive CT events.
872 lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
873 struct lpfc_iocbq *piocbq)
875 uint32_t evt_req_id = 0;
878 struct lpfc_dmabuf *dmabuf = NULL;
879 struct lpfc_bsg_event *evt;
880 struct event_data *evt_dat = NULL;
881 struct lpfc_iocbq *iocbq;
883 struct list_head head;
884 struct ulp_bde64 *bde;
887 struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
888 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
889 struct lpfc_hbq_entry *hbqe;
890 struct lpfc_sli_ct_request *ct_req;
891 struct fc_bsg_job *job = NULL;
892 struct bsg_job_data *dd_data = NULL;
896 INIT_LIST_HEAD(&head);
897 list_add_tail(&head, &piocbq->list);
899 if (piocbq->iocb.ulpBdeCount == 0 ||
900 piocbq->iocb.un.cont64[0].tus.f.bdeSize == 0)
901 goto error_ct_unsol_exit;
903 if (phba->link_state == LPFC_HBA_ERROR ||
904 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)))
905 goto error_ct_unsol_exit;
907 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
910 dma_addr = getPaddr(piocbq->iocb.un.cont64[0].addrHigh,
911 piocbq->iocb.un.cont64[0].addrLow);
912 dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, dma_addr);
915 goto error_ct_unsol_exit;
916 ct_req = (struct lpfc_sli_ct_request *)dmabuf->virt;
917 evt_req_id = ct_req->FsType;
918 cmd = ct_req->CommandResponse.bits.CmdRsp;
919 len = ct_req->CommandResponse.bits.Size;
920 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
921 lpfc_sli_ringpostbuf_put(phba, pring, dmabuf);
923 spin_lock_irqsave(&phba->ct_ev_lock, flags);
924 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
925 if (!(evt->type_mask & FC_REG_CT_EVENT) ||
926 evt->req_id != evt_req_id)
929 lpfc_bsg_event_ref(evt);
930 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
931 evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL);
932 if (evt_dat == NULL) {
933 spin_lock_irqsave(&phba->ct_ev_lock, flags);
934 lpfc_bsg_event_unref(evt);
935 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
936 "2614 Memory allocation failed for "
941 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
942 /* take accumulated byte count from the last iocbq */
943 iocbq = list_entry(head.prev, typeof(*iocbq), list);
944 evt_dat->len = iocbq->iocb.unsli3.rcvsli3.acc_len;
946 list_for_each_entry(iocbq, &head, list) {
947 for (i = 0; i < iocbq->iocb.ulpBdeCount; i++)
949 iocbq->iocb.un.cont64[i].tus.f.bdeSize;
953 evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL);
954 if (evt_dat->data == NULL) {
955 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
956 "2615 Memory allocation failed for "
957 "CT event data, size %d\n",
960 spin_lock_irqsave(&phba->ct_ev_lock, flags);
961 lpfc_bsg_event_unref(evt);
962 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
963 goto error_ct_unsol_exit;
966 list_for_each_entry(iocbq, &head, list) {
968 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
969 bdeBuf1 = iocbq->context2;
970 bdeBuf2 = iocbq->context3;
972 for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) {
973 if (phba->sli3_options &
974 LPFC_SLI3_HBQ_ENABLED) {
976 hbqe = (struct lpfc_hbq_entry *)
977 &iocbq->iocb.un.ulpWord[0];
978 size = hbqe->bde.tus.f.bdeSize;
981 hbqe = (struct lpfc_hbq_entry *)
984 size = hbqe->bde.tus.f.bdeSize;
987 if ((offset + size) > evt_dat->len)
988 size = evt_dat->len - offset;
990 size = iocbq->iocb.un.cont64[i].
992 bde = &iocbq->iocb.un.cont64[i];
993 dma_addr = getPaddr(bde->addrHigh,
995 dmabuf = lpfc_sli_ringpostbuf_get(phba,
999 lpfc_printf_log(phba, KERN_ERR,
1000 LOG_LIBDFC, "2616 No dmabuf "
1001 "found for iocbq 0x%p\n",
1003 kfree(evt_dat->data);
1005 spin_lock_irqsave(&phba->ct_ev_lock,
1007 lpfc_bsg_event_unref(evt);
1008 spin_unlock_irqrestore(
1009 &phba->ct_ev_lock, flags);
1010 goto error_ct_unsol_exit;
1012 memcpy((char *)(evt_dat->data) + offset,
1013 dmabuf->virt, size);
1015 if (evt_req_id != SLI_CT_ELX_LOOPBACK &&
1016 !(phba->sli3_options &
1017 LPFC_SLI3_HBQ_ENABLED)) {
1018 lpfc_sli_ringpostbuf_put(phba, pring,
1022 case ELX_LOOPBACK_DATA:
1025 diag_cmd_data_free(phba,
1026 (struct lpfc_dmabufext
1029 case ELX_LOOPBACK_XRI_SETUP:
1030 if ((phba->sli_rev ==
1032 (phba->sli3_options &
1033 LPFC_SLI3_HBQ_ENABLED
1035 lpfc_in_buf_free(phba,
1038 lpfc_post_buffer(phba,
1044 if (!(phba->sli3_options &
1045 LPFC_SLI3_HBQ_ENABLED))
1046 lpfc_post_buffer(phba,
1055 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1056 if (phba->sli_rev == LPFC_SLI_REV4) {
1057 evt_dat->immed_dat = phba->ctx_idx;
1058 phba->ctx_idx = (phba->ctx_idx + 1) % LPFC_CT_CTX_MAX;
1059 /* Provide warning for over-run of the ct_ctx array */
1060 if (phba->ct_ctx[evt_dat->immed_dat].valid ==
1062 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
1063 "2717 CT context array entry "
1064 "[%d] over-run: oxid:x%x, "
1065 "sid:x%x\n", phba->ctx_idx,
1067 evt_dat->immed_dat].oxid,
1069 evt_dat->immed_dat].SID);
1070 phba->ct_ctx[evt_dat->immed_dat].rxid =
1071 piocbq->iocb.ulpContext;
1072 phba->ct_ctx[evt_dat->immed_dat].oxid =
1073 piocbq->iocb.unsli3.rcvsli3.ox_id;
1074 phba->ct_ctx[evt_dat->immed_dat].SID =
1075 piocbq->iocb.un.rcvels.remoteID;
1076 phba->ct_ctx[evt_dat->immed_dat].valid = UNSOL_VALID;
1078 evt_dat->immed_dat = piocbq->iocb.ulpContext;
1080 evt_dat->type = FC_REG_CT_EVENT;
1081 list_add(&evt_dat->node, &evt->events_to_see);
1082 if (evt_req_id == SLI_CT_ELX_LOOPBACK) {
1083 wake_up_interruptible(&evt->wq);
1084 lpfc_bsg_event_unref(evt);
1088 list_move(evt->events_to_see.prev, &evt->events_to_get);
1090 dd_data = (struct bsg_job_data *)evt->dd_data;
1091 job = dd_data->set_job;
1092 dd_data->set_job = NULL;
1093 lpfc_bsg_event_unref(evt);
1095 job->reply->reply_payload_rcv_len = size;
1096 /* make error code available to userspace */
1097 job->reply->result = 0;
1098 job->dd_data = NULL;
1099 /* complete the job back to userspace */
1100 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1102 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1105 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1107 error_ct_unsol_exit:
1108 if (!list_empty(&head))
1110 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1111 (evt_req_id == SLI_CT_ELX_LOOPBACK))
1117 * lpfc_bsg_ct_unsol_abort - handler ct abort to management plane
1118 * @phba: Pointer to HBA context object.
1119 * @dmabuf: pointer to a dmabuf that describes the FC sequence
1121 * This function handles abort to the CT command toward management plane
1124 * If the pending context of a CT command to management plane present, clears
1125 * such context and returns 1 for handled; otherwise, it returns 0 indicating
1126 * no context exists.
1129 lpfc_bsg_ct_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
1131 struct fc_frame_header fc_hdr;
1132 struct fc_frame_header *fc_hdr_ptr = &fc_hdr;
1133 int ctx_idx, handled = 0;
1134 uint16_t oxid, rxid;
1137 memcpy(fc_hdr_ptr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
1138 sid = sli4_sid_from_fc_hdr(fc_hdr_ptr);
1139 oxid = be16_to_cpu(fc_hdr_ptr->fh_ox_id);
1140 rxid = be16_to_cpu(fc_hdr_ptr->fh_rx_id);
1142 for (ctx_idx = 0; ctx_idx < LPFC_CT_CTX_MAX; ctx_idx++) {
1143 if (phba->ct_ctx[ctx_idx].valid != UNSOL_VALID)
1145 if (phba->ct_ctx[ctx_idx].rxid != rxid)
1147 if (phba->ct_ctx[ctx_idx].oxid != oxid)
1149 if (phba->ct_ctx[ctx_idx].SID != sid)
1151 phba->ct_ctx[ctx_idx].valid = UNSOL_INVALID;
1158 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
1159 * @job: SET_EVENT fc_bsg_job
1162 lpfc_bsg_hba_set_event(struct fc_bsg_job *job)
1164 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
1165 struct lpfc_hba *phba = vport->phba;
1166 struct set_ct_event *event_req;
1167 struct lpfc_bsg_event *evt;
1169 struct bsg_job_data *dd_data = NULL;
1171 unsigned long flags;
1173 if (job->request_len <
1174 sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) {
1175 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1176 "2612 Received SET_CT_EVENT below minimum "
1182 event_req = (struct set_ct_event *)
1183 job->request->rqst_data.h_vendor.vendor_cmd;
1184 ev_mask = ((uint32_t)(unsigned long)event_req->type_mask &
1186 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1187 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
1188 if (evt->reg_id == event_req->ev_reg_id) {
1189 lpfc_bsg_event_ref(evt);
1190 evt->wait_time_stamp = jiffies;
1191 dd_data = (struct bsg_job_data *)evt->dd_data;
1195 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1197 if (&evt->node == &phba->ct_ev_waiters) {
1198 /* no event waiting struct yet - first call */
1199 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
1200 if (dd_data == NULL) {
1201 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1202 "2734 Failed allocation of dd_data\n");
1206 evt = lpfc_bsg_event_new(ev_mask, event_req->ev_reg_id,
1207 event_req->ev_req_id);
1209 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1210 "2617 Failed allocation of event "
1215 dd_data->type = TYPE_EVT;
1216 dd_data->set_job = NULL;
1217 dd_data->context_un.evt = evt;
1218 evt->dd_data = (void *)dd_data;
1219 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1220 list_add(&evt->node, &phba->ct_ev_waiters);
1221 lpfc_bsg_event_ref(evt);
1222 evt->wait_time_stamp = jiffies;
1223 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1226 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1228 dd_data->set_job = job; /* for unsolicited command */
1229 job->dd_data = dd_data; /* for fc transport timeout callback*/
1230 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1231 return 0; /* call job done later */
1234 if (dd_data != NULL)
1237 job->dd_data = NULL;
1242 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
1243 * @job: GET_EVENT fc_bsg_job
1246 lpfc_bsg_hba_get_event(struct fc_bsg_job *job)
1248 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
1249 struct lpfc_hba *phba = vport->phba;
1250 struct get_ct_event *event_req;
1251 struct get_ct_event_reply *event_reply;
1252 struct lpfc_bsg_event *evt;
1253 struct event_data *evt_dat = NULL;
1254 unsigned long flags;
1257 if (job->request_len <
1258 sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) {
1259 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1260 "2613 Received GET_CT_EVENT request below "
1266 event_req = (struct get_ct_event *)
1267 job->request->rqst_data.h_vendor.vendor_cmd;
1269 event_reply = (struct get_ct_event_reply *)
1270 job->reply->reply_data.vendor_reply.vendor_rsp;
1271 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1272 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
1273 if (evt->reg_id == event_req->ev_reg_id) {
1274 if (list_empty(&evt->events_to_get))
1276 lpfc_bsg_event_ref(evt);
1277 evt->wait_time_stamp = jiffies;
1278 evt_dat = list_entry(evt->events_to_get.prev,
1279 struct event_data, node);
1280 list_del(&evt_dat->node);
1284 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1286 /* The app may continue to ask for event data until it gets
1287 * an error indicating that there isn't anymore
1289 if (evt_dat == NULL) {
1290 job->reply->reply_payload_rcv_len = 0;
1295 if (evt_dat->len > job->request_payload.payload_len) {
1296 evt_dat->len = job->request_payload.payload_len;
1297 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1298 "2618 Truncated event data at %d "
1300 job->request_payload.payload_len);
1303 event_reply->type = evt_dat->type;
1304 event_reply->immed_data = evt_dat->immed_dat;
1305 if (evt_dat->len > 0)
1306 job->reply->reply_payload_rcv_len =
1307 sg_copy_from_buffer(job->request_payload.sg_list,
1308 job->request_payload.sg_cnt,
1309 evt_dat->data, evt_dat->len);
1311 job->reply->reply_payload_rcv_len = 0;
1314 kfree(evt_dat->data);
1318 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1319 lpfc_bsg_event_unref(evt);
1320 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1321 job->dd_data = NULL;
1322 job->reply->result = 0;
1327 job->dd_data = NULL;
1328 job->reply->result = rc;
1333 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1334 * @phba: Pointer to HBA context object.
1335 * @cmdiocbq: Pointer to command iocb.
1336 * @rspiocbq: Pointer to response iocb.
1338 * This function is the completion handler for iocbs issued using
1339 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1340 * ring event handler function without any lock held. This function
1341 * can be called from both worker thread context and interrupt
1342 * context. This function also can be called from other thread which
1343 * cleans up the SLI layer objects.
1344 * This function copy the contents of the response iocb to the
1345 * response iocb memory object provided by the caller of
1346 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1347 * sleeps for the iocb completion.
1350 lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba,
1351 struct lpfc_iocbq *cmdiocbq,
1352 struct lpfc_iocbq *rspiocbq)
1354 struct bsg_job_data *dd_data;
1355 struct fc_bsg_job *job;
1357 struct lpfc_dmabuf *bmp, *cmp;
1358 struct lpfc_nodelist *ndlp;
1359 unsigned long flags;
1362 dd_data = cmdiocbq->context1;
1364 /* Determine if job has been aborted */
1365 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1366 job = dd_data->set_job;
1368 /* Prevent timeout handling from trying to abort job */
1369 job->dd_data = NULL;
1371 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1373 ndlp = dd_data->context_un.iocb.ndlp;
1374 cmp = cmdiocbq->context2;
1375 bmp = cmdiocbq->context3;
1376 rsp = &rspiocbq->iocb;
1378 /* Copy the completed job data or set the error status */
1381 if (rsp->ulpStatus) {
1382 if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1383 switch (rsp->un.ulpWord[4] & IOERR_PARAM_MASK) {
1384 case IOERR_SEQUENCE_TIMEOUT:
1387 case IOERR_INVALID_RPI:
1398 job->reply->reply_payload_rcv_len = 0;
1402 lpfc_free_bsg_buffers(phba, cmp);
1403 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1405 lpfc_sli_release_iocbq(phba, cmdiocbq);
1409 /* Complete the job if the job is still active */
1412 job->reply->result = rc;
1419 * lpfc_issue_ct_rsp - issue a ct response
1420 * @phba: Pointer to HBA context object.
1421 * @job: Pointer to the job object.
1422 * @tag: tag index value into the ports context exchange array.
1423 * @bmp: Pointer to a dma buffer descriptor.
1424 * @num_entry: Number of enties in the bde.
1427 lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct fc_bsg_job *job, uint32_t tag,
1428 struct lpfc_dmabuf *cmp, struct lpfc_dmabuf *bmp,
1432 struct lpfc_iocbq *ctiocb = NULL;
1434 struct lpfc_nodelist *ndlp = NULL;
1435 struct bsg_job_data *dd_data;
1438 /* allocate our bsg tracking structure */
1439 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
1441 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1442 "2736 Failed allocation of dd_data\n");
1447 /* Allocate buffer for command iocb */
1448 ctiocb = lpfc_sli_get_iocbq(phba);
1454 icmd = &ctiocb->iocb;
1455 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
1456 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
1457 icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys);
1458 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
1459 icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
1460 icmd->un.xseq64.w5.hcsw.Fctl = (LS | LA);
1461 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
1462 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL;
1463 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
1465 /* Fill in rest of iocb */
1466 icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
1467 icmd->ulpBdeCount = 1;
1469 icmd->ulpClass = CLASS3;
1470 if (phba->sli_rev == LPFC_SLI_REV4) {
1471 /* Do not issue unsol response if oxid not marked as valid */
1472 if (phba->ct_ctx[tag].valid != UNSOL_VALID) {
1474 goto issue_ct_rsp_exit;
1476 icmd->ulpContext = phba->ct_ctx[tag].rxid;
1477 icmd->unsli3.rcvsli3.ox_id = phba->ct_ctx[tag].oxid;
1478 ndlp = lpfc_findnode_did(phba->pport, phba->ct_ctx[tag].SID);
1480 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
1481 "2721 ndlp null for oxid %x SID %x\n",
1483 phba->ct_ctx[tag].SID);
1485 goto issue_ct_rsp_exit;
1488 /* Check if the ndlp is active */
1489 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1491 goto issue_ct_rsp_exit;
1494 /* get a refernece count so the ndlp doesn't go away while
1497 if (!lpfc_nlp_get(ndlp)) {
1499 goto issue_ct_rsp_exit;
1502 icmd->un.ulpWord[3] =
1503 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
1505 /* The exchange is done, mark the entry as invalid */
1506 phba->ct_ctx[tag].valid = UNSOL_INVALID;
1508 icmd->ulpContext = (ushort) tag;
1510 icmd->ulpTimeout = phba->fc_ratov * 2;
1512 /* Xmit CT response on exchange <xid> */
1513 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1514 "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
1515 icmd->ulpContext, icmd->ulpIoTag, tag, phba->link_state);
1517 ctiocb->iocb_cmpl = NULL;
1518 ctiocb->iocb_flag |= LPFC_IO_LIBDFC;
1519 ctiocb->vport = phba->pport;
1520 ctiocb->context1 = dd_data;
1521 ctiocb->context2 = cmp;
1522 ctiocb->context3 = bmp;
1523 ctiocb->context_un.ndlp = ndlp;
1524 ctiocb->iocb_cmpl = lpfc_issue_ct_rsp_cmp;
1526 dd_data->type = TYPE_IOCB;
1527 dd_data->set_job = job;
1528 dd_data->context_un.iocb.cmdiocbq = ctiocb;
1529 dd_data->context_un.iocb.ndlp = ndlp;
1530 dd_data->context_un.iocb.rmp = NULL;
1531 job->dd_data = dd_data;
1533 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1534 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1536 goto issue_ct_rsp_exit;
1538 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1539 writel(creg_val, phba->HCregaddr);
1540 readl(phba->HCregaddr); /* flush */
1543 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
1545 if (rc == IOCB_SUCCESS)
1546 return 0; /* done for now */
1549 lpfc_sli_release_iocbq(phba, ctiocb);
1557 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1558 * @job: SEND_MGMT_RESP fc_bsg_job
1561 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job *job)
1563 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
1564 struct lpfc_hba *phba = vport->phba;
1565 struct send_mgmt_resp *mgmt_resp = (struct send_mgmt_resp *)
1566 job->request->rqst_data.h_vendor.vendor_cmd;
1567 struct ulp_bde64 *bpl;
1568 struct lpfc_dmabuf *bmp = NULL, *cmp = NULL;
1570 uint32_t tag = mgmt_resp->tag;
1571 unsigned long reqbfrcnt =
1572 (unsigned long)job->request_payload.payload_len;
1575 /* in case no data is transferred */
1576 job->reply->reply_payload_rcv_len = 0;
1578 if (!reqbfrcnt || (reqbfrcnt > (80 * BUF_SZ_4K))) {
1580 goto send_mgmt_rsp_exit;
1583 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1586 goto send_mgmt_rsp_exit;
1589 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
1592 goto send_mgmt_rsp_free_bmp;
1595 INIT_LIST_HEAD(&bmp->list);
1596 bpl = (struct ulp_bde64 *) bmp->virt;
1597 bpl_entries = (LPFC_BPL_SIZE/sizeof(struct ulp_bde64));
1598 cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len,
1599 1, bpl, &bpl_entries);
1602 goto send_mgmt_rsp_free_bmp;
1604 lpfc_bsg_copy_data(cmp, &job->request_payload,
1605 job->request_payload.payload_len, 1);
1607 rc = lpfc_issue_ct_rsp(phba, job, tag, cmp, bmp, bpl_entries);
1609 if (rc == IOCB_SUCCESS)
1610 return 0; /* done for now */
1614 lpfc_free_bsg_buffers(phba, cmp);
1616 send_mgmt_rsp_free_bmp:
1618 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1621 /* make error code available to userspace */
1622 job->reply->result = rc;
1623 job->dd_data = NULL;
1628 * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
1629 * @phba: Pointer to HBA context object.
1631 * This function is responsible for preparing driver for diag loopback
1635 lpfc_bsg_diag_mode_enter(struct lpfc_hba *phba)
1637 struct lpfc_vport **vports;
1638 struct Scsi_Host *shost;
1639 struct lpfc_sli *psli;
1640 struct lpfc_sli_ring *pring;
1647 pring = &psli->ring[LPFC_FCP_RING];
1651 if ((phba->link_state == LPFC_HBA_ERROR) ||
1652 (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
1653 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
1656 vports = lpfc_create_vport_work_array(phba);
1658 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1659 shost = lpfc_shost_from_vport(vports[i]);
1660 scsi_block_requests(shost);
1662 lpfc_destroy_vport_work_array(phba, vports);
1664 shost = lpfc_shost_from_vport(phba->pport);
1665 scsi_block_requests(shost);
1668 while (!list_empty(&pring->txcmplq)) {
1669 if (i++ > 500) /* wait up to 5 seconds */
1677 * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
1678 * @phba: Pointer to HBA context object.
1680 * This function is responsible for driver exit processing of setting up
1681 * diag loopback mode on device.
1684 lpfc_bsg_diag_mode_exit(struct lpfc_hba *phba)
1686 struct Scsi_Host *shost;
1687 struct lpfc_vport **vports;
1690 vports = lpfc_create_vport_work_array(phba);
1692 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1693 shost = lpfc_shost_from_vport(vports[i]);
1694 scsi_unblock_requests(shost);
1696 lpfc_destroy_vport_work_array(phba, vports);
1698 shost = lpfc_shost_from_vport(phba->pport);
1699 scsi_unblock_requests(shost);
1705 * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
1706 * @phba: Pointer to HBA context object.
1707 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1709 * This function is responsible for placing an sli3 port into diagnostic
1710 * loopback mode in order to perform a diagnostic loopback test.
1711 * All new scsi requests are blocked, a small delay is used to allow the
1712 * scsi requests to complete then the link is brought down. If the link is
1713 * is placed in loopback mode then scsi requests are again allowed
1714 * so the scsi mid-layer doesn't give up on the port.
1715 * All of this is done in-line.
1718 lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job)
1720 struct diag_mode_set *loopback_mode;
1721 uint32_t link_flags;
1723 LPFC_MBOXQ_t *pmboxq = NULL;
1724 int mbxstatus = MBX_SUCCESS;
1728 /* no data to return just the return code */
1729 job->reply->reply_payload_rcv_len = 0;
1731 if (job->request_len < sizeof(struct fc_bsg_request) +
1732 sizeof(struct diag_mode_set)) {
1733 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1734 "2738 Received DIAG MODE request size:%d "
1735 "below the minimum size:%d\n",
1737 (int)(sizeof(struct fc_bsg_request) +
1738 sizeof(struct diag_mode_set)));
1743 rc = lpfc_bsg_diag_mode_enter(phba);
1747 /* bring the link to diagnostic mode */
1748 loopback_mode = (struct diag_mode_set *)
1749 job->request->rqst_data.h_vendor.vendor_cmd;
1750 link_flags = loopback_mode->type;
1751 timeout = loopback_mode->timeout * 100;
1753 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1756 goto loopback_mode_exit;
1758 memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1759 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1760 pmboxq->u.mb.mbxOwner = OWN_HOST;
1762 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
1764 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) {
1765 /* wait for link down before proceeding */
1767 while (phba->link_state != LPFC_LINK_DOWN) {
1768 if (i++ > timeout) {
1770 goto loopback_mode_exit;
1775 memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1776 if (link_flags == INTERNAL_LOOP_BACK)
1777 pmboxq->u.mb.un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
1779 pmboxq->u.mb.un.varInitLnk.link_flags =
1780 FLAGS_TOPOLOGY_MODE_LOOP;
1782 pmboxq->u.mb.mbxCommand = MBX_INIT_LINK;
1783 pmboxq->u.mb.mbxOwner = OWN_HOST;
1785 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1788 if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus))
1791 spin_lock_irq(&phba->hbalock);
1792 phba->link_flag |= LS_LOOPBACK_MODE;
1793 spin_unlock_irq(&phba->hbalock);
1794 /* wait for the link attention interrupt */
1798 while (phba->link_state != LPFC_HBA_READY) {
1799 if (i++ > timeout) {
1812 lpfc_bsg_diag_mode_exit(phba);
1815 * Let SLI layer release mboxq if mbox command completed after timeout.
1817 if (pmboxq && mbxstatus != MBX_TIMEOUT)
1818 mempool_free(pmboxq, phba->mbox_mem_pool);
1821 /* make error code available to userspace */
1822 job->reply->result = rc;
1823 /* complete the job back to userspace if no error */
1830 * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
1831 * @phba: Pointer to HBA context object.
1832 * @diag: Flag for set link to diag or nomral operation state.
1834 * This function is responsible for issuing a sli4 mailbox command for setting
1835 * link to either diag state or normal operation state.
1838 lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba *phba, uint32_t diag)
1840 LPFC_MBOXQ_t *pmboxq;
1841 struct lpfc_mbx_set_link_diag_state *link_diag_state;
1842 uint32_t req_len, alloc_len;
1843 int mbxstatus = MBX_SUCCESS, rc;
1845 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1849 req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) -
1850 sizeof(struct lpfc_sli4_cfg_mhdr));
1851 alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1852 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE,
1853 req_len, LPFC_SLI4_MBX_EMBED);
1854 if (alloc_len != req_len) {
1856 goto link_diag_state_set_out;
1858 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
1859 "3128 Set link to diagnostic state:x%x (x%x/x%x)\n",
1860 diag, phba->sli4_hba.lnk_info.lnk_tp,
1861 phba->sli4_hba.lnk_info.lnk_no);
1863 link_diag_state = &pmboxq->u.mqe.un.link_diag_state;
1864 bf_set(lpfc_mbx_set_diag_state_diag_bit_valid, &link_diag_state->u.req,
1865 LPFC_DIAG_STATE_DIAG_BIT_VALID_CHANGE);
1866 bf_set(lpfc_mbx_set_diag_state_link_num, &link_diag_state->u.req,
1867 phba->sli4_hba.lnk_info.lnk_no);
1868 bf_set(lpfc_mbx_set_diag_state_link_type, &link_diag_state->u.req,
1869 phba->sli4_hba.lnk_info.lnk_tp);
1871 bf_set(lpfc_mbx_set_diag_state_diag,
1872 &link_diag_state->u.req, 1);
1874 bf_set(lpfc_mbx_set_diag_state_diag,
1875 &link_diag_state->u.req, 0);
1877 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
1879 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0))
1884 link_diag_state_set_out:
1885 if (pmboxq && (mbxstatus != MBX_TIMEOUT))
1886 mempool_free(pmboxq, phba->mbox_mem_pool);
1892 * lpfc_sli4_bsg_set_internal_loopback - set sli4 internal loopback diagnostic
1893 * @phba: Pointer to HBA context object.
1895 * This function is responsible for issuing a sli4 mailbox command for setting
1896 * up internal loopback diagnostic.
1899 lpfc_sli4_bsg_set_internal_loopback(struct lpfc_hba *phba)
1901 LPFC_MBOXQ_t *pmboxq;
1902 uint32_t req_len, alloc_len;
1903 struct lpfc_mbx_set_link_diag_loopback *link_diag_loopback;
1904 int mbxstatus = MBX_SUCCESS, rc = 0;
1906 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1909 req_len = (sizeof(struct lpfc_mbx_set_link_diag_loopback) -
1910 sizeof(struct lpfc_sli4_cfg_mhdr));
1911 alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1912 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK,
1913 req_len, LPFC_SLI4_MBX_EMBED);
1914 if (alloc_len != req_len) {
1915 mempool_free(pmboxq, phba->mbox_mem_pool);
1918 link_diag_loopback = &pmboxq->u.mqe.un.link_diag_loopback;
1919 bf_set(lpfc_mbx_set_diag_state_link_num,
1920 &link_diag_loopback->u.req, phba->sli4_hba.lnk_info.lnk_no);
1921 bf_set(lpfc_mbx_set_diag_state_link_type,
1922 &link_diag_loopback->u.req, phba->sli4_hba.lnk_info.lnk_tp);
1923 bf_set(lpfc_mbx_set_diag_lpbk_type, &link_diag_loopback->u.req,
1924 LPFC_DIAG_LOOPBACK_TYPE_INTERNAL);
1926 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
1927 if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus)) {
1928 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1929 "3127 Failed setup loopback mode mailbox "
1930 "command, rc:x%x, status:x%x\n", mbxstatus,
1931 pmboxq->u.mb.mbxStatus);
1934 if (pmboxq && (mbxstatus != MBX_TIMEOUT))
1935 mempool_free(pmboxq, phba->mbox_mem_pool);
1940 * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic
1941 * @phba: Pointer to HBA context object.
1943 * This function set up SLI4 FC port registrations for diagnostic run, which
1944 * includes all the rpis, vfi, and also vpi.
1947 lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba *phba)
1951 if (phba->pport->fc_flag & FC_VFI_REGISTERED) {
1952 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1953 "3136 Port still had vfi registered: "
1954 "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
1955 phba->pport->fc_myDID, phba->fcf.fcfi,
1956 phba->sli4_hba.vfi_ids[phba->pport->vfi],
1957 phba->vpi_ids[phba->pport->vpi]);
1960 rc = lpfc_issue_reg_vfi(phba->pport);
1965 * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
1966 * @phba: Pointer to HBA context object.
1967 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1969 * This function is responsible for placing an sli4 port into diagnostic
1970 * loopback mode in order to perform a diagnostic loopback test.
1973 lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job)
1975 struct diag_mode_set *loopback_mode;
1976 uint32_t link_flags, timeout;
1979 /* no data to return just the return code */
1980 job->reply->reply_payload_rcv_len = 0;
1982 if (job->request_len < sizeof(struct fc_bsg_request) +
1983 sizeof(struct diag_mode_set)) {
1984 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1985 "3011 Received DIAG MODE request size:%d "
1986 "below the minimum size:%d\n",
1988 (int)(sizeof(struct fc_bsg_request) +
1989 sizeof(struct diag_mode_set)));
1994 rc = lpfc_bsg_diag_mode_enter(phba);
1998 /* indicate we are in loobpack diagnostic mode */
1999 spin_lock_irq(&phba->hbalock);
2000 phba->link_flag |= LS_LOOPBACK_MODE;
2001 spin_unlock_irq(&phba->hbalock);
2003 /* reset port to start frome scratch */
2004 rc = lpfc_selective_reset(phba);
2008 /* bring the link to diagnostic mode */
2009 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2010 "3129 Bring link to diagnostic state.\n");
2011 loopback_mode = (struct diag_mode_set *)
2012 job->request->rqst_data.h_vendor.vendor_cmd;
2013 link_flags = loopback_mode->type;
2014 timeout = loopback_mode->timeout * 100;
2016 rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1);
2018 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2019 "3130 Failed to bring link to diagnostic "
2020 "state, rc:x%x\n", rc);
2021 goto loopback_mode_exit;
2024 /* wait for link down before proceeding */
2026 while (phba->link_state != LPFC_LINK_DOWN) {
2027 if (i++ > timeout) {
2029 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2030 "3131 Timeout waiting for link to "
2031 "diagnostic mode, timeout:%d ms\n",
2033 goto loopback_mode_exit;
2038 /* set up loopback mode */
2039 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2040 "3132 Set up loopback mode:x%x\n", link_flags);
2042 if (link_flags == INTERNAL_LOOP_BACK)
2043 rc = lpfc_sli4_bsg_set_internal_loopback(phba);
2044 else if (link_flags == EXTERNAL_LOOP_BACK)
2045 rc = lpfc_hba_init_link_fc_topology(phba,
2046 FLAGS_TOPOLOGY_MODE_PT_PT,
2050 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
2051 "3141 Loopback mode:x%x not supported\n",
2053 goto loopback_mode_exit;
2057 /* wait for the link attention interrupt */
2060 while (phba->link_state < LPFC_LINK_UP) {
2061 if (i++ > timeout) {
2063 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2064 "3137 Timeout waiting for link up "
2065 "in loopback mode, timeout:%d ms\n",
2073 /* port resource registration setup for loopback diagnostic */
2075 /* set up a none zero myDID for loopback test */
2076 phba->pport->fc_myDID = 1;
2077 rc = lpfc_sli4_diag_fcport_reg_setup(phba);
2079 goto loopback_mode_exit;
2082 /* wait for the port ready */
2085 while (phba->link_state != LPFC_HBA_READY) {
2086 if (i++ > timeout) {
2088 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2089 "3133 Timeout waiting for port "
2090 "loopback mode ready, timeout:%d ms\n",
2099 /* clear loopback diagnostic mode */
2101 spin_lock_irq(&phba->hbalock);
2102 phba->link_flag &= ~LS_LOOPBACK_MODE;
2103 spin_unlock_irq(&phba->hbalock);
2105 lpfc_bsg_diag_mode_exit(phba);
2108 /* make error code available to userspace */
2109 job->reply->result = rc;
2110 /* complete the job back to userspace if no error */
2117 * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
2118 * @job: LPFC_BSG_VENDOR_DIAG_MODE
2120 * This function is responsible for responding to check and dispatch bsg diag
2121 * command from the user to proper driver action routines.
2124 lpfc_bsg_diag_loopback_mode(struct fc_bsg_job *job)
2126 struct Scsi_Host *shost;
2127 struct lpfc_vport *vport;
2128 struct lpfc_hba *phba;
2134 vport = (struct lpfc_vport *)job->shost->hostdata;
2141 if (phba->sli_rev < LPFC_SLI_REV4)
2142 rc = lpfc_sli3_bsg_diag_loopback_mode(phba, job);
2143 else if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
2144 LPFC_SLI_INTF_IF_TYPE_2)
2145 rc = lpfc_sli4_bsg_diag_loopback_mode(phba, job);
2153 * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
2154 * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
2156 * This function is responsible for responding to check and dispatch bsg diag
2157 * command from the user to proper driver action routines.
2160 lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job *job)
2162 struct Scsi_Host *shost;
2163 struct lpfc_vport *vport;
2164 struct lpfc_hba *phba;
2165 struct diag_mode_set *loopback_mode_end_cmd;
2172 vport = (struct lpfc_vport *)job->shost->hostdata;
2179 if (phba->sli_rev < LPFC_SLI_REV4)
2181 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2182 LPFC_SLI_INTF_IF_TYPE_2)
2185 /* clear loopback diagnostic mode */
2186 spin_lock_irq(&phba->hbalock);
2187 phba->link_flag &= ~LS_LOOPBACK_MODE;
2188 spin_unlock_irq(&phba->hbalock);
2189 loopback_mode_end_cmd = (struct diag_mode_set *)
2190 job->request->rqst_data.h_vendor.vendor_cmd;
2191 timeout = loopback_mode_end_cmd->timeout * 100;
2193 rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0);
2195 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2196 "3139 Failed to bring link to diagnostic "
2197 "state, rc:x%x\n", rc);
2198 goto loopback_mode_end_exit;
2201 /* wait for link down before proceeding */
2203 while (phba->link_state != LPFC_LINK_DOWN) {
2204 if (i++ > timeout) {
2206 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
2207 "3140 Timeout waiting for link to "
2208 "diagnostic mode_end, timeout:%d ms\n",
2210 /* there is nothing much we can do here */
2216 /* reset port resource registrations */
2217 rc = lpfc_selective_reset(phba);
2218 phba->pport->fc_myDID = 0;
2220 loopback_mode_end_exit:
2221 /* make return code available to userspace */
2222 job->reply->result = rc;
2223 /* complete the job back to userspace if no error */
2230 * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
2231 * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
2233 * This function is to perform SLI4 diag link test request from the user
2237 lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job *job)
2239 struct Scsi_Host *shost;
2240 struct lpfc_vport *vport;
2241 struct lpfc_hba *phba;
2242 LPFC_MBOXQ_t *pmboxq;
2243 struct sli4_link_diag *link_diag_test_cmd;
2244 uint32_t req_len, alloc_len;
2246 struct lpfc_mbx_run_link_diag_test *run_link_diag_test;
2247 union lpfc_sli4_cfg_shdr *shdr;
2248 uint32_t shdr_status, shdr_add_status;
2249 struct diag_status *diag_status_reply;
2250 int mbxstatus, rc = 0;
2257 vport = (struct lpfc_vport *)job->shost->hostdata;
2268 if (phba->sli_rev < LPFC_SLI_REV4) {
2272 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2273 LPFC_SLI_INTF_IF_TYPE_2) {
2278 if (job->request_len < sizeof(struct fc_bsg_request) +
2279 sizeof(struct sli4_link_diag)) {
2280 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2281 "3013 Received LINK DIAG TEST request "
2282 " size:%d below the minimum size:%d\n",
2284 (int)(sizeof(struct fc_bsg_request) +
2285 sizeof(struct sli4_link_diag)));
2290 rc = lpfc_bsg_diag_mode_enter(phba);
2294 link_diag_test_cmd = (struct sli4_link_diag *)
2295 job->request->rqst_data.h_vendor.vendor_cmd;
2296 timeout = link_diag_test_cmd->timeout * 100;
2298 rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1);
2303 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2306 goto link_diag_test_exit;
2309 req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) -
2310 sizeof(struct lpfc_sli4_cfg_mhdr));
2311 alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2312 LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE,
2313 req_len, LPFC_SLI4_MBX_EMBED);
2314 if (alloc_len != req_len) {
2316 goto link_diag_test_exit;
2318 run_link_diag_test = &pmboxq->u.mqe.un.link_diag_test;
2319 bf_set(lpfc_mbx_run_diag_test_link_num, &run_link_diag_test->u.req,
2320 phba->sli4_hba.lnk_info.lnk_no);
2321 bf_set(lpfc_mbx_run_diag_test_link_type, &run_link_diag_test->u.req,
2322 phba->sli4_hba.lnk_info.lnk_tp);
2323 bf_set(lpfc_mbx_run_diag_test_test_id, &run_link_diag_test->u.req,
2324 link_diag_test_cmd->test_id);
2325 bf_set(lpfc_mbx_run_diag_test_loops, &run_link_diag_test->u.req,
2326 link_diag_test_cmd->loops);
2327 bf_set(lpfc_mbx_run_diag_test_test_ver, &run_link_diag_test->u.req,
2328 link_diag_test_cmd->test_version);
2329 bf_set(lpfc_mbx_run_diag_test_err_act, &run_link_diag_test->u.req,
2330 link_diag_test_cmd->error_action);
2332 mbxstatus = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2334 shdr = (union lpfc_sli4_cfg_shdr *)
2335 &pmboxq->u.mqe.un.sli4_config.header.cfg_shdr;
2336 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2337 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2338 if (shdr_status || shdr_add_status || mbxstatus) {
2339 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
2340 "3010 Run link diag test mailbox failed with "
2341 "mbx_status x%x status x%x, add_status x%x\n",
2342 mbxstatus, shdr_status, shdr_add_status);
2345 diag_status_reply = (struct diag_status *)
2346 job->reply->reply_data.vendor_reply.vendor_rsp;
2348 if (job->reply_len <
2349 sizeof(struct fc_bsg_request) + sizeof(struct diag_status)) {
2350 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2351 "3012 Received Run link diag test reply "
2352 "below minimum size (%d): reply_len:%d\n",
2353 (int)(sizeof(struct fc_bsg_request) +
2354 sizeof(struct diag_status)),
2360 diag_status_reply->mbox_status = mbxstatus;
2361 diag_status_reply->shdr_status = shdr_status;
2362 diag_status_reply->shdr_add_status = shdr_add_status;
2364 link_diag_test_exit:
2365 rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0);
2368 mempool_free(pmboxq, phba->mbox_mem_pool);
2370 lpfc_bsg_diag_mode_exit(phba);
2373 /* make error code available to userspace */
2374 job->reply->result = rc;
2375 /* complete the job back to userspace if no error */
2382 * lpfcdiag_loop_self_reg - obtains a remote port login id
2383 * @phba: Pointer to HBA context object
2384 * @rpi: Pointer to a remote port login id
2386 * This function obtains a remote port login id so the diag loopback test
2387 * can send and receive its own unsolicited CT command.
2389 static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t *rpi)
2392 struct lpfc_dmabuf *dmabuff;
2395 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2399 if (phba->sli_rev < LPFC_SLI_REV4)
2400 status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID,
2401 (uint8_t *)&phba->pport->fc_sparam,
2404 *rpi = lpfc_sli4_alloc_rpi(phba);
2405 status = lpfc_reg_rpi(phba, phba->pport->vpi,
2406 phba->pport->fc_myDID,
2407 (uint8_t *)&phba->pport->fc_sparam,
2412 mempool_free(mbox, phba->mbox_mem_pool);
2413 if (phba->sli_rev == LPFC_SLI_REV4)
2414 lpfc_sli4_free_rpi(phba, *rpi);
2418 dmabuff = (struct lpfc_dmabuf *) mbox->context1;
2419 mbox->context1 = NULL;
2420 mbox->context2 = NULL;
2421 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
2423 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
2424 lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
2426 if (status != MBX_TIMEOUT)
2427 mempool_free(mbox, phba->mbox_mem_pool);
2428 if (phba->sli_rev == LPFC_SLI_REV4)
2429 lpfc_sli4_free_rpi(phba, *rpi);
2433 if (phba->sli_rev < LPFC_SLI_REV4)
2434 *rpi = mbox->u.mb.un.varWords[0];
2436 lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
2438 mempool_free(mbox, phba->mbox_mem_pool);
2443 * lpfcdiag_loop_self_unreg - unregs from the rpi
2444 * @phba: Pointer to HBA context object
2445 * @rpi: Remote port login id
2447 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
2449 static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi)
2454 /* Allocate mboxq structure */
2455 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2459 if (phba->sli_rev < LPFC_SLI_REV4)
2460 lpfc_unreg_login(phba, 0, rpi, mbox);
2462 lpfc_unreg_login(phba, phba->pport->vpi,
2463 phba->sli4_hba.rpi_ids[rpi], mbox);
2465 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
2467 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
2468 if (status != MBX_TIMEOUT)
2469 mempool_free(mbox, phba->mbox_mem_pool);
2472 mempool_free(mbox, phba->mbox_mem_pool);
2473 if (phba->sli_rev == LPFC_SLI_REV4)
2474 lpfc_sli4_free_rpi(phba, rpi);
2479 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
2480 * @phba: Pointer to HBA context object
2481 * @rpi: Remote port login id
2482 * @txxri: Pointer to transmit exchange id
2483 * @rxxri: Pointer to response exchabge id
2485 * This function obtains the transmit and receive ids required to send
2486 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
2487 * flags are used to the unsolicted response handler is able to process
2488 * the ct command sent on the same port.
2490 static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
2491 uint16_t *txxri, uint16_t * rxxri)
2493 struct lpfc_bsg_event *evt;
2494 struct lpfc_iocbq *cmdiocbq, *rspiocbq;
2496 struct lpfc_dmabuf *dmabuf;
2497 struct ulp_bde64 *bpl = NULL;
2498 struct lpfc_sli_ct_request *ctreq = NULL;
2501 int iocb_stat = IOCB_SUCCESS;
2502 unsigned long flags;
2506 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
2507 SLI_CT_ELX_LOOPBACK);
2511 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2512 list_add(&evt->node, &phba->ct_ev_waiters);
2513 lpfc_bsg_event_ref(evt);
2514 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2516 cmdiocbq = lpfc_sli_get_iocbq(phba);
2517 rspiocbq = lpfc_sli_get_iocbq(phba);
2519 dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2521 dmabuf->virt = lpfc_mbuf_alloc(phba, 0, &dmabuf->phys);
2523 INIT_LIST_HEAD(&dmabuf->list);
2524 bpl = (struct ulp_bde64 *) dmabuf->virt;
2525 memset(bpl, 0, sizeof(*bpl));
2526 ctreq = (struct lpfc_sli_ct_request *)(bpl + 1);
2528 le32_to_cpu(putPaddrHigh(dmabuf->phys +
2531 le32_to_cpu(putPaddrLow(dmabuf->phys +
2533 bpl->tus.f.bdeFlags = 0;
2534 bpl->tus.f.bdeSize = ELX_LOOPBACK_HEADER_SZ;
2535 bpl->tus.w = le32_to_cpu(bpl->tus.w);
2539 if (cmdiocbq == NULL || rspiocbq == NULL ||
2540 dmabuf == NULL || bpl == NULL || ctreq == NULL ||
2541 dmabuf->virt == NULL) {
2543 goto err_get_xri_exit;
2546 cmd = &cmdiocbq->iocb;
2547 rsp = &rspiocbq->iocb;
2549 memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
2551 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
2552 ctreq->RevisionId.bits.InId = 0;
2553 ctreq->FsType = SLI_CT_ELX_LOOPBACK;
2554 ctreq->FsSubType = 0;
2555 ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_XRI_SETUP;
2556 ctreq->CommandResponse.bits.Size = 0;
2559 cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(dmabuf->phys);
2560 cmd->un.xseq64.bdl.addrLow = putPaddrLow(dmabuf->phys);
2561 cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
2562 cmd->un.xseq64.bdl.bdeSize = sizeof(*bpl);
2564 cmd->un.xseq64.w5.hcsw.Fctl = LA;
2565 cmd->un.xseq64.w5.hcsw.Dfctl = 0;
2566 cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
2567 cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
2569 cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR;
2570 cmd->ulpBdeCount = 1;
2572 cmd->ulpClass = CLASS3;
2573 cmd->ulpContext = rpi;
2575 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
2576 cmdiocbq->vport = phba->pport;
2577 cmdiocbq->iocb_cmpl = NULL;
2579 iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
2581 (phba->fc_ratov * 2)
2582 + LPFC_DRVR_TIMEOUT);
2585 goto err_get_xri_exit;
2587 *txxri = rsp->ulpContext;
2590 evt->wait_time_stamp = jiffies;
2591 time_left = wait_event_interruptible_timeout(
2592 evt->wq, !list_empty(&evt->events_to_see),
2593 msecs_to_jiffies(1000 *
2594 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT)));
2595 if (list_empty(&evt->events_to_see))
2596 ret_val = (time_left) ? -EINTR : -ETIMEDOUT;
2598 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2599 list_move(evt->events_to_see.prev, &evt->events_to_get);
2600 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2601 *rxxri = (list_entry(evt->events_to_get.prev,
2602 typeof(struct event_data),
2608 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2609 lpfc_bsg_event_unref(evt); /* release ref */
2610 lpfc_bsg_event_unref(evt); /* delete */
2611 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2615 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2619 if (cmdiocbq && (iocb_stat != IOCB_TIMEDOUT))
2620 lpfc_sli_release_iocbq(phba, cmdiocbq);
2622 lpfc_sli_release_iocbq(phba, rspiocbq);
2627 * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
2628 * @phba: Pointer to HBA context object
2630 * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and.
2631 * retruns the pointer to the buffer.
2633 static struct lpfc_dmabuf *
2634 lpfc_bsg_dma_page_alloc(struct lpfc_hba *phba)
2636 struct lpfc_dmabuf *dmabuf;
2637 struct pci_dev *pcidev = phba->pcidev;
2639 /* allocate dma buffer struct */
2640 dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2644 INIT_LIST_HEAD(&dmabuf->list);
2646 /* now, allocate dma buffer */
2647 dmabuf->virt = dma_alloc_coherent(&pcidev->dev, BSG_MBOX_SIZE,
2648 &(dmabuf->phys), GFP_KERNEL);
2650 if (!dmabuf->virt) {
2654 memset((uint8_t *)dmabuf->virt, 0, BSG_MBOX_SIZE);
2660 * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
2661 * @phba: Pointer to HBA context object.
2662 * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
2664 * This routine just simply frees a dma buffer and its associated buffer
2665 * descriptor referred by @dmabuf.
2668 lpfc_bsg_dma_page_free(struct lpfc_hba *phba, struct lpfc_dmabuf *dmabuf)
2670 struct pci_dev *pcidev = phba->pcidev;
2676 dma_free_coherent(&pcidev->dev, BSG_MBOX_SIZE,
2677 dmabuf->virt, dmabuf->phys);
2683 * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
2684 * @phba: Pointer to HBA context object.
2685 * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
2687 * This routine just simply frees all dma buffers and their associated buffer
2688 * descriptors referred by @dmabuf_list.
2691 lpfc_bsg_dma_page_list_free(struct lpfc_hba *phba,
2692 struct list_head *dmabuf_list)
2694 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
2696 if (list_empty(dmabuf_list))
2699 list_for_each_entry_safe(dmabuf, next_dmabuf, dmabuf_list, list) {
2700 list_del_init(&dmabuf->list);
2701 lpfc_bsg_dma_page_free(phba, dmabuf);
2707 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
2708 * @phba: Pointer to HBA context object
2709 * @bpl: Pointer to 64 bit bde structure
2710 * @size: Number of bytes to process
2711 * @nocopydata: Flag to copy user data into the allocated buffer
2713 * This function allocates page size buffers and populates an lpfc_dmabufext.
2714 * If allowed the user data pointed to with indataptr is copied into the kernel
2715 * memory. The chained list of page size buffers is returned.
2717 static struct lpfc_dmabufext *
2718 diag_cmd_data_alloc(struct lpfc_hba *phba,
2719 struct ulp_bde64 *bpl, uint32_t size,
2722 struct lpfc_dmabufext *mlist = NULL;
2723 struct lpfc_dmabufext *dmp;
2724 int cnt, offset = 0, i = 0;
2725 struct pci_dev *pcidev;
2727 pcidev = phba->pcidev;
2730 /* We get chunks of 4K */
2731 if (size > BUF_SZ_4K)
2736 /* allocate struct lpfc_dmabufext buffer header */
2737 dmp = kmalloc(sizeof(struct lpfc_dmabufext), GFP_KERNEL);
2741 INIT_LIST_HEAD(&dmp->dma.list);
2743 /* Queue it to a linked list */
2745 list_add_tail(&dmp->dma.list, &mlist->dma.list);
2749 /* allocate buffer */
2750 dmp->dma.virt = dma_alloc_coherent(&pcidev->dev,
2761 bpl->tus.f.bdeFlags = 0;
2762 pci_dma_sync_single_for_device(phba->pcidev,
2763 dmp->dma.phys, LPFC_BPL_SIZE, PCI_DMA_TODEVICE);
2766 memset((uint8_t *)dmp->dma.virt, 0, cnt);
2767 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
2770 /* build buffer ptr list for IOCB */
2771 bpl->addrLow = le32_to_cpu(putPaddrLow(dmp->dma.phys));
2772 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dmp->dma.phys));
2773 bpl->tus.f.bdeSize = (ushort) cnt;
2774 bpl->tus.w = le32_to_cpu(bpl->tus.w);
2785 diag_cmd_data_free(phba, mlist);
2790 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
2791 * @phba: Pointer to HBA context object
2792 * @rxxri: Receive exchange id
2793 * @len: Number of data bytes
2795 * This function allocates and posts a data buffer of sufficient size to receive
2796 * an unsolicted CT command.
2798 static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
2801 struct lpfc_sli *psli = &phba->sli;
2802 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2803 struct lpfc_iocbq *cmdiocbq;
2805 struct list_head head, *curr, *next;
2806 struct lpfc_dmabuf *rxbmp;
2807 struct lpfc_dmabuf *dmp;
2808 struct lpfc_dmabuf *mp[2] = {NULL, NULL};
2809 struct ulp_bde64 *rxbpl = NULL;
2811 struct lpfc_dmabufext *rxbuffer = NULL;
2816 cmdiocbq = lpfc_sli_get_iocbq(phba);
2817 rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2818 if (rxbmp != NULL) {
2819 rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys);
2821 INIT_LIST_HEAD(&rxbmp->list);
2822 rxbpl = (struct ulp_bde64 *) rxbmp->virt;
2823 rxbuffer = diag_cmd_data_alloc(phba, rxbpl, len, 0);
2827 if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) {
2829 goto err_post_rxbufs_exit;
2832 /* Queue buffers for the receive exchange */
2833 num_bde = (uint32_t)rxbuffer->flag;
2834 dmp = &rxbuffer->dma;
2836 cmd = &cmdiocbq->iocb;
2839 INIT_LIST_HEAD(&head);
2840 list_add_tail(&head, &dmp->list);
2841 list_for_each_safe(curr, next, &head) {
2842 mp[i] = list_entry(curr, struct lpfc_dmabuf, list);
2845 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2846 mp[i]->buffer_tag = lpfc_sli_get_buffer_tag(phba);
2847 cmd->un.quexri64cx.buff.bde.addrHigh =
2848 putPaddrHigh(mp[i]->phys);
2849 cmd->un.quexri64cx.buff.bde.addrLow =
2850 putPaddrLow(mp[i]->phys);
2851 cmd->un.quexri64cx.buff.bde.tus.f.bdeSize =
2852 ((struct lpfc_dmabufext *)mp[i])->size;
2853 cmd->un.quexri64cx.buff.buffer_tag = mp[i]->buffer_tag;
2854 cmd->ulpCommand = CMD_QUE_XRI64_CX;
2857 cmd->ulpBdeCount = 1;
2858 cmd->unsli3.que_xri64cx_ext_words.ebde_count = 0;
2861 cmd->un.cont64[i].addrHigh = putPaddrHigh(mp[i]->phys);
2862 cmd->un.cont64[i].addrLow = putPaddrLow(mp[i]->phys);
2863 cmd->un.cont64[i].tus.f.bdeSize =
2864 ((struct lpfc_dmabufext *)mp[i])->size;
2865 cmd->ulpBdeCount = ++i;
2867 if ((--num_bde > 0) && (i < 2))
2870 cmd->ulpCommand = CMD_QUE_XRI_BUF64_CX;
2874 cmd->ulpClass = CLASS3;
2875 cmd->ulpContext = rxxri;
2877 iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq,
2879 if (iocb_stat == IOCB_ERROR) {
2880 diag_cmd_data_free(phba,
2881 (struct lpfc_dmabufext *)mp[0]);
2883 diag_cmd_data_free(phba,
2884 (struct lpfc_dmabufext *)mp[1]);
2885 dmp = list_entry(next, struct lpfc_dmabuf, list);
2887 goto err_post_rxbufs_exit;
2890 lpfc_sli_ringpostbuf_put(phba, pring, mp[0]);
2892 lpfc_sli_ringpostbuf_put(phba, pring, mp[1]);
2896 /* The iocb was freed by lpfc_sli_issue_iocb */
2897 cmdiocbq = lpfc_sli_get_iocbq(phba);
2899 dmp = list_entry(next, struct lpfc_dmabuf, list);
2901 goto err_post_rxbufs_exit;
2904 cmd = &cmdiocbq->iocb;
2909 err_post_rxbufs_exit:
2913 lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys);
2918 lpfc_sli_release_iocbq(phba, cmdiocbq);
2923 * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
2924 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2926 * This function receives a user data buffer to be transmitted and received on
2927 * the same port, the link must be up and in loopback mode prior
2929 * 1. A kernel buffer is allocated to copy the user data into.
2930 * 2. The port registers with "itself".
2931 * 3. The transmit and receive exchange ids are obtained.
2932 * 4. The receive exchange id is posted.
2933 * 5. A new els loopback event is created.
2934 * 6. The command and response iocbs are allocated.
2935 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2937 * This function is meant to be called n times while the port is in loopback
2938 * so it is the apps responsibility to issue a reset to take the port out
2942 lpfc_bsg_diag_loopback_run(struct fc_bsg_job *job)
2944 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
2945 struct lpfc_hba *phba = vport->phba;
2946 struct diag_mode_test *diag_mode;
2947 struct lpfc_bsg_event *evt;
2948 struct event_data *evdat;
2949 struct lpfc_sli *psli = &phba->sli;
2952 size_t segment_len = 0, segment_offset = 0, current_offset = 0;
2954 struct lpfc_iocbq *cmdiocbq, *rspiocbq = NULL;
2955 IOCB_t *cmd, *rsp = NULL;
2956 struct lpfc_sli_ct_request *ctreq;
2957 struct lpfc_dmabuf *txbmp;
2958 struct ulp_bde64 *txbpl = NULL;
2959 struct lpfc_dmabufext *txbuffer = NULL;
2960 struct list_head head;
2961 struct lpfc_dmabuf *curr;
2962 uint16_t txxri = 0, rxxri;
2964 uint8_t *ptr = NULL, *rx_databuf = NULL;
2967 int iocb_stat = IOCB_SUCCESS;
2968 unsigned long flags;
2969 void *dataout = NULL;
2972 /* in case no data is returned return just the return code */
2973 job->reply->reply_payload_rcv_len = 0;
2975 if (job->request_len <
2976 sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_test)) {
2977 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2978 "2739 Received DIAG TEST request below minimum "
2981 goto loopback_test_exit;
2984 if (job->request_payload.payload_len !=
2985 job->reply_payload.payload_len) {
2987 goto loopback_test_exit;
2989 diag_mode = (struct diag_mode_test *)
2990 job->request->rqst_data.h_vendor.vendor_cmd;
2992 if ((phba->link_state == LPFC_HBA_ERROR) ||
2993 (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
2994 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
2996 goto loopback_test_exit;
2999 if (!lpfc_is_link_up(phba) || !(phba->link_flag & LS_LOOPBACK_MODE)) {
3001 goto loopback_test_exit;
3004 size = job->request_payload.payload_len;
3005 full_size = size + ELX_LOOPBACK_HEADER_SZ; /* plus the header */
3007 if ((size == 0) || (size > 80 * BUF_SZ_4K)) {
3009 goto loopback_test_exit;
3012 if (full_size >= BUF_SZ_4K) {
3014 * Allocate memory for ioctl data. If buffer is bigger than 64k,
3015 * then we allocate 64k and re-use that buffer over and over to
3016 * xfer the whole block. This is because Linux kernel has a
3017 * problem allocating more than 120k of kernel space memory. Saw
3018 * problem with GET_FCPTARGETMAPPING...
3020 if (size <= (64 * 1024))
3021 total_mem = full_size;
3023 total_mem = 64 * 1024;
3025 /* Allocate memory for ioctl data */
3026 total_mem = BUF_SZ_4K;
3028 dataout = kmalloc(total_mem, GFP_KERNEL);
3029 if (dataout == NULL) {
3031 goto loopback_test_exit;
3035 ptr += ELX_LOOPBACK_HEADER_SZ;
3036 sg_copy_to_buffer(job->request_payload.sg_list,
3037 job->request_payload.sg_cnt,
3039 rc = lpfcdiag_loop_self_reg(phba, &rpi);
3041 goto loopback_test_exit;
3043 if (phba->sli_rev < LPFC_SLI_REV4) {
3044 rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri);
3046 lpfcdiag_loop_self_unreg(phba, rpi);
3047 goto loopback_test_exit;
3050 rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size);
3052 lpfcdiag_loop_self_unreg(phba, rpi);
3053 goto loopback_test_exit;
3056 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
3057 SLI_CT_ELX_LOOPBACK);
3059 lpfcdiag_loop_self_unreg(phba, rpi);
3061 goto loopback_test_exit;
3064 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3065 list_add(&evt->node, &phba->ct_ev_waiters);
3066 lpfc_bsg_event_ref(evt);
3067 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3069 cmdiocbq = lpfc_sli_get_iocbq(phba);
3070 if (phba->sli_rev < LPFC_SLI_REV4)
3071 rspiocbq = lpfc_sli_get_iocbq(phba);
3072 txbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3075 txbmp->virt = lpfc_mbuf_alloc(phba, 0, &txbmp->phys);
3077 INIT_LIST_HEAD(&txbmp->list);
3078 txbpl = (struct ulp_bde64 *) txbmp->virt;
3079 txbuffer = diag_cmd_data_alloc(phba,
3080 txbpl, full_size, 0);
3084 if (!cmdiocbq || !txbmp || !txbpl || !txbuffer || !txbmp->virt) {
3086 goto err_loopback_test_exit;
3088 if ((phba->sli_rev < LPFC_SLI_REV4) && !rspiocbq) {
3090 goto err_loopback_test_exit;
3093 cmd = &cmdiocbq->iocb;
3094 if (phba->sli_rev < LPFC_SLI_REV4)
3095 rsp = &rspiocbq->iocb;
3097 INIT_LIST_HEAD(&head);
3098 list_add_tail(&head, &txbuffer->dma.list);
3099 list_for_each_entry(curr, &head, list) {
3100 segment_len = ((struct lpfc_dmabufext *)curr)->size;
3101 if (current_offset == 0) {
3103 memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
3104 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
3105 ctreq->RevisionId.bits.InId = 0;
3106 ctreq->FsType = SLI_CT_ELX_LOOPBACK;
3107 ctreq->FsSubType = 0;
3108 ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_DATA;
3109 ctreq->CommandResponse.bits.Size = size;
3110 segment_offset = ELX_LOOPBACK_HEADER_SZ;
3114 BUG_ON(segment_offset >= segment_len);
3115 memcpy(curr->virt + segment_offset,
3116 ptr + current_offset,
3117 segment_len - segment_offset);
3119 current_offset += segment_len - segment_offset;
3120 BUG_ON(current_offset > size);
3124 /* Build the XMIT_SEQUENCE iocb */
3125 num_bde = (uint32_t)txbuffer->flag;
3127 cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(txbmp->phys);
3128 cmd->un.xseq64.bdl.addrLow = putPaddrLow(txbmp->phys);
3129 cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
3130 cmd->un.xseq64.bdl.bdeSize = (num_bde * sizeof(struct ulp_bde64));
3132 cmd->un.xseq64.w5.hcsw.Fctl = (LS | LA);
3133 cmd->un.xseq64.w5.hcsw.Dfctl = 0;
3134 cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
3135 cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
3137 cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
3138 cmd->ulpBdeCount = 1;
3140 cmd->ulpClass = CLASS3;
3142 if (phba->sli_rev < LPFC_SLI_REV4) {
3143 cmd->ulpContext = txxri;
3145 cmd->un.xseq64.bdl.ulpIoTag32 = 0;
3146 cmd->un.ulpWord[3] = phba->sli4_hba.rpi_ids[rpi];
3147 cmdiocbq->context3 = txbmp;
3148 cmdiocbq->sli4_xritag = NO_XRI;
3149 cmd->unsli3.rcvsli3.ox_id = 0xffff;
3151 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
3152 cmdiocbq->vport = phba->pport;
3153 cmdiocbq->iocb_cmpl = NULL;
3154 iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
3155 rspiocbq, (phba->fc_ratov * 2) +
3158 if ((iocb_stat != IOCB_SUCCESS) || ((phba->sli_rev < LPFC_SLI_REV4) &&
3159 (rsp->ulpStatus != IOCB_SUCCESS))) {
3160 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3161 "3126 Failed loopback test issue iocb: "
3162 "iocb_stat:x%x\n", iocb_stat);
3164 goto err_loopback_test_exit;
3168 time_left = wait_event_interruptible_timeout(
3169 evt->wq, !list_empty(&evt->events_to_see),
3170 msecs_to_jiffies(1000 *
3171 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT)));
3173 if (list_empty(&evt->events_to_see)) {
3174 rc = (time_left) ? -EINTR : -ETIMEDOUT;
3175 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3176 "3125 Not receiving unsolicited event, "
3179 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3180 list_move(evt->events_to_see.prev, &evt->events_to_get);
3181 evdat = list_entry(evt->events_to_get.prev,
3182 typeof(*evdat), node);
3183 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3184 rx_databuf = evdat->data;
3185 if (evdat->len != full_size) {
3186 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3187 "1603 Loopback test did not receive expected "
3188 "data length. actual length 0x%x expected "
3190 evdat->len, full_size);
3192 } else if (rx_databuf == NULL)
3196 /* skip over elx loopback header */
3197 rx_databuf += ELX_LOOPBACK_HEADER_SZ;
3198 job->reply->reply_payload_rcv_len =
3199 sg_copy_from_buffer(job->reply_payload.sg_list,
3200 job->reply_payload.sg_cnt,
3202 job->reply->reply_payload_rcv_len = size;
3206 err_loopback_test_exit:
3207 lpfcdiag_loop_self_unreg(phba, rpi);
3209 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3210 lpfc_bsg_event_unref(evt); /* release ref */
3211 lpfc_bsg_event_unref(evt); /* delete */
3212 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3214 if ((cmdiocbq != NULL) && (iocb_stat != IOCB_TIMEDOUT))
3215 lpfc_sli_release_iocbq(phba, cmdiocbq);
3217 if (rspiocbq != NULL)
3218 lpfc_sli_release_iocbq(phba, rspiocbq);
3220 if (txbmp != NULL) {
3221 if (txbpl != NULL) {
3222 if (txbuffer != NULL)
3223 diag_cmd_data_free(phba, txbuffer);
3224 lpfc_mbuf_free(phba, txbmp->virt, txbmp->phys);
3231 /* make error code available to userspace */
3232 job->reply->result = rc;
3233 job->dd_data = NULL;
3234 /* complete the job back to userspace if no error */
3235 if (rc == IOCB_SUCCESS)
3241 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
3242 * @job: GET_DFC_REV fc_bsg_job
3245 lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job)
3247 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
3248 struct lpfc_hba *phba = vport->phba;
3249 struct get_mgmt_rev *event_req;
3250 struct get_mgmt_rev_reply *event_reply;
3253 if (job->request_len <
3254 sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev)) {
3255 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3256 "2740 Received GET_DFC_REV request below "
3262 event_req = (struct get_mgmt_rev *)
3263 job->request->rqst_data.h_vendor.vendor_cmd;
3265 event_reply = (struct get_mgmt_rev_reply *)
3266 job->reply->reply_data.vendor_reply.vendor_rsp;
3268 if (job->reply_len <
3269 sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev_reply)) {
3270 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3271 "2741 Received GET_DFC_REV reply below "
3277 event_reply->info.a_Major = MANAGEMENT_MAJOR_REV;
3278 event_reply->info.a_Minor = MANAGEMENT_MINOR_REV;
3280 job->reply->result = rc;
3287 * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
3288 * @phba: Pointer to HBA context object.
3289 * @pmboxq: Pointer to mailbox command.
3291 * This is completion handler function for mailbox commands issued from
3292 * lpfc_bsg_issue_mbox function. This function is called by the
3293 * mailbox event handler function with no lock held. This function
3294 * will wake up thread waiting on the wait queue pointed by context1
3298 lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3300 struct bsg_job_data *dd_data;
3301 struct fc_bsg_job *job;
3303 unsigned long flags;
3304 uint8_t *pmb, *pmb_buf;
3306 dd_data = pmboxq->context1;
3309 * The outgoing buffer is readily referred from the dma buffer,
3310 * just need to get header part from mailboxq structure.
3312 pmb = (uint8_t *)&pmboxq->u.mb;
3313 pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb;
3314 memcpy(pmb_buf, pmb, sizeof(MAILBOX_t));
3316 /* Determine if job has been aborted */
3318 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3319 job = dd_data->set_job;
3321 /* Prevent timeout handling from trying to abort job */
3322 job->dd_data = NULL;
3324 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3326 /* Copy the mailbox data to the job if it is still active */
3329 size = job->reply_payload.payload_len;
3330 job->reply->reply_payload_rcv_len =
3331 sg_copy_from_buffer(job->reply_payload.sg_list,
3332 job->reply_payload.sg_cnt,
3336 dd_data->set_job = NULL;
3337 mempool_free(dd_data->context_un.mbox.pmboxq, phba->mbox_mem_pool);
3338 lpfc_bsg_dma_page_free(phba, dd_data->context_un.mbox.dmabuffers);
3341 /* Complete the job if the job is still active */
3344 job->reply->result = 0;
3351 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
3352 * @phba: Pointer to HBA context object.
3353 * @mb: Pointer to a mailbox object.
3354 * @vport: Pointer to a vport object.
3356 * Some commands require the port to be offline, some may not be called from
3359 static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba,
3360 MAILBOX_t *mb, struct lpfc_vport *vport)
3362 /* return negative error values for bsg job */
3363 switch (mb->mbxCommand) {
3367 case MBX_CONFIG_LINK:
3368 case MBX_CONFIG_RING:
3369 case MBX_RESET_RING:
3370 case MBX_UNREG_LOGIN:
3372 case MBX_DUMP_CONTEXT:
3376 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3377 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3378 "2743 Command 0x%x is illegal in on-line "
3384 case MBX_WRITE_VPARMS:
3387 case MBX_READ_CONFIG:
3388 case MBX_READ_RCONFIG:
3389 case MBX_READ_STATUS:
3392 case MBX_READ_LNK_STAT:
3393 case MBX_DUMP_MEMORY:
3395 case MBX_UPDATE_CFG:
3396 case MBX_KILL_BOARD:
3397 case MBX_READ_TOPOLOGY:
3399 case MBX_LOAD_EXP_ROM:
3401 case MBX_DEL_LD_ENTRY:
3404 case MBX_SLI4_CONFIG:
3405 case MBX_READ_EVENT_LOG:
3406 case MBX_READ_EVENT_LOG_STATUS:
3407 case MBX_WRITE_EVENT_LOG:
3408 case MBX_PORT_CAPABILITIES:
3409 case MBX_PORT_IOV_CONTROL:
3410 case MBX_RUN_BIU_DIAG64:
3412 case MBX_SET_VARIABLE:
3413 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3414 "1226 mbox: set_variable 0x%x, 0x%x\n",
3416 mb->un.varWords[1]);
3417 if ((mb->un.varWords[0] == SETVAR_MLOMNT)
3418 && (mb->un.varWords[1] == 1)) {
3419 phba->wait_4_mlo_maint_flg = 1;
3420 } else if (mb->un.varWords[0] == SETVAR_MLORST) {
3421 spin_lock_irq(&phba->hbalock);
3422 phba->link_flag &= ~LS_LOOPBACK_MODE;
3423 spin_unlock_irq(&phba->hbalock);
3424 phba->fc_topology = LPFC_TOPOLOGY_PT_PT;
3427 case MBX_READ_SPARM64:
3429 case MBX_REG_LOGIN64:
3430 case MBX_CONFIG_PORT:
3431 case MBX_RUN_BIU_DIAG:
3433 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
3434 "2742 Unknown Command 0x%x\n",
3443 * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
3444 * @phba: Pointer to HBA context object.
3446 * This is routine clean up and reset BSG handling of multi-buffer mbox
3450 lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba *phba)
3452 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE)
3455 /* free all memory, including dma buffers */
3456 lpfc_bsg_dma_page_list_free(phba,
3457 &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3458 lpfc_bsg_dma_page_free(phba, phba->mbox_ext_buf_ctx.mbx_dmabuf);
3459 /* multi-buffer write mailbox command pass-through complete */
3460 memset((char *)&phba->mbox_ext_buf_ctx, 0,
3461 sizeof(struct lpfc_mbox_ext_buf_ctx));
3462 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3468 * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
3469 * @phba: Pointer to HBA context object.
3470 * @pmboxq: Pointer to mailbox command.
3472 * This is routine handles BSG job for mailbox commands completions with
3473 * multiple external buffers.
3475 static struct fc_bsg_job *
3476 lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3478 struct bsg_job_data *dd_data;
3479 struct fc_bsg_job *job;
3480 uint8_t *pmb, *pmb_buf;
3481 unsigned long flags;
3484 struct lpfc_dmabuf *dmabuf;
3485 struct lpfc_sli_config_mbox *sli_cfg_mbx;
3488 dd_data = pmboxq->context1;
3490 /* Determine if job has been aborted */
3491 spin_lock_irqsave(&phba->ct_ev_lock, flags);
3492 job = dd_data->set_job;
3494 /* Prevent timeout handling from trying to abort job */
3495 job->dd_data = NULL;
3497 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
3500 * The outgoing buffer is readily referred from the dma buffer,
3501 * just need to get header part from mailboxq structure.
3504 pmb = (uint8_t *)&pmboxq->u.mb;
3505 pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb;
3506 /* Copy the byte swapped response mailbox back to the user */
3507 memcpy(pmb_buf, pmb, sizeof(MAILBOX_t));
3508 /* if there is any non-embedded extended data copy that too */
3509 dmabuf = phba->mbox_ext_buf_ctx.mbx_dmabuf;
3510 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
3511 if (!bsg_bf_get(lpfc_mbox_hdr_emb,
3512 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) {
3513 pmbx = (uint8_t *)dmabuf->virt;
3514 /* byte swap the extended data following the mailbox command */
3515 lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)],
3516 &pmbx[sizeof(MAILBOX_t)],
3517 sli_cfg_mbx->un.sli_config_emb0_subsys.mse[0].buf_len);
3520 /* Complete the job if the job is still active */
3523 size = job->reply_payload.payload_len;
3524 job->reply->reply_payload_rcv_len =
3525 sg_copy_from_buffer(job->reply_payload.sg_list,
3526 job->reply_payload.sg_cnt,
3529 /* result for successful */
3530 job->reply->result = 0;
3532 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3533 "2937 SLI_CONFIG ext-buffer maibox command "
3534 "(x%x/x%x) complete bsg job done, bsize:%d\n",
3535 phba->mbox_ext_buf_ctx.nembType,
3536 phba->mbox_ext_buf_ctx.mboxType, size);
3537 lpfc_idiag_mbxacc_dump_bsg_mbox(phba,
3538 phba->mbox_ext_buf_ctx.nembType,
3539 phba->mbox_ext_buf_ctx.mboxType,
3540 dma_ebuf, sta_pos_addr,
3541 phba->mbox_ext_buf_ctx.mbx_dmabuf, 0);
3543 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3544 "2938 SLI_CONFIG ext-buffer maibox "
3545 "command (x%x/x%x) failure, rc:x%x\n",
3546 phba->mbox_ext_buf_ctx.nembType,
3547 phba->mbox_ext_buf_ctx.mboxType, rc);
3552 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_DONE;
3558 * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
3559 * @phba: Pointer to HBA context object.
3560 * @pmboxq: Pointer to mailbox command.
3562 * This is completion handler function for mailbox read commands with multiple
3566 lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3568 struct fc_bsg_job *job;
3570 job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq);
3572 /* handle the BSG job with mailbox command */
3574 pmboxq->u.mb.mbxStatus = MBXERR_ERROR;
3576 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3577 "2939 SLI_CONFIG ext-buffer rd maibox command "
3578 "complete, ctxState:x%x, mbxStatus:x%x\n",
3579 phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus);
3581 if (pmboxq->u.mb.mbxStatus || phba->mbox_ext_buf_ctx.numBuf == 1)
3582 lpfc_bsg_mbox_ext_session_reset(phba);
3584 /* free base driver mailbox structure memory */
3585 mempool_free(pmboxq, phba->mbox_mem_pool);
3587 /* if the job is still active, call job done */
3595 * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
3596 * @phba: Pointer to HBA context object.
3597 * @pmboxq: Pointer to mailbox command.
3599 * This is completion handler function for mailbox write commands with multiple
3603 lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
3605 struct fc_bsg_job *job;
3607 job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq);
3609 /* handle the BSG job with the mailbox command */
3611 pmboxq->u.mb.mbxStatus = MBXERR_ERROR;
3613 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3614 "2940 SLI_CONFIG ext-buffer wr maibox command "
3615 "complete, ctxState:x%x, mbxStatus:x%x\n",
3616 phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus);
3618 /* free all memory, including dma buffers */
3619 mempool_free(pmboxq, phba->mbox_mem_pool);
3620 lpfc_bsg_mbox_ext_session_reset(phba);
3622 /* if the job is still active, call job done */
3630 lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3631 uint32_t index, struct lpfc_dmabuf *mbx_dmabuf,
3632 struct lpfc_dmabuf *ext_dmabuf)
3634 struct lpfc_sli_config_mbox *sli_cfg_mbx;
3636 /* pointer to the start of mailbox command */
3637 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)mbx_dmabuf->virt;
3639 if (nemb_tp == nemb_mse) {
3641 sli_cfg_mbx->un.sli_config_emb0_subsys.
3643 putPaddrHigh(mbx_dmabuf->phys +
3645 sli_cfg_mbx->un.sli_config_emb0_subsys.
3647 putPaddrLow(mbx_dmabuf->phys +
3649 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3650 "2943 SLI_CONFIG(mse)[%d], "
3651 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3653 sli_cfg_mbx->un.sli_config_emb0_subsys.
3655 sli_cfg_mbx->un.sli_config_emb0_subsys.
3657 sli_cfg_mbx->un.sli_config_emb0_subsys.
3660 sli_cfg_mbx->un.sli_config_emb0_subsys.
3662 putPaddrHigh(ext_dmabuf->phys);
3663 sli_cfg_mbx->un.sli_config_emb0_subsys.
3665 putPaddrLow(ext_dmabuf->phys);
3666 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3667 "2944 SLI_CONFIG(mse)[%d], "
3668 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3670 sli_cfg_mbx->un.sli_config_emb0_subsys.
3672 sli_cfg_mbx->un.sli_config_emb0_subsys.
3674 sli_cfg_mbx->un.sli_config_emb0_subsys.
3679 sli_cfg_mbx->un.sli_config_emb1_subsys.
3681 putPaddrHigh(mbx_dmabuf->phys +
3683 sli_cfg_mbx->un.sli_config_emb1_subsys.
3685 putPaddrLow(mbx_dmabuf->phys +
3687 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3688 "3007 SLI_CONFIG(hbd)[%d], "
3689 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3691 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
3693 sli_config_emb1_subsys.hbd[index]),
3694 sli_cfg_mbx->un.sli_config_emb1_subsys.
3696 sli_cfg_mbx->un.sli_config_emb1_subsys.
3700 sli_cfg_mbx->un.sli_config_emb1_subsys.
3702 putPaddrHigh(ext_dmabuf->phys);
3703 sli_cfg_mbx->un.sli_config_emb1_subsys.
3705 putPaddrLow(ext_dmabuf->phys);
3706 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3707 "3008 SLI_CONFIG(hbd)[%d], "
3708 "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
3710 bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
3712 sli_config_emb1_subsys.hbd[index]),
3713 sli_cfg_mbx->un.sli_config_emb1_subsys.
3715 sli_cfg_mbx->un.sli_config_emb1_subsys.
3723 * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
3724 * @phba: Pointer to HBA context object.
3725 * @mb: Pointer to a BSG mailbox object.
3726 * @nemb_tp: Enumerate of non-embedded mailbox command type.
3727 * @dmabuff: Pointer to a DMA buffer descriptor.
3729 * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
3730 * non-embedded external bufffers.
3733 lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job,
3734 enum nemb_type nemb_tp,
3735 struct lpfc_dmabuf *dmabuf)
3737 struct lpfc_sli_config_mbox *sli_cfg_mbx;
3738 struct dfc_mbox_req *mbox_req;
3739 struct lpfc_dmabuf *curr_dmabuf, *next_dmabuf;
3740 uint32_t ext_buf_cnt, ext_buf_index;
3741 struct lpfc_dmabuf *ext_dmabuf = NULL;
3742 struct bsg_job_data *dd_data = NULL;
3743 LPFC_MBOXQ_t *pmboxq = NULL;
3749 (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
3751 /* pointer to the start of mailbox command */
3752 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
3754 if (nemb_tp == nemb_mse) {
3755 ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt,
3756 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr);
3757 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) {
3758 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3759 "2945 Handled SLI_CONFIG(mse) rd, "
3760 "ext_buf_cnt(%d) out of range(%d)\n",
3762 LPFC_MBX_SLI_CONFIG_MAX_MSE);
3766 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3767 "2941 Handled SLI_CONFIG(mse) rd, "
3768 "ext_buf_cnt:%d\n", ext_buf_cnt);
3770 /* sanity check on interface type for support */
3771 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3772 LPFC_SLI_INTF_IF_TYPE_2) {
3776 /* nemb_tp == nemb_hbd */
3777 ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count;
3778 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) {
3779 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3780 "2946 Handled SLI_CONFIG(hbd) rd, "
3781 "ext_buf_cnt(%d) out of range(%d)\n",
3783 LPFC_MBX_SLI_CONFIG_MAX_HBD);
3787 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3788 "2942 Handled SLI_CONFIG(hbd) rd, "
3789 "ext_buf_cnt:%d\n", ext_buf_cnt);
3792 /* before dma descriptor setup */
3793 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox,
3794 sta_pre_addr, dmabuf, ext_buf_cnt);
3796 /* reject non-embedded mailbox command with none external buffer */
3797 if (ext_buf_cnt == 0) {
3800 } else if (ext_buf_cnt > 1) {
3801 /* additional external read buffers */
3802 for (i = 1; i < ext_buf_cnt; i++) {
3803 ext_dmabuf = lpfc_bsg_dma_page_alloc(phba);
3808 list_add_tail(&ext_dmabuf->list,
3809 &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3813 /* bsg tracking structure */
3814 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
3820 /* mailbox command structure for base driver */
3821 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3826 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3828 /* for the first external buffer */
3829 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf);
3831 /* for the rest of external buffer descriptors if any */
3832 if (ext_buf_cnt > 1) {
3834 list_for_each_entry_safe(curr_dmabuf, next_dmabuf,
3835 &phba->mbox_ext_buf_ctx.ext_dmabuf_list, list) {
3836 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp,
3837 ext_buf_index, dmabuf,
3843 /* after dma descriptor setup */
3844 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox,
3845 sta_pos_addr, dmabuf, ext_buf_cnt);
3847 /* construct base driver mbox command */
3848 pmb = &pmboxq->u.mb;
3849 pmbx = (uint8_t *)dmabuf->virt;
3850 memcpy(pmb, pmbx, sizeof(*pmb));
3851 pmb->mbxOwner = OWN_HOST;
3852 pmboxq->vport = phba->pport;
3854 /* multi-buffer handling context */
3855 phba->mbox_ext_buf_ctx.nembType = nemb_tp;
3856 phba->mbox_ext_buf_ctx.mboxType = mbox_rd;
3857 phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt;
3858 phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag;
3859 phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum;
3860 phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf;
3862 /* callback for multi-buffer read mailbox command */
3863 pmboxq->mbox_cmpl = lpfc_bsg_issue_read_mbox_ext_cmpl;
3865 /* context fields to callback function */
3866 pmboxq->context1 = dd_data;
3867 dd_data->type = TYPE_MBOX;
3868 dd_data->set_job = job;
3869 dd_data->context_un.mbox.pmboxq = pmboxq;
3870 dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx;
3871 job->dd_data = dd_data;
3874 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
3877 * Non-embedded mailbox subcommand data gets byte swapped here because
3878 * the lower level driver code only does the first 64 mailbox words.
3880 if ((!bsg_bf_get(lpfc_mbox_hdr_emb,
3881 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) &&
3882 (nemb_tp == nemb_mse))
3883 lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)],
3884 &pmbx[sizeof(MAILBOX_t)],
3885 sli_cfg_mbx->un.sli_config_emb0_subsys.
3888 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3889 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
3890 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3891 "2947 Issued SLI_CONFIG ext-buffer "
3892 "maibox command, rc:x%x\n", rc);
3893 return SLI_CONFIG_HANDLED;
3895 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3896 "2948 Failed to issue SLI_CONFIG ext-buffer "
3897 "maibox command, rc:x%x\n", rc);
3902 mempool_free(pmboxq, phba->mbox_mem_pool);
3903 lpfc_bsg_dma_page_list_free(phba,
3904 &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
3906 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE;
3911 * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
3912 * @phba: Pointer to HBA context object.
3913 * @mb: Pointer to a BSG mailbox object.
3914 * @dmabuff: Pointer to a DMA buffer descriptor.
3916 * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
3917 * non-embedded external bufffers.
3920 lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job,
3921 enum nemb_type nemb_tp,
3922 struct lpfc_dmabuf *dmabuf)
3924 struct dfc_mbox_req *mbox_req;
3925 struct lpfc_sli_config_mbox *sli_cfg_mbx;
3926 uint32_t ext_buf_cnt;
3927 struct bsg_job_data *dd_data = NULL;
3928 LPFC_MBOXQ_t *pmboxq = NULL;
3931 int rc = SLI_CONFIG_NOT_HANDLED, i;
3934 (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
3936 /* pointer to the start of mailbox command */
3937 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
3939 if (nemb_tp == nemb_mse) {
3940 ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt,
3941 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr);
3942 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) {
3943 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3944 "2953 Failed SLI_CONFIG(mse) wr, "
3945 "ext_buf_cnt(%d) out of range(%d)\n",
3947 LPFC_MBX_SLI_CONFIG_MAX_MSE);
3950 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3951 "2949 Handled SLI_CONFIG(mse) wr, "
3952 "ext_buf_cnt:%d\n", ext_buf_cnt);
3954 /* sanity check on interface type for support */
3955 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3956 LPFC_SLI_INTF_IF_TYPE_2)
3958 /* nemb_tp == nemb_hbd */
3959 ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count;
3960 if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) {
3961 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
3962 "2954 Failed SLI_CONFIG(hbd) wr, "
3963 "ext_buf_cnt(%d) out of range(%d)\n",
3965 LPFC_MBX_SLI_CONFIG_MAX_HBD);
3968 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3969 "2950 Handled SLI_CONFIG(hbd) wr, "
3970 "ext_buf_cnt:%d\n", ext_buf_cnt);
3973 /* before dma buffer descriptor setup */
3974 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox,
3975 sta_pre_addr, dmabuf, ext_buf_cnt);
3977 if (ext_buf_cnt == 0)
3980 /* for the first external buffer */
3981 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf);
3983 /* after dma descriptor setup */
3984 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox,
3985 sta_pos_addr, dmabuf, ext_buf_cnt);
3987 /* log for looking forward */
3988 for (i = 1; i < ext_buf_cnt; i++) {
3989 if (nemb_tp == nemb_mse)
3990 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3991 "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
3992 i, sli_cfg_mbx->un.sli_config_emb0_subsys.
3995 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
3996 "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
3997 i, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
3998 &sli_cfg_mbx->un.sli_config_emb1_subsys.
4002 /* multi-buffer handling context */
4003 phba->mbox_ext_buf_ctx.nembType = nemb_tp;
4004 phba->mbox_ext_buf_ctx.mboxType = mbox_wr;
4005 phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt;
4006 phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag;
4007 phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum;
4008 phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf;
4010 if (ext_buf_cnt == 1) {
4011 /* bsg tracking structure */
4012 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
4018 /* mailbox command structure for base driver */
4019 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4024 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4025 pmb = &pmboxq->u.mb;
4026 mbx = (uint8_t *)dmabuf->virt;
4027 memcpy(pmb, mbx, sizeof(*pmb));
4028 pmb->mbxOwner = OWN_HOST;
4029 pmboxq->vport = phba->pport;
4031 /* callback for multi-buffer read mailbox command */
4032 pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl;
4034 /* context fields to callback function */
4035 pmboxq->context1 = dd_data;
4036 dd_data->type = TYPE_MBOX;
4037 dd_data->set_job = job;
4038 dd_data->context_un.mbox.pmboxq = pmboxq;
4039 dd_data->context_un.mbox.mb = (MAILBOX_t *)mbx;
4040 job->dd_data = dd_data;
4044 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
4045 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
4046 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
4047 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4048 "2955 Issued SLI_CONFIG ext-buffer "
4049 "maibox command, rc:x%x\n", rc);
4050 return SLI_CONFIG_HANDLED;
4052 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4053 "2956 Failed to issue SLI_CONFIG ext-buffer "
4054 "maibox command, rc:x%x\n", rc);
4059 /* wait for additoinal external buffers */
4061 job->reply->result = 0;
4063 return SLI_CONFIG_HANDLED;
4067 mempool_free(pmboxq, phba->mbox_mem_pool);
4074 * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
4075 * @phba: Pointer to HBA context object.
4076 * @mb: Pointer to a BSG mailbox object.
4077 * @dmabuff: Pointer to a DMA buffer descriptor.
4079 * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
4080 * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
4081 * with embedded sussystem 0x1 and opcodes with external HBDs.
4084 lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job,
4085 struct lpfc_dmabuf *dmabuf)
4087 struct lpfc_sli_config_mbox *sli_cfg_mbx;
4090 int rc = SLI_CONFIG_NOT_HANDLED;
4092 /* state change on new multi-buffer pass-through mailbox command */
4093 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_HOST;
4095 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
4097 if (!bsg_bf_get(lpfc_mbox_hdr_emb,
4098 &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) {
4099 subsys = bsg_bf_get(lpfc_emb0_subcmnd_subsys,
4100 &sli_cfg_mbx->un.sli_config_emb0_subsys);
4101 opcode = bsg_bf_get(lpfc_emb0_subcmnd_opcode,
4102 &sli_cfg_mbx->un.sli_config_emb0_subsys);
4103 if (subsys == SLI_CONFIG_SUBSYS_FCOE) {
4105 case FCOE_OPCODE_READ_FCF:
4106 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4107 "2957 Handled SLI_CONFIG "
4108 "subsys_fcoe, opcode:x%x\n",
4110 rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
4113 case FCOE_OPCODE_ADD_FCF:
4114 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4115 "2958 Handled SLI_CONFIG "
4116 "subsys_fcoe, opcode:x%x\n",
4118 rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job,
4122 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4123 "2959 Reject SLI_CONFIG "
4124 "subsys_fcoe, opcode:x%x\n",
4129 } else if (subsys == SLI_CONFIG_SUBSYS_COMN) {
4131 case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES:
4132 case COMN_OPCODE_GET_CNTL_ATTRIBUTES:
4133 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4134 "3106 Handled SLI_CONFIG "
4135 "subsys_comn, opcode:x%x\n",
4137 rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
4141 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4142 "3107 Reject SLI_CONFIG "
4143 "subsys_comn, opcode:x%x\n",
4149 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4150 "2977 Reject SLI_CONFIG "
4151 "subsys:x%d, opcode:x%x\n",
4156 subsys = bsg_bf_get(lpfc_emb1_subcmnd_subsys,
4157 &sli_cfg_mbx->un.sli_config_emb1_subsys);
4158 opcode = bsg_bf_get(lpfc_emb1_subcmnd_opcode,
4159 &sli_cfg_mbx->un.sli_config_emb1_subsys);
4160 if (subsys == SLI_CONFIG_SUBSYS_COMN) {
4162 case COMN_OPCODE_READ_OBJECT:
4163 case COMN_OPCODE_READ_OBJECT_LIST:
4164 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4165 "2960 Handled SLI_CONFIG "
4166 "subsys_comn, opcode:x%x\n",
4168 rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
4171 case COMN_OPCODE_WRITE_OBJECT:
4172 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4173 "2961 Handled SLI_CONFIG "
4174 "subsys_comn, opcode:x%x\n",
4176 rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job,
4180 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4181 "2962 Not handled SLI_CONFIG "
4182 "subsys_comn, opcode:x%x\n",
4184 rc = SLI_CONFIG_NOT_HANDLED;
4188 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4189 "2978 Not handled SLI_CONFIG "
4190 "subsys:x%d, opcode:x%x\n",
4192 rc = SLI_CONFIG_NOT_HANDLED;
4196 /* state reset on not handled new multi-buffer mailbox command */
4197 if (rc != SLI_CONFIG_HANDLED)
4198 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE;
4204 * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
4205 * @phba: Pointer to HBA context object.
4207 * This routine is for requesting to abort a pass-through mailbox command with
4208 * multiple external buffers due to error condition.
4211 lpfc_bsg_mbox_ext_abort(struct lpfc_hba *phba)
4213 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT)
4214 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS;
4216 lpfc_bsg_mbox_ext_session_reset(phba);
4221 * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
4222 * @phba: Pointer to HBA context object.
4223 * @dmabuf: Pointer to a DMA buffer descriptor.
4225 * This routine extracts the next mailbox read external buffer back to
4226 * user space through BSG.
4229 lpfc_bsg_read_ebuf_get(struct lpfc_hba *phba, struct fc_bsg_job *job)
4231 struct lpfc_sli_config_mbox *sli_cfg_mbx;
4232 struct lpfc_dmabuf *dmabuf;
4237 index = phba->mbox_ext_buf_ctx.seqNum;
4238 phba->mbox_ext_buf_ctx.seqNum++;
4240 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)
4241 phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
4243 if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) {
4244 size = bsg_bf_get(lpfc_mbox_sli_config_mse_len,
4245 &sli_cfg_mbx->un.sli_config_emb0_subsys.mse[index]);
4246 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4247 "2963 SLI_CONFIG (mse) ext-buffer rd get "
4248 "buffer[%d], size:%d\n", index, size);
4250 size = bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
4251 &sli_cfg_mbx->un.sli_config_emb1_subsys.hbd[index]);
4252 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4253 "2964 SLI_CONFIG (hbd) ext-buffer rd get "
4254 "buffer[%d], size:%d\n", index, size);
4256 if (list_empty(&phba->mbox_ext_buf_ctx.ext_dmabuf_list))
4258 dmabuf = list_first_entry(&phba->mbox_ext_buf_ctx.ext_dmabuf_list,
4259 struct lpfc_dmabuf, list);
4260 list_del_init(&dmabuf->list);
4262 /* after dma buffer descriptor setup */
4263 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType,
4264 mbox_rd, dma_ebuf, sta_pos_addr,
4267 pbuf = (uint8_t *)dmabuf->virt;
4268 job->reply->reply_payload_rcv_len =
4269 sg_copy_from_buffer(job->reply_payload.sg_list,
4270 job->reply_payload.sg_cnt,
4273 lpfc_bsg_dma_page_free(phba, dmabuf);
4275 if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) {
4276 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4277 "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
4278 "command session done\n");
4279 lpfc_bsg_mbox_ext_session_reset(phba);
4282 job->reply->result = 0;
4285 return SLI_CONFIG_HANDLED;
4289 * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
4290 * @phba: Pointer to HBA context object.
4291 * @dmabuf: Pointer to a DMA buffer descriptor.
4293 * This routine sets up the next mailbox read external buffer obtained
4294 * from user space through BSG.
4297 lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct fc_bsg_job *job,
4298 struct lpfc_dmabuf *dmabuf)
4300 struct lpfc_sli_config_mbox *sli_cfg_mbx;
4301 struct bsg_job_data *dd_data = NULL;
4302 LPFC_MBOXQ_t *pmboxq = NULL;
4304 enum nemb_type nemb_tp;
4310 index = phba->mbox_ext_buf_ctx.seqNum;
4311 phba->mbox_ext_buf_ctx.seqNum++;
4312 nemb_tp = phba->mbox_ext_buf_ctx.nembType;
4314 sli_cfg_mbx = (struct lpfc_sli_config_mbox *)
4315 phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
4317 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
4323 pbuf = (uint8_t *)dmabuf->virt;
4324 size = job->request_payload.payload_len;
4325 sg_copy_to_buffer(job->request_payload.sg_list,
4326 job->request_payload.sg_cnt,
4329 if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) {
4330 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4331 "2966 SLI_CONFIG (mse) ext-buffer wr set "
4332 "buffer[%d], size:%d\n",
4333 phba->mbox_ext_buf_ctx.seqNum, size);
4336 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4337 "2967 SLI_CONFIG (hbd) ext-buffer wr set "
4338 "buffer[%d], size:%d\n",
4339 phba->mbox_ext_buf_ctx.seqNum, size);
4343 /* set up external buffer descriptor and add to external buffer list */
4344 lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, index,
4345 phba->mbox_ext_buf_ctx.mbx_dmabuf,
4347 list_add_tail(&dmabuf->list, &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
4349 /* after write dma buffer */
4350 lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType,
4351 mbox_wr, dma_ebuf, sta_pos_addr,
4354 if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) {
4355 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4356 "2968 SLI_CONFIG ext-buffer wr all %d "
4357 "ebuffers received\n",
4358 phba->mbox_ext_buf_ctx.numBuf);
4359 /* mailbox command structure for base driver */
4360 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4365 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4366 pbuf = (uint8_t *)phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
4367 pmb = &pmboxq->u.mb;
4368 memcpy(pmb, pbuf, sizeof(*pmb));
4369 pmb->mbxOwner = OWN_HOST;
4370 pmboxq->vport = phba->pport;
4372 /* callback for multi-buffer write mailbox command */
4373 pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl;
4375 /* context fields to callback function */
4376 pmboxq->context1 = dd_data;
4377 dd_data->type = TYPE_MBOX;
4378 dd_data->set_job = job;
4379 dd_data->context_un.mbox.pmboxq = pmboxq;
4380 dd_data->context_un.mbox.mb = (MAILBOX_t *)pbuf;
4381 job->dd_data = dd_data;
4384 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
4386 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
4387 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
4388 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4389 "2969 Issued SLI_CONFIG ext-buffer "
4390 "maibox command, rc:x%x\n", rc);
4391 return SLI_CONFIG_HANDLED;
4393 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4394 "2970 Failed to issue SLI_CONFIG ext-buffer "
4395 "maibox command, rc:x%x\n", rc);
4400 /* wait for additoinal external buffers */
4401 job->reply->result = 0;
4403 return SLI_CONFIG_HANDLED;
4406 lpfc_bsg_dma_page_free(phba, dmabuf);
4413 * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
4414 * @phba: Pointer to HBA context object.
4415 * @mb: Pointer to a BSG mailbox object.
4416 * @dmabuff: Pointer to a DMA buffer descriptor.
4418 * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
4419 * command with multiple non-embedded external buffers.
4422 lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba *phba, struct fc_bsg_job *job,
4423 struct lpfc_dmabuf *dmabuf)
4427 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4428 "2971 SLI_CONFIG buffer (type:x%x)\n",
4429 phba->mbox_ext_buf_ctx.mboxType);
4431 if (phba->mbox_ext_buf_ctx.mboxType == mbox_rd) {
4432 if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_DONE) {
4433 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4434 "2972 SLI_CONFIG rd buffer state "
4436 phba->mbox_ext_buf_ctx.state);
4437 lpfc_bsg_mbox_ext_abort(phba);
4440 rc = lpfc_bsg_read_ebuf_get(phba, job);
4441 if (rc == SLI_CONFIG_HANDLED)
4442 lpfc_bsg_dma_page_free(phba, dmabuf);
4443 } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
4444 if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_HOST) {
4445 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4446 "2973 SLI_CONFIG wr buffer state "
4448 phba->mbox_ext_buf_ctx.state);
4449 lpfc_bsg_mbox_ext_abort(phba);
4452 rc = lpfc_bsg_write_ebuf_set(phba, job, dmabuf);
4458 * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
4459 * @phba: Pointer to HBA context object.
4460 * @mb: Pointer to a BSG mailbox object.
4461 * @dmabuff: Pointer to a DMA buffer descriptor.
4463 * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
4464 * (0x9B) mailbox commands and external buffers.
4467 lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba *phba, struct fc_bsg_job *job,
4468 struct lpfc_dmabuf *dmabuf)
4470 struct dfc_mbox_req *mbox_req;
4471 int rc = SLI_CONFIG_NOT_HANDLED;
4474 (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
4476 /* mbox command with/without single external buffer */
4477 if (mbox_req->extMboxTag == 0 && mbox_req->extSeqNum == 0)
4480 /* mbox command and first external buffer */
4481 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE) {
4482 if (mbox_req->extSeqNum == 1) {
4483 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4484 "2974 SLI_CONFIG mailbox: tag:%d, "
4485 "seq:%d\n", mbox_req->extMboxTag,
4486 mbox_req->extSeqNum);
4487 rc = lpfc_bsg_handle_sli_cfg_mbox(phba, job, dmabuf);
4490 goto sli_cfg_ext_error;
4494 * handle additional external buffers
4497 /* check broken pipe conditions */
4498 if (mbox_req->extMboxTag != phba->mbox_ext_buf_ctx.mbxTag)
4499 goto sli_cfg_ext_error;
4500 if (mbox_req->extSeqNum > phba->mbox_ext_buf_ctx.numBuf)
4501 goto sli_cfg_ext_error;
4502 if (mbox_req->extSeqNum != phba->mbox_ext_buf_ctx.seqNum + 1)
4503 goto sli_cfg_ext_error;
4505 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4506 "2975 SLI_CONFIG mailbox external buffer: "
4507 "extSta:x%x, tag:%d, seq:%d\n",
4508 phba->mbox_ext_buf_ctx.state, mbox_req->extMboxTag,
4509 mbox_req->extSeqNum);
4510 rc = lpfc_bsg_handle_sli_cfg_ebuf(phba, job, dmabuf);
4514 /* all other cases, broken pipe */
4515 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
4516 "2976 SLI_CONFIG mailbox broken pipe: "
4517 "ctxSta:x%x, ctxNumBuf:%d "
4518 "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
4519 phba->mbox_ext_buf_ctx.state,
4520 phba->mbox_ext_buf_ctx.numBuf,
4521 phba->mbox_ext_buf_ctx.mbxTag,
4522 phba->mbox_ext_buf_ctx.seqNum,
4523 mbox_req->extMboxTag, mbox_req->extSeqNum);
4525 lpfc_bsg_mbox_ext_session_reset(phba);
4531 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
4532 * @phba: Pointer to HBA context object.
4533 * @mb: Pointer to a mailbox object.
4534 * @vport: Pointer to a vport object.
4536 * Allocate a tracking object, mailbox command memory, get a mailbox
4537 * from the mailbox pool, copy the caller mailbox command.
4539 * If offline and the sli is active we need to poll for the command (port is
4540 * being reset) and com-plete the job, otherwise issue the mailbox command and
4541 * let our completion handler finish the command.
4544 lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job,
4545 struct lpfc_vport *vport)
4547 LPFC_MBOXQ_t *pmboxq = NULL; /* internal mailbox queue */
4548 MAILBOX_t *pmb; /* shortcut to the pmboxq mailbox */
4549 /* a 4k buffer to hold the mb and extended data from/to the bsg */
4550 uint8_t *pmbx = NULL;
4551 struct bsg_job_data *dd_data = NULL; /* bsg data tracking structure */
4552 struct lpfc_dmabuf *dmabuf = NULL;
4553 struct dfc_mbox_req *mbox_req;
4554 struct READ_EVENT_LOG_VAR *rdEventLog;
4555 uint32_t transmit_length, receive_length, mode;
4556 struct lpfc_mbx_sli4_config *sli4_config;
4557 struct lpfc_mbx_nembed_cmd *nembed_sge;
4558 struct mbox_header *header;
4559 struct ulp_bde64 *bde;
4560 uint8_t *ext = NULL;
4565 /* in case no data is transferred */
4566 job->reply->reply_payload_rcv_len = 0;
4568 /* sanity check to protect driver */
4569 if (job->reply_payload.payload_len > BSG_MBOX_SIZE ||
4570 job->request_payload.payload_len > BSG_MBOX_SIZE) {
4576 * Don't allow mailbox commands to be sent when blocked or when in
4577 * the middle of discovery
4579 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
4585 (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
4587 /* check if requested extended data lengths are valid */
4588 if ((mbox_req->inExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t)) ||
4589 (mbox_req->outExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t))) {
4594 dmabuf = lpfc_bsg_dma_page_alloc(phba);
4595 if (!dmabuf || !dmabuf->virt) {
4600 /* Get the mailbox command or external buffer from BSG */
4601 pmbx = (uint8_t *)dmabuf->virt;
4602 size = job->request_payload.payload_len;
4603 sg_copy_to_buffer(job->request_payload.sg_list,
4604 job->request_payload.sg_cnt, pmbx, size);
4606 /* Handle possible SLI_CONFIG with non-embedded payloads */
4607 if (phba->sli_rev == LPFC_SLI_REV4) {
4608 rc = lpfc_bsg_handle_sli_cfg_ext(phba, job, dmabuf);
4609 if (rc == SLI_CONFIG_HANDLED)
4613 /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
4616 rc = lpfc_bsg_check_cmd_access(phba, (MAILBOX_t *)pmbx, vport);
4618 goto job_done; /* must be negative */
4620 /* allocate our bsg tracking structure */
4621 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
4623 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
4624 "2727 Failed allocation of dd_data\n");
4629 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4634 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4636 pmb = &pmboxq->u.mb;
4637 memcpy(pmb, pmbx, sizeof(*pmb));
4638 pmb->mbxOwner = OWN_HOST;
4639 pmboxq->vport = vport;
4641 /* If HBA encountered an error attention, allow only DUMP
4642 * or RESTART mailbox commands until the HBA is restarted.
4644 if (phba->pport->stopped &&
4645 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4646 pmb->mbxCommand != MBX_RESTART &&
4647 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4648 pmb->mbxCommand != MBX_WRITE_WWN)
4649 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4650 "2797 mbox: Issued mailbox cmd "
4651 "0x%x while in stopped state.\n",
4654 /* extended mailbox commands will need an extended buffer */
4655 if (mbox_req->inExtWLen || mbox_req->outExtWLen) {
4657 ext = from + sizeof(MAILBOX_t);
4658 pmboxq->context2 = ext;
4659 pmboxq->in_ext_byte_len =
4660 mbox_req->inExtWLen * sizeof(uint32_t);
4661 pmboxq->out_ext_byte_len =
4662 mbox_req->outExtWLen * sizeof(uint32_t);
4663 pmboxq->mbox_offset_word = mbox_req->mbOffset;
4666 /* biu diag will need a kernel buffer to transfer the data
4667 * allocate our own buffer and setup the mailbox command to
4670 if (pmb->mbxCommand == MBX_RUN_BIU_DIAG64) {
4671 transmit_length = pmb->un.varWords[1];
4672 receive_length = pmb->un.varWords[4];
4673 /* transmit length cannot be greater than receive length or
4674 * mailbox extension size
4676 if ((transmit_length > receive_length) ||
4677 (transmit_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t))) {
4681 pmb->un.varBIUdiag.un.s2.xmit_bde64.addrHigh =
4682 putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t));
4683 pmb->un.varBIUdiag.un.s2.xmit_bde64.addrLow =
4684 putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t));
4686 pmb->un.varBIUdiag.un.s2.rcv_bde64.addrHigh =
4687 putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t)
4688 + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize);
4689 pmb->un.varBIUdiag.un.s2.rcv_bde64.addrLow =
4690 putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t)
4691 + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize);
4692 } else if (pmb->mbxCommand == MBX_READ_EVENT_LOG) {
4693 rdEventLog = &pmb->un.varRdEventLog;
4694 receive_length = rdEventLog->rcv_bde64.tus.f.bdeSize;
4695 mode = bf_get(lpfc_event_log, rdEventLog);
4697 /* receive length cannot be greater than mailbox
4700 if (receive_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t)) {
4705 /* mode zero uses a bde like biu diags command */
4707 pmb->un.varWords[3] = putPaddrLow(dmabuf->phys
4708 + sizeof(MAILBOX_t));
4709 pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys
4710 + sizeof(MAILBOX_t));
4712 } else if (phba->sli_rev == LPFC_SLI_REV4) {
4713 /* Let type 4 (well known data) through because the data is
4714 * returned in varwords[4-8]
4715 * otherwise check the recieve length and fetch the buffer addr
4717 if ((pmb->mbxCommand == MBX_DUMP_MEMORY) &&
4718 (pmb->un.varDmp.type != DMP_WELL_KNOWN)) {
4719 /* rebuild the command for sli4 using our own buffers
4720 * like we do for biu diags
4722 receive_length = pmb->un.varWords[2];
4723 /* receive length cannot be greater than mailbox
4726 if (receive_length == 0) {
4730 pmb->un.varWords[3] = putPaddrLow(dmabuf->phys
4731 + sizeof(MAILBOX_t));
4732 pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys
4733 + sizeof(MAILBOX_t));
4734 } else if ((pmb->mbxCommand == MBX_UPDATE_CFG) &&
4735 pmb->un.varUpdateCfg.co) {
4736 bde = (struct ulp_bde64 *)&pmb->un.varWords[4];
4738 /* bde size cannot be greater than mailbox ext size */
4739 if (bde->tus.f.bdeSize >
4740 BSG_MBOX_SIZE - sizeof(MAILBOX_t)) {
4744 bde->addrHigh = putPaddrHigh(dmabuf->phys
4745 + sizeof(MAILBOX_t));
4746 bde->addrLow = putPaddrLow(dmabuf->phys
4747 + sizeof(MAILBOX_t));
4748 } else if (pmb->mbxCommand == MBX_SLI4_CONFIG) {
4749 /* Handling non-embedded SLI_CONFIG mailbox command */
4750 sli4_config = &pmboxq->u.mqe.un.sli4_config;
4751 if (!bf_get(lpfc_mbox_hdr_emb,
4752 &sli4_config->header.cfg_mhdr)) {
4753 /* rebuild the command for sli4 using our
4754 * own buffers like we do for biu diags
4756 header = (struct mbox_header *)
4757 &pmb->un.varWords[0];
4758 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
4759 &pmb->un.varWords[0];
4760 receive_length = nembed_sge->sge[0].length;
4762 /* receive length cannot be greater than
4763 * mailbox extension size
4765 if ((receive_length == 0) ||
4767 BSG_MBOX_SIZE - sizeof(MAILBOX_t))) {
4772 nembed_sge->sge[0].pa_hi =
4773 putPaddrHigh(dmabuf->phys
4774 + sizeof(MAILBOX_t));
4775 nembed_sge->sge[0].pa_lo =
4776 putPaddrLow(dmabuf->phys
4777 + sizeof(MAILBOX_t));
4782 dd_data->context_un.mbox.dmabuffers = dmabuf;
4784 /* setup wake call as IOCB callback */
4785 pmboxq->mbox_cmpl = lpfc_bsg_issue_mbox_cmpl;
4787 /* setup context field to pass wait_queue pointer to wake function */
4788 pmboxq->context1 = dd_data;
4789 dd_data->type = TYPE_MBOX;
4790 dd_data->set_job = job;
4791 dd_data->context_un.mbox.pmboxq = pmboxq;
4792 dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx;
4793 dd_data->context_un.mbox.ext = ext;
4794 dd_data->context_un.mbox.mbOffset = mbox_req->mbOffset;
4795 dd_data->context_un.mbox.inExtWLen = mbox_req->inExtWLen;
4796 dd_data->context_un.mbox.outExtWLen = mbox_req->outExtWLen;
4797 job->dd_data = dd_data;
4799 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4800 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
4801 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4802 if (rc != MBX_SUCCESS) {
4803 rc = (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
4807 /* job finished, copy the data */
4808 memcpy(pmbx, pmb, sizeof(*pmb));
4809 job->reply->reply_payload_rcv_len =
4810 sg_copy_from_buffer(job->reply_payload.sg_list,
4811 job->reply_payload.sg_cnt,
4813 /* not waiting mbox already done */
4818 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
4819 if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY))
4820 return 1; /* job started */
4823 /* common exit for error or job completed inline */
4825 mempool_free(pmboxq, phba->mbox_mem_pool);
4826 lpfc_bsg_dma_page_free(phba, dmabuf);
4834 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
4835 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
4838 lpfc_bsg_mbox_cmd(struct fc_bsg_job *job)
4840 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
4841 struct lpfc_hba *phba = vport->phba;
4842 struct dfc_mbox_req *mbox_req;
4845 /* mix-and-match backward compatibility */
4846 job->reply->reply_payload_rcv_len = 0;
4847 if (job->request_len <
4848 sizeof(struct fc_bsg_request) + sizeof(struct dfc_mbox_req)) {
4849 lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
4850 "2737 Mix-and-match backward compatibility "
4851 "between MBOX_REQ old size:%d and "
4852 "new request size:%d\n",
4853 (int)(job->request_len -
4854 sizeof(struct fc_bsg_request)),
4855 (int)sizeof(struct dfc_mbox_req));
4856 mbox_req = (struct dfc_mbox_req *)
4857 job->request->rqst_data.h_vendor.vendor_cmd;
4858 mbox_req->extMboxTag = 0;
4859 mbox_req->extSeqNum = 0;
4862 rc = lpfc_bsg_issue_mbox(phba, job, vport);
4866 job->reply->result = 0;
4867 job->dd_data = NULL;
4870 /* job submitted, will complete later*/
4871 rc = 0; /* return zero, no error */
4873 /* some error occurred */
4874 job->reply->result = rc;
4875 job->dd_data = NULL;
4882 * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
4883 * @phba: Pointer to HBA context object.
4884 * @cmdiocbq: Pointer to command iocb.
4885 * @rspiocbq: Pointer to response iocb.
4887 * This function is the completion handler for iocbs issued using
4888 * lpfc_menlo_cmd function. This function is called by the
4889 * ring event handler function without any lock held. This function
4890 * can be called from both worker thread context and interrupt
4891 * context. This function also can be called from another thread which
4892 * cleans up the SLI layer objects.
4893 * This function copies the contents of the response iocb to the
4894 * response iocb memory object provided by the caller of
4895 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4896 * sleeps for the iocb completion.
4899 lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba *phba,
4900 struct lpfc_iocbq *cmdiocbq,
4901 struct lpfc_iocbq *rspiocbq)
4903 struct bsg_job_data *dd_data;
4904 struct fc_bsg_job *job;
4906 struct lpfc_dmabuf *bmp, *cmp, *rmp;
4907 struct lpfc_bsg_menlo *menlo;
4908 unsigned long flags;
4909 struct menlo_response *menlo_resp;
4910 unsigned int rsp_size;
4913 dd_data = cmdiocbq->context1;
4914 cmp = cmdiocbq->context2;
4915 bmp = cmdiocbq->context3;
4916 menlo = &dd_data->context_un.menlo;
4918 rsp = &rspiocbq->iocb;
4920 /* Determine if job has been aborted */
4921 spin_lock_irqsave(&phba->ct_ev_lock, flags);
4922 job = dd_data->set_job;
4924 /* Prevent timeout handling from trying to abort job */
4925 job->dd_data = NULL;
4927 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
4929 /* Copy the job data or set the failing status for the job */
4932 /* always return the xri, this would be used in the case
4933 * of a menlo download to allow the data to be sent as a
4934 * continuation of the exchange.
4937 menlo_resp = (struct menlo_response *)
4938 job->reply->reply_data.vendor_reply.vendor_rsp;
4939 menlo_resp->xri = rsp->ulpContext;
4940 if (rsp->ulpStatus) {
4941 if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
4942 switch (rsp->un.ulpWord[4] & IOERR_PARAM_MASK) {
4943 case IOERR_SEQUENCE_TIMEOUT:
4946 case IOERR_INVALID_RPI:
4957 rsp_size = rsp->un.genreq64.bdl.bdeSize;
4958 job->reply->reply_payload_rcv_len =
4959 lpfc_bsg_copy_data(rmp, &job->reply_payload,
4965 lpfc_sli_release_iocbq(phba, cmdiocbq);
4966 lpfc_free_bsg_buffers(phba, cmp);
4967 lpfc_free_bsg_buffers(phba, rmp);
4968 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
4972 /* Complete the job if active */
4975 job->reply->result = rc;
4983 * lpfc_menlo_cmd - send an ioctl for menlo hardware
4984 * @job: fc_bsg_job to handle
4986 * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
4987 * all the command completions will return the xri for the command.
4988 * For menlo data requests a gen request 64 CX is used to continue the exchange
4989 * supplied in the menlo request header xri field.
4992 lpfc_menlo_cmd(struct fc_bsg_job *job)
4994 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
4995 struct lpfc_hba *phba = vport->phba;
4996 struct lpfc_iocbq *cmdiocbq;
4999 struct menlo_command *menlo_cmd;
5000 struct menlo_response *menlo_resp;
5001 struct lpfc_dmabuf *bmp = NULL, *cmp = NULL, *rmp = NULL;
5004 struct bsg_job_data *dd_data;
5005 struct ulp_bde64 *bpl = NULL;
5007 /* in case no data is returned return just the return code */
5008 job->reply->reply_payload_rcv_len = 0;
5010 if (job->request_len <
5011 sizeof(struct fc_bsg_request) +
5012 sizeof(struct menlo_command)) {
5013 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
5014 "2784 Received MENLO_CMD request below "
5020 if (job->reply_len <
5021 sizeof(struct fc_bsg_request) + sizeof(struct menlo_response)) {
5022 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
5023 "2785 Received MENLO_CMD reply below "
5029 if (!(phba->menlo_flag & HBA_MENLO_SUPPORT)) {
5030 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
5031 "2786 Adapter does not support menlo "
5037 menlo_cmd = (struct menlo_command *)
5038 job->request->rqst_data.h_vendor.vendor_cmd;
5040 menlo_resp = (struct menlo_response *)
5041 job->reply->reply_data.vendor_reply.vendor_rsp;
5043 /* allocate our bsg tracking structure */
5044 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
5046 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
5047 "2787 Failed allocation of dd_data\n");
5052 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5058 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
5064 INIT_LIST_HEAD(&bmp->list);
5066 bpl = (struct ulp_bde64 *)bmp->virt;
5067 request_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64);
5068 cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len,
5069 1, bpl, &request_nseg);
5074 lpfc_bsg_copy_data(cmp, &job->request_payload,
5075 job->request_payload.payload_len, 1);
5077 bpl += request_nseg;
5078 reply_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64) - request_nseg;
5079 rmp = lpfc_alloc_bsg_buffers(phba, job->reply_payload.payload_len, 0,
5086 cmdiocbq = lpfc_sli_get_iocbq(phba);
5092 cmd = &cmdiocbq->iocb;
5093 cmd->un.genreq64.bdl.ulpIoTag32 = 0;
5094 cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
5095 cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
5096 cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
5097 cmd->un.genreq64.bdl.bdeSize =
5098 (request_nseg + reply_nseg) * sizeof(struct ulp_bde64);
5099 cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
5100 cmd->un.genreq64.w5.hcsw.Dfctl = 0;
5101 cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CMD;
5102 cmd->un.genreq64.w5.hcsw.Type = MENLO_TRANSPORT_TYPE; /* 0xfe */
5103 cmd->ulpBdeCount = 1;
5104 cmd->ulpClass = CLASS3;
5105 cmd->ulpOwner = OWN_CHIP;
5106 cmd->ulpLe = 1; /* Limited Edition */
5107 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
5108 cmdiocbq->vport = phba->pport;
5109 /* We want the firmware to timeout before we do */
5110 cmd->ulpTimeout = MENLO_TIMEOUT - 5;
5111 cmdiocbq->iocb_cmpl = lpfc_bsg_menlo_cmd_cmp;
5112 cmdiocbq->context1 = dd_data;
5113 cmdiocbq->context2 = cmp;
5114 cmdiocbq->context3 = bmp;
5115 if (menlo_cmd->cmd == LPFC_BSG_VENDOR_MENLO_CMD) {
5116 cmd->ulpCommand = CMD_GEN_REQUEST64_CR;
5117 cmd->ulpPU = MENLO_PU; /* 3 */
5118 cmd->un.ulpWord[4] = MENLO_DID; /* 0x0000FC0E */
5119 cmd->ulpContext = MENLO_CONTEXT; /* 0 */
5121 cmd->ulpCommand = CMD_GEN_REQUEST64_CX;
5123 cmd->un.ulpWord[4] = 0;
5124 cmd->ulpContext = menlo_cmd->xri;
5127 dd_data->type = TYPE_MENLO;
5128 dd_data->set_job = job;
5129 dd_data->context_un.menlo.cmdiocbq = cmdiocbq;
5130 dd_data->context_un.menlo.rmp = rmp;
5131 job->dd_data = dd_data;
5133 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq,
5135 if (rc == IOCB_SUCCESS)
5136 return 0; /* done for now */
5138 lpfc_sli_release_iocbq(phba, cmdiocbq);
5141 lpfc_free_bsg_buffers(phba, rmp);
5143 lpfc_free_bsg_buffers(phba, cmp);
5146 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
5151 /* make error code available to userspace */
5152 job->reply->result = rc;
5153 job->dd_data = NULL;
5158 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
5159 * @job: fc_bsg_job to handle
5162 lpfc_bsg_hst_vendor(struct fc_bsg_job *job)
5164 int command = job->request->rqst_data.h_vendor.vendor_cmd[0];
5168 case LPFC_BSG_VENDOR_SET_CT_EVENT:
5169 rc = lpfc_bsg_hba_set_event(job);
5171 case LPFC_BSG_VENDOR_GET_CT_EVENT:
5172 rc = lpfc_bsg_hba_get_event(job);
5174 case LPFC_BSG_VENDOR_SEND_MGMT_RESP:
5175 rc = lpfc_bsg_send_mgmt_rsp(job);
5177 case LPFC_BSG_VENDOR_DIAG_MODE:
5178 rc = lpfc_bsg_diag_loopback_mode(job);
5180 case LPFC_BSG_VENDOR_DIAG_MODE_END:
5181 rc = lpfc_sli4_bsg_diag_mode_end(job);
5183 case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK:
5184 rc = lpfc_bsg_diag_loopback_run(job);
5186 case LPFC_BSG_VENDOR_LINK_DIAG_TEST:
5187 rc = lpfc_sli4_bsg_link_diag_test(job);
5189 case LPFC_BSG_VENDOR_GET_MGMT_REV:
5190 rc = lpfc_bsg_get_dfc_rev(job);
5192 case LPFC_BSG_VENDOR_MBOX:
5193 rc = lpfc_bsg_mbox_cmd(job);
5195 case LPFC_BSG_VENDOR_MENLO_CMD:
5196 case LPFC_BSG_VENDOR_MENLO_DATA:
5197 rc = lpfc_menlo_cmd(job);
5201 job->reply->reply_payload_rcv_len = 0;
5202 /* make error code available to userspace */
5203 job->reply->result = rc;
5211 * lpfc_bsg_request - handle a bsg request from the FC transport
5212 * @job: fc_bsg_job to handle
5215 lpfc_bsg_request(struct fc_bsg_job *job)
5220 msgcode = job->request->msgcode;
5222 case FC_BSG_HST_VENDOR:
5223 rc = lpfc_bsg_hst_vendor(job);
5225 case FC_BSG_RPT_ELS:
5226 rc = lpfc_bsg_rport_els(job);
5229 rc = lpfc_bsg_send_mgmt_cmd(job);
5233 job->reply->reply_payload_rcv_len = 0;
5234 /* make error code available to userspace */
5235 job->reply->result = rc;
5243 * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
5244 * @job: fc_bsg_job that has timed out
5246 * This function just aborts the job's IOCB. The aborted IOCB will return to
5247 * the waiting function which will handle passing the error back to userspace
5250 lpfc_bsg_timeout(struct fc_bsg_job *job)
5252 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
5253 struct lpfc_hba *phba = vport->phba;
5254 struct lpfc_iocbq *cmdiocb;
5255 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5256 struct bsg_job_data *dd_data;
5257 unsigned long flags;
5259 LIST_HEAD(completions);
5260 struct lpfc_iocbq *check_iocb, *next_iocb;
5262 /* if job's driver data is NULL, the command completed or is in the
5263 * the process of completing. In this case, return status to request
5264 * so the timeout is retried. This avoids double completion issues
5265 * and the request will be pulled off the timer queue when the
5266 * command's completion handler executes. Otherwise, prevent the
5267 * command's completion handler from executing the job done callback
5268 * and continue processing to abort the outstanding the command.
5271 spin_lock_irqsave(&phba->ct_ev_lock, flags);
5272 dd_data = (struct bsg_job_data *)job->dd_data;
5274 dd_data->set_job = NULL;
5275 job->dd_data = NULL;
5277 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5281 switch (dd_data->type) {
5283 /* Check to see if IOCB was issued to the port or not. If not,
5284 * remove it from the txq queue and call cancel iocbs.
5285 * Otherwise, call abort iotag
5288 cmdiocb = dd_data->context_un.iocb.cmdiocbq;
5289 spin_lock_irq(&phba->hbalock);
5290 list_for_each_entry_safe(check_iocb, next_iocb, &pring->txq,
5292 if (check_iocb == cmdiocb) {
5293 list_move_tail(&check_iocb->list, &completions);
5297 if (list_empty(&completions))
5298 lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb);
5299 spin_unlock_irq(&phba->hbalock);
5300 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5301 if (!list_empty(&completions)) {
5302 lpfc_sli_cancel_iocbs(phba, &completions,
5303 IOSTAT_LOCAL_REJECT,
5309 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5313 /* Update the ext buf ctx state if needed */
5315 if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT)
5316 phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS;
5317 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5320 /* Check to see if IOCB was issued to the port or not. If not,
5321 * remove it from the txq queue and call cancel iocbs.
5322 * Otherwise, call abort iotag.
5325 cmdiocb = dd_data->context_un.menlo.cmdiocbq;
5326 spin_lock_irq(&phba->hbalock);
5327 list_for_each_entry_safe(check_iocb, next_iocb, &pring->txq,
5329 if (check_iocb == cmdiocb) {
5330 list_move_tail(&check_iocb->list, &completions);
5334 if (list_empty(&completions))
5335 lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb);
5336 spin_unlock_irq(&phba->hbalock);
5337 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5338 if (!list_empty(&completions)) {
5339 lpfc_sli_cancel_iocbs(phba, &completions,
5340 IOSTAT_LOCAL_REJECT,
5345 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
5349 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
5350 * otherwise an error message will be displayed on the console
5351 * so always return success (zero)