FC_SLI3_HBQ_ENABLED) {
				bdeBuf1 = iocbq->context2;
				bdeBuf2 = iocbq->context3;
			}
			for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) {
				int size = 0;
				if (phba->sli3_options &
				    LPFC_SLI3_HBQ_ENABLED) {
					if (i == 0) {
						hbqe = (struct lpfc_hbq_entry *)
						  &iocbq->iocb.un.ulpWord[0];
						size = hbqe->bde.tus.f.bdeSize;
						dmabuf = bdeBuf1;
					} else if (i == 1) {
						hbqe = (struct lpfc_hbq_entry *)
							&iocbq->iocb.unsli3.
							sli3Words[4];
						size = hbqe->bde.tus.f.bdeSize;
						dmabuf = bdeBuf2;
					}
					if ((offset + size) > evt_dat->len)
						size = evt_dat->len - offset;
				} else {
					size = iocbq->iocb.un.cont64[i].
						tus.f.bdeSize;
					bde = &iocbq->iocb.un.cont64[i];
					dma_addr = getPaddr(bde->addrHigh,
							    bde->addrLow);
					dmabuf = lpfc_sli_ringpostbuf_get(phba,
							pring, dma_addr);
				}
				if (!dmabuf) {
					lpfc_printf_log(phba, KERN_ERR,
						LOG_LIBDFC, "2616 No dmabuf "
						"found for iocbq 0x%p\n",
						iocbq);
					kfree(evt_dat->data);
					kfree(evt_dat);
					mutex_lock(&phba->ct_event_mutex);
					lpfc_ct_event_unref(evt);
					mutex_unlock(&phba->ct_event_mutex);
					goto error_ct_unsol_exit;
				}
				memcpy((char *)(evt_dat->data) + offset,
				       dmabuf->virt, size);
				offset += size;
				if (evt_req_id!= SLI_CT_ELX_LOOPBACK &&
				   !(phba->sli3_options &
				      LPFC_SLI3_HBQ_ENABLED)) {
					lpfc_sli_ringpostbuf_put(phba, pring,
								 dmabuf);
				} else {
					switch (cmd) {
					case ELX_LOOPBACK_XRI_SETUP:
						if (!(phba->sli3_options &
						      LPFC_SLI3_HBQ_ENABLED))
							lpfc_post_buffer(phba,
									 pring,
									 1);
						else
							lpfc_in_buf_free(phba,
									dmabuf);
						break;
					default:
						if (!(phba->sli3_options &
						      LPFC_SLI3_HBQ_ENABLED))
							lpfc_post_buffer(phba,
									 pring,
									 1);
						break;
					}
				}
			}
		}

		mutex_lock(&phba->ct_event_mutex);
		if (phba->sli_rev == LPFC_SLI_REV4) {
			evt_dat->immed_dat = phba->ctx_idx;
			phba->ctx_idx = (phba->ctx_idx + 1) % 64;
			phba->ct_ctx[evt_dat->immed_dat].oxid =
						piocbq->iocb.ulpContext;
			phba->ct_ctx[evt_dat->immed_dat].SID =
				piocbq->iocb.un.rcvels.remoteID;
		} else
			evt_dat->immed_dat = piocbq->iocb.ulpContext;

		evt_dat->type = FC_REG_CT_EVENT;
		list_add(&evt_dat->node, &evt->events_to_see);
		wake_up_interruptible(&evt->wq);
		lpfc_ct_event_unref(evt);
		if (evt_req_id == SLI_CT_ELX_LOOPBACK)
			break;
	}
	mutex_unlock(&phba->ct_event_mutex);

error_ct_unsol_exit:
	if (!list_empty(&head))
		list_del(&head);

	return;
}

/**
 * lpfc_bsg_set_event - process a SET_EVENT bsg vendor command
 * @job: SET_EVENT fc_bsg_job
 */
static int
lpfc_bsg_set_event(struct fc_bsg_job *job)
{
	struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
	struct lpfc_hba *phba = vport->phba;
	struct set_ct_event *event_req;
	struct lpfc_ct_event *evt;
	int rc = 0;

	if (job->request_len <
	    sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) {
		lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
				"2612 Received SET_CT_EVENT below minimum "
				"size\n");
		return -EINVAL;
	}

	event_req = (struct set_ct_event *)
		job->request->rqst_data.h_vendor.vendor_cmd;

	mutex_lock(&phba->ct_event_mutex);
	list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
		if (evt->reg_id == event_req->ev_reg_id) {
			lpfc_ct_event_ref(evt);
			evt->wait_time_stamp = jiffies;
			break;
		}
	}
	mutex_unlock(&phba->ct_event_mutex);

	if (&evt->node == &phba->ct_ev_waiters) {
		/* no event waiting struct yet - first call */
		evt = lpfc_ct_event_new(event_req->ev_reg_id,
					event_req->ev_req_id);
		if (!evt) {
			lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
					"2617 Failed allocation of event "
					"waiter\n");
			return -ENOMEM;
		}

		mutex_lock(&phba->ct_event_mutex);
		list_add(&evt->node, &phba->ct_ev_waiters);
		lpfc_ct_event_ref(evt);
		mutex_unlock(&phba->ct_event_mutex);
	}

	evt->waiting = 1;
	if (wait_event_interruptible(evt->wq,
				    !list_empty(&evt->events_to_see))) {
		mutex_lock(&phba->ct_event_mutex);
		lpfc_ct_event_unref(evt); /* release ref */
		lpfc_ct_event_unref(evt); /* delete */
		mutex_unlock(&phba->ct_event_mutex);
		rc = -EINTR;
		goto set_event_out;
	}

	evt->wait_time_stamp = jiffies;
	evt->waiting = 0;

	mutex_lock(&phba->ct_event_mutex);
	list_move(evt->events_to_see.prev, &evt->events_to_get);
	lpfc_ct_event_unref(evt); /* release ref */
	mutex_unlock(&phba->ct_event_mutex);

set_event_out:
	/* set_event carries no reply payload */
	job->reply->reply_payload_rcv_len = 0;
	/* make error code available to userspace */
	job->