void c2_ae_event(struct c2_dev *c2dev, u32 mq_index) { struct c2_mq *mq = c2dev->qptr_array[mq_index]; union c2wr *wr; void *resource_user_context; struct iw_cm_event cm_event; struct ib_event ib_event; enum c2_resource_indicator resource_indicator; enum c2_event_id event_id; unsigned long flags; int status; /* * retrieve the message */ wr = c2_mq_consume(mq); if (!wr) return; memset(&ib_event, 0, sizeof(ib_event)); memset(&cm_event, 0, sizeof(cm_event)); event_id = c2_wr_get_id(wr); resource_indicator = be32_to_cpu(wr->ae.ae_generic.resource_type); resource_user_context = (void *) (unsigned long) wr->ae.ae_generic.user_context; status = cm_event.status = c2_convert_cm_status(c2_wr_get_result(wr)); pr_debug("event received c2_dev=%p, event_id=%d, " "resource_indicator=%d, user_context=%p, status = %d\n", c2dev, event_id, resource_indicator, resource_user_context, status); switch (resource_indicator) { case C2_RES_IND_QP:{ struct c2_qp *qp = (struct c2_qp *)resource_user_context; struct iw_cm_id *cm_id = qp->cm_id; struct c2wr_ae_active_connect_results *res; if (!cm_id) { pr_debug("event received, but cm_id is <nul>, qp=%p!\n", qp); goto ignore_it; } pr_debug("%s: event = %s, user_context=%llx, " "resource_type=%x, " "resource=%x, qp_state=%s\n", __func__, to_event_str(event_id), (unsigned long long) wr->ae.ae_generic.user_context, be32_to_cpu(wr->ae.ae_generic.resource_type), be32_to_cpu(wr->ae.ae_generic.resource), to_qp_state_str(be32_to_cpu(wr->ae.ae_generic.qp_state))); c2_set_qp_state(qp, be32_to_cpu(wr->ae.ae_generic.qp_state)); switch (event_id) { case CCAE_ACTIVE_CONNECT_RESULTS: res = &wr->ae.ae_active_connect_results; cm_event.event = IW_CM_EVENT_CONNECT_REPLY; cm_event.local_addr.sin_addr.s_addr = res->laddr; cm_event.remote_addr.sin_addr.s_addr = res->raddr; cm_event.local_addr.sin_port = res->lport; cm_event.remote_addr.sin_port = res->rport; if (status == 0) { cm_event.private_data_len = be32_to_cpu(res->private_data_length); cm_event.private_data = res->private_data; } else { spin_lock_irqsave(&qp->lock, flags); if (qp->cm_id) { qp->cm_id->rem_ref(qp->cm_id); qp->cm_id = NULL; } spin_unlock_irqrestore(&qp->lock, flags); cm_event.private_data_len = 0; cm_event.private_data = NULL; } if (cm_id->event_handler) cm_id->event_handler(cm_id, &cm_event); break; case CCAE_TERMINATE_MESSAGE_RECEIVED: case CCAE_CQ_SQ_COMPLETION_OVERFLOW: ib_event.device = &c2dev->ibdev; ib_event.element.qp = &qp->ibqp; ib_event.event = IB_EVENT_QP_REQ_ERR; if (qp->ibqp.event_handler) qp->ibqp.event_handler(&ib_event, qp->ibqp. qp_context); break; case CCAE_BAD_CLOSE: case CCAE_LLP_CLOSE_COMPLETE: case CCAE_LLP_CONNECTION_RESET: case CCAE_LLP_CONNECTION_LOST: BUG_ON(cm_id->event_handler==(void*)0x6b6b6b6b); spin_lock_irqsave(&qp->lock, flags); if (qp->cm_id) { qp->cm_id->rem_ref(qp->cm_id); qp->cm_id = NULL; } spin_unlock_irqrestore(&qp->lock, flags); cm_event.event = IW_CM_EVENT_CLOSE; cm_event.status = 0; if (cm_id->event_handler) cm_id->event_handler(cm_id, &cm_event); break; default: BUG_ON(1); pr_debug("%s:%d Unexpected event_id=%d on QP=%p, " "CM_ID=%p\n", __func__, __LINE__, event_id, qp, cm_id); break; } break; } case C2_RES_IND_EP:{ struct c2wr_ae_connection_request *req = &wr->ae.ae_connection_request; struct iw_cm_id *cm_id = (struct iw_cm_id *)resource_user_context; pr_debug("C2_RES_IND_EP event_id=%d\n", event_id); if (event_id != CCAE_CONNECTION_REQUEST) { pr_debug("%s: Invalid event_id: %d\n", __func__, event_id); break; } cm_event.event = IW_CM_EVENT_CONNECT_REQUEST; cm_event.provider_data = (void*)(unsigned long)req->cr_handle; cm_event.local_addr.sin_addr.s_addr = req->laddr; cm_event.remote_addr.sin_addr.s_addr = req->raddr; cm_event.local_addr.sin_port = req->lport; cm_event.remote_addr.sin_port = req->rport; cm_event.private_data_len = be32_to_cpu(req->private_data_length); cm_event.private_data = req->private_data; /* * Until ird/ord negotiation via MPAv2 support is added, send * max supported values */ cm_event.ird = cm_event.ord = 128; if (cm_id->event_handler) cm_id->event_handler(cm_id, &cm_event); break; } case C2_RES_IND_CQ:{ struct c2_cq *cq = (struct c2_cq *) resource_user_context; pr_debug("IB_EVENT_CQ_ERR\n"); ib_event.device = &c2dev->ibdev; ib_event.element.cq = &cq->ibcq; ib_event.event = IB_EVENT_CQ_ERR; if (cq->ibcq.event_handler) cq->ibcq.event_handler(&ib_event, cq->ibcq.cq_context); } default: printk("Bad resource indicator = %d\n", resource_indicator); break; } ignore_it: c2_mq_free(mq); }
static inline int c2_poll_one(struct c2_dev *c2dev, struct c2_cq *cq, struct ib_wc *entry) { struct c2wr_ce *ce; struct c2_qp *qp; int is_recv = 0; ce = c2_mq_consume(&cq->mq); if (!ce) { return -EAGAIN; } /* * if the qp returned is null then this qp has already * been freed and we are unable process the completion. * try pulling the next message */ while ((qp = (struct c2_qp *) (unsigned long) ce->qp_user_context) == NULL) { c2_mq_free(&cq->mq); ce = c2_mq_consume(&cq->mq); if (!ce) return -EAGAIN; } entry->status = c2_cqe_status_to_openib(c2_wr_get_result(ce)); entry->wr_id = ce->hdr.context; entry->qp = &qp->ibqp; entry->wc_flags = 0; entry->slid = 0; entry->sl = 0; entry->src_qp = 0; entry->dlid_path_bits = 0; entry->pkey_index = 0; switch (c2_wr_get_id(ce)) { case C2_WR_TYPE_SEND: entry->opcode = IB_WC_SEND; break; case C2_WR_TYPE_RDMA_WRITE: entry->opcode = IB_WC_RDMA_WRITE; break; case C2_WR_TYPE_RDMA_READ: entry->opcode = IB_WC_RDMA_READ; break; case C2_WR_TYPE_RECV: entry->byte_len = be32_to_cpu(ce->bytes_rcvd); entry->opcode = IB_WC_RECV; is_recv = 1; break; default: break; } /* consume the WQEs */ if (is_recv) c2_mq_lconsume(&qp->rq_mq, 1); else c2_mq_lconsume(&qp->sq_mq, be32_to_cpu(c2_wr_get_wqe_count(ce)) + 1); /* free the message */ c2_mq_free(&cq->mq); return 0; }
/* * Handles verbs WR replies. */ static void handle_vq(struct c2_dev *c2dev, u32 mq_index) { void *adapter_msg, *reply_msg; struct c2wr_hdr *host_msg; struct c2wr_hdr tmp; struct c2_mq *reply_vq; struct c2_vq_req *req; struct iw_cm_event cm_event; int err; reply_vq = c2dev->qptr_array[mq_index]; /* * get next msg from mq_index into adapter_msg. * don't free it yet. */ adapter_msg = c2_mq_consume(reply_vq); if (adapter_msg == NULL) { return; } host_msg = vq_repbuf_alloc(c2dev); /* * If we can't get a host buffer, then we'll still * wakeup the waiter, we just won't give him the msg. * It is assumed the waiter will deal with this... */ if (!host_msg) { pr_debug("handle_vq: no repbufs!\n"); /* * just copy the WR header into a local variable. * this allows us to still demux on the context */ host_msg = &tmp; memcpy(host_msg, adapter_msg, sizeof(tmp)); reply_msg = NULL; } else { memcpy(host_msg, adapter_msg, reply_vq->msg_size); reply_msg = host_msg; } /* * consume the msg from the MQ */ c2_mq_free(reply_vq); /* * wakeup the waiter. */ req = (struct c2_vq_req *) (unsigned long) host_msg->context; if (req == NULL) { /* * We should never get here, as the adapter should * never send us a reply that we're not expecting. */ if (reply_msg != NULL) vq_repbuf_free(c2dev, host_msg); pr_debug("handle_vq: UNEXPECTEDLY got NULL req\n"); return; } if (reply_msg) err = c2_errno(reply_msg); else err = -ENOMEM; if (!err) switch (req->event) { case IW_CM_EVENT_ESTABLISHED: c2_set_qp_state(req->qp, C2_QP_STATE_RTS); /* * Until ird/ord negotiation via MPAv2 support is added, send * max supported values */ cm_event.ird = cm_event.ord = 128; case IW_CM_EVENT_CLOSE: /* * Move the QP to RTS if this is * the established event */ cm_event.event = req->event; cm_event.status = 0; cm_event.local_addr = req->cm_id->local_addr; cm_event.remote_addr = req->cm_id->remote_addr; cm_event.private_data = NULL; cm_event.private_data_len = 0; req->cm_id->event_handler(req->cm_id, &cm_event); break; default: break; } req->reply_msg = (u64) (unsigned long) (reply_msg); atomic_set(&req->reply_ready, 1); wake_up(&req->wait_object); /* * If the request was cancelled, then this put will * free the vq_req memory...and reply_msg!!! */ vq_req_put(c2dev, req); }