Commit bcc60c38 authored by Or Gerlitz's avatar Or Gerlitz Committed by Roland Dreier

IB/iser: New receive buffer posting logic

Currently, the recv buffer posting logic is based on the transactional
nature of iSER which allows for posting a buffer before sending a PDU.
Change this to post only when the number of outstanding recv buffers
is below a water mark and in a batched manner, thus simplifying and
optimizing the data path.  Use a pre-allocated ring of recv buffers
instead of allocating from kmem cache.  A special treatment is given
to the login response buffer whose size must be 8K unlike the size of
buffers used for any other purpose which is 128 bytes.
Signed-off-by: default avatarOr Gerlitz <ogerlitz@voltaire.com>
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent 1cef4659
...@@ -283,7 +283,7 @@ iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx) ...@@ -283,7 +283,7 @@ iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
* due to issues with the login code re iser sematics * due to issues with the login code re iser sematics
* this not set in iscsi_conn_setup - FIXME * this not set in iscsi_conn_setup - FIXME
*/ */
conn->max_recv_dlength = 128; conn->max_recv_dlength = ISER_RECV_DATA_SEG_LEN;
iser_conn = conn->dd_data; iser_conn = conn->dd_data;
conn->dd_data = iser_conn; conn->dd_data = iser_conn;
......
...@@ -102,9 +102,9 @@ ...@@ -102,9 +102,9 @@
#define ISER_MAX_TX_MISC_PDUS 6 /* NOOP_OUT(2), TEXT(1), * #define ISER_MAX_TX_MISC_PDUS 6 /* NOOP_OUT(2), TEXT(1), *
* SCSI_TMFUNC(2), LOGOUT(1) */ * SCSI_TMFUNC(2), LOGOUT(1) */
#define ISER_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX + \ #define ISER_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX)
ISER_MAX_RX_MISC_PDUS + \
ISER_MAX_TX_MISC_PDUS) #define ISER_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
/* the max TX (send) WR supported by the iSER QP is defined by * /* the max TX (send) WR supported by the iSER QP is defined by *
* max_send_wr = T * (1 + D) + C ; D is how many inflight dataouts we expect * * max_send_wr = T * (1 + D) + C ; D is how many inflight dataouts we expect *
...@@ -132,6 +132,12 @@ struct iser_hdr { ...@@ -132,6 +132,12 @@ struct iser_hdr {
__be64 read_va; __be64 read_va;
} __attribute__((packed)); } __attribute__((packed));
/* Constant PDU lengths calculations */
#define ISER_HEADERS_LEN (sizeof(struct iser_hdr) + sizeof(struct iscsi_hdr))
#define ISER_RECV_DATA_SEG_LEN 128
#define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN)
#define ISER_RX_LOGIN_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
/* Length of an object name string */ /* Length of an object name string */
#define ISER_OBJECT_NAME_SIZE 64 #define ISER_OBJECT_NAME_SIZE 64
...@@ -212,7 +218,6 @@ struct iser_dto { ...@@ -212,7 +218,6 @@ struct iser_dto {
}; };
enum iser_desc_type { enum iser_desc_type {
ISCSI_RX,
ISCSI_TX_CONTROL , ISCSI_TX_CONTROL ,
ISCSI_TX_SCSI_COMMAND, ISCSI_TX_SCSI_COMMAND,
ISCSI_TX_DATAOUT ISCSI_TX_DATAOUT
...@@ -228,6 +233,17 @@ struct iser_desc { ...@@ -228,6 +233,17 @@ struct iser_desc {
struct iser_dto dto; struct iser_dto dto;
}; };
#define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \
sizeof(u64) + sizeof(struct ib_sge)))
struct iser_rx_desc {
struct iser_hdr iser_header;
struct iscsi_hdr iscsi_header;
char data[ISER_RECV_DATA_SEG_LEN];
u64 dma_addr;
struct ib_sge rx_sg;
char pad[ISER_RX_PAD_SIZE];
} __attribute__((packed));
struct iser_device { struct iser_device {
struct ib_device *ib_device; struct ib_device *ib_device;
struct ib_pd *pd; struct ib_pd *pd;
...@@ -256,6 +272,12 @@ struct iser_conn { ...@@ -256,6 +272,12 @@ struct iser_conn {
struct iser_page_vec *page_vec; /* represents SG to fmr maps* struct iser_page_vec *page_vec; /* represents SG to fmr maps*
* maps serialized as tx is*/ * maps serialized as tx is*/
struct list_head conn_list; /* entry in ig conn list */ struct list_head conn_list; /* entry in ig conn list */
char *login_buf;
u64 login_dma;
unsigned int rx_desc_head;
struct iser_rx_desc *rx_descs;
struct ib_recv_wr rx_wr[ISER_MIN_POSTED_RX];
}; };
struct iscsi_iser_conn { struct iscsi_iser_conn {
...@@ -319,8 +341,9 @@ void iser_conn_put(struct iser_conn *ib_conn); ...@@ -319,8 +341,9 @@ void iser_conn_put(struct iser_conn *ib_conn);
void iser_conn_terminate(struct iser_conn *ib_conn); void iser_conn_terminate(struct iser_conn *ib_conn);
void iser_rcv_completion(struct iser_desc *desc, void iser_rcv_completion(struct iser_rx_desc *desc,
unsigned long dto_xfer_len); unsigned long dto_xfer_len,
struct iser_conn *ib_conn);
void iser_snd_completion(struct iser_desc *desc); void iser_snd_completion(struct iser_desc *desc);
...@@ -332,6 +355,8 @@ void iser_dto_buffs_release(struct iser_dto *dto); ...@@ -332,6 +355,8 @@ void iser_dto_buffs_release(struct iser_dto *dto);
int iser_regd_buff_release(struct iser_regd_buf *regd_buf); int iser_regd_buff_release(struct iser_regd_buf *regd_buf);
void iser_free_rx_descriptors(struct iser_conn *ib_conn);
void iser_reg_single(struct iser_device *device, void iser_reg_single(struct iser_device *device,
struct iser_regd_buf *regd_buf, struct iser_regd_buf *regd_buf,
enum dma_data_direction direction); enum dma_data_direction direction);
...@@ -353,7 +378,8 @@ int iser_reg_page_vec(struct iser_conn *ib_conn, ...@@ -353,7 +378,8 @@ int iser_reg_page_vec(struct iser_conn *ib_conn,
void iser_unreg_mem(struct iser_mem_reg *mem_reg); void iser_unreg_mem(struct iser_mem_reg *mem_reg);
int iser_post_recv(struct iser_desc *rx_desc); int iser_post_recvl(struct iser_conn *ib_conn);
int iser_post_recvm(struct iser_conn *ib_conn, int count);
int iser_post_send(struct iser_desc *tx_desc); int iser_post_send(struct iser_desc *tx_desc);
int iser_conn_state_comp(struct iser_conn *ib_conn, int iser_conn_state_comp(struct iser_conn *ib_conn,
......
...@@ -129,13 +129,23 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn) ...@@ -129,13 +129,23 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
{ {
struct iser_device *device; struct iser_device *device;
struct ib_qp_init_attr init_attr; struct ib_qp_init_attr init_attr;
int ret; int ret = -ENOMEM;
struct ib_fmr_pool_param params; struct ib_fmr_pool_param params;
BUG_ON(ib_conn->device == NULL); BUG_ON(ib_conn->device == NULL);
device = ib_conn->device; device = ib_conn->device;
ib_conn->login_buf = kmalloc(ISER_RX_LOGIN_SIZE, GFP_KERNEL);
if (!ib_conn->login_buf) {
goto alloc_err;
ret = -ENOMEM;
}
ib_conn->login_dma = ib_dma_map_single(ib_conn->device->ib_device,
(void *)ib_conn->login_buf, ISER_RX_LOGIN_SIZE,
DMA_FROM_DEVICE);
ib_conn->page_vec = kmalloc(sizeof(struct iser_page_vec) + ib_conn->page_vec = kmalloc(sizeof(struct iser_page_vec) +
(sizeof(u64) * (ISCSI_ISER_SG_TABLESIZE +1)), (sizeof(u64) * (ISCSI_ISER_SG_TABLESIZE +1)),
GFP_KERNEL); GFP_KERNEL);
...@@ -174,7 +184,7 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn) ...@@ -174,7 +184,7 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
init_attr.cap.max_send_wr = ISER_QP_MAX_REQ_DTOS; init_attr.cap.max_send_wr = ISER_QP_MAX_REQ_DTOS;
init_attr.cap.max_recv_wr = ISER_QP_MAX_RECV_DTOS; init_attr.cap.max_recv_wr = ISER_QP_MAX_RECV_DTOS;
init_attr.cap.max_send_sge = MAX_REGD_BUF_VECTOR_LEN; init_attr.cap.max_send_sge = MAX_REGD_BUF_VECTOR_LEN;
init_attr.cap.max_recv_sge = 2; init_attr.cap.max_recv_sge = 1;
init_attr.sq_sig_type = IB_SIGNAL_REQ_WR; init_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
init_attr.qp_type = IB_QPT_RC; init_attr.qp_type = IB_QPT_RC;
...@@ -192,6 +202,7 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn) ...@@ -192,6 +202,7 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
(void)ib_destroy_fmr_pool(ib_conn->fmr_pool); (void)ib_destroy_fmr_pool(ib_conn->fmr_pool);
fmr_pool_err: fmr_pool_err:
kfree(ib_conn->page_vec); kfree(ib_conn->page_vec);
kfree(ib_conn->login_buf);
alloc_err: alloc_err:
iser_err("unable to alloc mem or create resource, err %d\n", ret); iser_err("unable to alloc mem or create resource, err %d\n", ret);
return ret; return ret;
...@@ -314,7 +325,7 @@ static void iser_conn_release(struct iser_conn *ib_conn) ...@@ -314,7 +325,7 @@ static void iser_conn_release(struct iser_conn *ib_conn)
mutex_lock(&ig.connlist_mutex); mutex_lock(&ig.connlist_mutex);
list_del(&ib_conn->conn_list); list_del(&ib_conn->conn_list);
mutex_unlock(&ig.connlist_mutex); mutex_unlock(&ig.connlist_mutex);
iser_free_rx_descriptors(ib_conn);
iser_free_ib_conn_res(ib_conn); iser_free_ib_conn_res(ib_conn);
ib_conn->device = NULL; ib_conn->device = NULL;
/* on EVENT_ADDR_ERROR there's no device yet for this conn */ /* on EVENT_ADDR_ERROR there's no device yet for this conn */
...@@ -625,6 +636,60 @@ void iser_unreg_mem(struct iser_mem_reg *reg) ...@@ -625,6 +636,60 @@ void iser_unreg_mem(struct iser_mem_reg *reg)
reg->mem_h = NULL; reg->mem_h = NULL;
} }
int iser_post_recvl(struct iser_conn *ib_conn)
{
struct ib_recv_wr rx_wr, *rx_wr_failed;
struct ib_sge sge;
int ib_ret;
sge.addr = ib_conn->login_dma;
sge.length = ISER_RX_LOGIN_SIZE;
sge.lkey = ib_conn->device->mr->lkey;
rx_wr.wr_id = (unsigned long)ib_conn->login_buf;
rx_wr.sg_list = &sge;
rx_wr.num_sge = 1;
rx_wr.next = NULL;
atomic_inc(&ib_conn->post_recv_buf_count);
ib_ret = ib_post_recv(ib_conn->qp, &rx_wr, &rx_wr_failed);
if (ib_ret) {
iser_err("ib_post_recv failed ret=%d\n", ib_ret);
atomic_dec(&ib_conn->post_recv_buf_count);
}
return ib_ret;
}
int iser_post_recvm(struct iser_conn *ib_conn, int count)
{
struct ib_recv_wr *rx_wr, *rx_wr_failed;
int i, ib_ret;
unsigned int my_rx_head = ib_conn->rx_desc_head;
struct iser_rx_desc *rx_desc;
for (rx_wr = ib_conn->rx_wr, i = 0; i < count; i++, rx_wr++) {
rx_desc = &ib_conn->rx_descs[my_rx_head];
rx_wr->wr_id = (unsigned long)rx_desc;
rx_wr->sg_list = &rx_desc->rx_sg;
rx_wr->num_sge = 1;
rx_wr->next = rx_wr + 1;
my_rx_head = (my_rx_head + 1) & (ISER_QP_MAX_RECV_DTOS - 1);
}
rx_wr--;
rx_wr->next = NULL; /* mark end of work requests list */
atomic_add(count, &ib_conn->post_recv_buf_count);
ib_ret = ib_post_recv(ib_conn->qp, ib_conn->rx_wr, &rx_wr_failed);
if (ib_ret) {
iser_err("ib_post_recv failed ret=%d\n", ib_ret);
atomic_sub(count, &ib_conn->post_recv_buf_count);
} else
ib_conn->rx_desc_head = my_rx_head;
return ib_ret;
}
/** /**
* iser_dto_to_iov - builds IOV from a dto descriptor * iser_dto_to_iov - builds IOV from a dto descriptor
*/ */
...@@ -665,39 +730,6 @@ static void iser_dto_to_iov(struct iser_dto *dto, struct ib_sge *iov, int iov_le ...@@ -665,39 +730,6 @@ static void iser_dto_to_iov(struct iser_dto *dto, struct ib_sge *iov, int iov_le
} }
} }
/**
* iser_post_recv - Posts a receive buffer.
*
* returns 0 on success, -1 on failure
*/
int iser_post_recv(struct iser_desc *rx_desc)
{
int ib_ret, ret_val = 0;
struct ib_recv_wr recv_wr, *recv_wr_failed;
struct ib_sge iov[2];
struct iser_conn *ib_conn;
struct iser_dto *recv_dto = &rx_desc->dto;
/* Retrieve conn */
ib_conn = recv_dto->ib_conn;
iser_dto_to_iov(recv_dto, iov, 2);
recv_wr.next = NULL;
recv_wr.sg_list = iov;
recv_wr.num_sge = recv_dto->regd_vector_len;
recv_wr.wr_id = (unsigned long)rx_desc;
atomic_inc(&ib_conn->post_recv_buf_count);
ib_ret = ib_post_recv(ib_conn->qp, &recv_wr, &recv_wr_failed);
if (ib_ret) {
iser_err("ib_post_recv failed ret=%d\n", ib_ret);
atomic_dec(&ib_conn->post_recv_buf_count);
ret_val = -1;
}
return ret_val;
}
/** /**
* iser_start_send - Initiate a Send DTO operation * iser_start_send - Initiate a Send DTO operation
...@@ -737,18 +769,17 @@ int iser_post_send(struct iser_desc *tx_desc) ...@@ -737,18 +769,17 @@ int iser_post_send(struct iser_desc *tx_desc)
return ret_val; return ret_val;
} }
static void iser_handle_comp_error(struct iser_desc *desc) static void iser_handle_comp_error(struct iser_desc *desc,
struct iser_conn *ib_conn)
{ {
struct iser_dto *dto = &desc->dto; struct iser_rx_desc *rx = (struct iser_rx_desc *)desc;
struct iser_conn *ib_conn = dto->ib_conn; struct iser_rx_desc *rx_first = ib_conn->rx_descs;
struct iser_rx_desc *rx_last = rx_first + (ISER_QP_MAX_RECV_DTOS - 1);
iser_dto_buffs_release(dto);
if (desc->type == ISCSI_RX) { if ((char *)desc == ib_conn->login_buf ||
kfree(desc->data); (rx_first <= rx && rx <= rx_last))
kmem_cache_free(ig.desc_cache, desc);
atomic_dec(&ib_conn->post_recv_buf_count); atomic_dec(&ib_conn->post_recv_buf_count);
} else { /* type is TX control/command/dataout */ else { /* type is TX control/command/dataout */
if (desc->type == ISCSI_TX_DATAOUT) if (desc->type == ISCSI_TX_DATAOUT)
kmem_cache_free(ig.desc_cache, desc); kmem_cache_free(ig.desc_cache, desc);
atomic_dec(&ib_conn->post_send_buf_count); atomic_dec(&ib_conn->post_send_buf_count);
...@@ -780,20 +811,25 @@ static void iser_cq_tasklet_fn(unsigned long data) ...@@ -780,20 +811,25 @@ static void iser_cq_tasklet_fn(unsigned long data)
struct ib_wc wc; struct ib_wc wc;
struct iser_desc *desc; struct iser_desc *desc;
unsigned long xfer_len; unsigned long xfer_len;
struct iser_conn *ib_conn;
while (ib_poll_cq(cq, 1, &wc) == 1) { while (ib_poll_cq(cq, 1, &wc) == 1) {
desc = (struct iser_desc *) (unsigned long) wc.wr_id; desc = (struct iser_desc *) (unsigned long) wc.wr_id;
BUG_ON(desc == NULL); BUG_ON(desc == NULL);
ib_conn = wc.qp->qp_context;
if (wc.status == IB_WC_SUCCESS) { if (wc.status == IB_WC_SUCCESS) {
if (desc->type == ISCSI_RX) { if (wc.opcode == IB_WC_RECV) {
xfer_len = (unsigned long)wc.byte_len; xfer_len = (unsigned long)wc.byte_len;
iser_rcv_completion(desc, xfer_len); iser_rcv_completion((struct iser_rx_desc *)desc,
xfer_len, ib_conn);
} else /* type == ISCSI_TX_CONTROL/SCSI_CMD/DOUT */ } else /* type == ISCSI_TX_CONTROL/SCSI_CMD/DOUT */
iser_snd_completion(desc); iser_snd_completion(desc);
} else { } else {
iser_err("comp w. error op %d status %d\n",desc->type,wc.status); if (wc.status != IB_WC_WR_FLUSH_ERR)
iser_handle_comp_error(desc); iser_err("id %llx status %d vend_err %x\n",
wc.wr_id, wc.status, wc.vendor_err);
iser_handle_comp_error(desc, ib_conn);
} }
} }
/* #warning "it is assumed here that arming CQ only once its empty" * /* #warning "it is assumed here that arming CQ only once its empty" *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment