static int isert_alloc_for_rdma(struct isert_cmnd *pdu, int sge_cnt, struct isert_connection *isert_conn) { struct isert_wr *wr; struct ib_sge *sg_pool; int i, ret = 0; int wr_cnt; sg_pool = kmalloc(sizeof(*sg_pool) * sge_cnt, GFP_KERNEL); if (unlikely(sg_pool == NULL)) { ret = -ENOMEM; goto out; } wr_cnt = DIV_ROUND_UP(sge_cnt, isert_conn->max_sge); wr = kmalloc(sizeof(*wr) * wr_cnt, GFP_KERNEL); if (unlikely(wr == NULL)) { ret = -ENOMEM; goto out_free_sg_pool; } kfree(pdu->wr); pdu->wr = wr; kfree(pdu->sg_pool); pdu->sg_pool = sg_pool; pdu->n_wr = wr_cnt; pdu->n_sge = sge_cnt; for (i = 0; i < wr_cnt; ++i) isert_wr_set_fields(&pdu->wr[i], isert_conn, pdu); for (i = 0; i < sge_cnt; ++i) pdu->sg_pool[i].lkey = isert_conn->isert_dev->mr->lkey; goto out; out_free_sg_pool: kfree(sg_pool); out: return ret; }
void isert_post_drain(struct isert_connection *isert_conn) { if (!test_and_set_bit(ISERT_DRAIN_POSTED, &isert_conn->flags)) { struct ib_send_wr *bad_wr; int err; isert_wr_set_fields(&isert_conn->drain_wr, isert_conn, NULL); isert_conn->drain_wr.wr_op = ISER_WR_SEND; isert_conn->drain_wr.send_wr.wr_id = _ptr_to_u64(&isert_conn->drain_wr); isert_conn->drain_wr.send_wr.opcode = IB_WR_SEND; err = ib_post_send(isert_conn->qp, &isert_conn->drain_wr.send_wr, &bad_wr); if (unlikely(err)) { pr_err("Failed to post drain wr, err:%d\n", err); /* We need to decrement iser_conn->kref in order to be able to cleanup * the connection */ set_bit(ISERT_DRAIN_FAILED, &isert_conn->flags); isert_conn_free(isert_conn); } } }