nvme/tcp: Add a helper function nvme_tcp_pdu_set_data

This function will be exteneded later for multiple SGL
support.

Change-Id: I1f6962ec03c72e335efaa311a12d3891312fcc53
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449968
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Ziye Yang 2019-04-03 17:29:33 +08:00 committed by Jim Harris
parent 5a1dc44423
commit 8f3b4a3a6d
3 changed files with 25 additions and 28 deletions

View File

@ -396,4 +396,11 @@ nvme_tcp_read_payload_data(struct spdk_sock *sock, struct nvme_tcp_pdu *pdu)
return nvme_tcp_readv_data(sock, iov, iovec_cnt); return nvme_tcp_readv_data(sock, iov, iovec_cnt);
} }
static void
nvme_tcp_pdu_set_data(struct nvme_tcp_pdu *pdu, void *data, uint32_t data_len)
{
pdu->data = data;
pdu->data_len = data_len;
}
#endif /* SPDK_INTERNAL_NVME_TCP_H */ #endif /* SPDK_INTERNAL_NVME_TCP_H */

View File

@ -594,9 +594,10 @@ nvme_tcp_qpair_cmd_send_complete(void *cb_arg)
static void static void
nvme_tcp_pdu_set_data_buf(struct nvme_tcp_pdu *pdu, nvme_tcp_pdu_set_data_buf(struct nvme_tcp_pdu *pdu,
struct nvme_tcp_req *tcp_req) struct nvme_tcp_req *tcp_req,
uint32_t data_len)
{ {
pdu->data = (void *)((uint64_t)tcp_req->buf + tcp_req->datao); nvme_tcp_pdu_set_data(pdu, (void *)((uint64_t)tcp_req->buf + tcp_req->datao), data_len);
} }
static int static int
@ -649,9 +650,7 @@ nvme_tcp_qpair_capsule_cmd_send(struct nvme_tcp_qpair *tqpair,
} }
tcp_req->datao = 0; tcp_req->datao = 0;
nvme_tcp_pdu_set_data_buf(pdu, tcp_req); nvme_tcp_pdu_set_data_buf(pdu, tcp_req, tcp_req->req->payload_size);
pdu->data_len = tcp_req->req->payload_size;
end: end:
capsule_cmd->common.plen = plen; capsule_cmd->common.plen = plen;
return nvme_tcp_qpair_write_pdu(tqpair, pdu, nvme_tcp_qpair_cmd_send_complete, NULL); return nvme_tcp_qpair_write_pdu(tqpair, pdu, nvme_tcp_qpair_cmd_send_complete, NULL);
@ -803,16 +802,14 @@ nvme_tcp_qpair_send_h2c_term_req(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_
DSET32(&h2c_term_req->fei, error_offset); DSET32(&h2c_term_req->fei, error_offset);
} }
rsp_pdu->data = (uint8_t *)rsp_pdu->hdr.raw + h2c_term_req_hdr_len;
copy_len = pdu->hdr.common.hlen; copy_len = pdu->hdr.common.hlen;
if (copy_len > SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE) { if (copy_len > SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE) {
copy_len = SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE; copy_len = SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE;
} }
/* Copy the error info into the buffer */ /* Copy the error info into the buffer */
memcpy((uint8_t *)rsp_pdu->data, pdu->hdr.raw, copy_len); memcpy((uint8_t *)rsp_pdu->hdr.raw + h2c_term_req_hdr_len, pdu->hdr.raw, copy_len);
rsp_pdu->data_len = copy_len; nvme_tcp_pdu_set_data(rsp_pdu, (uint8_t *)rsp_pdu->hdr.raw + h2c_term_req_hdr_len, copy_len);
/* Contain the header len of the wrong received pdu */ /* Contain the header len of the wrong received pdu */
h2c_term_req->common.plen = h2c_term_req->common.hlen + copy_len; h2c_term_req->common.plen = h2c_term_req->common.hlen + copy_len;
@ -1144,7 +1141,6 @@ nvme_tcp_c2h_term_req_hdr_handle(struct nvme_tcp_qpair *tqpair,
uint32_t error_offset = 0; uint32_t error_offset = 0;
enum spdk_nvme_tcp_term_req_fes fes; enum spdk_nvme_tcp_term_req_fes fes;
if (c2h_term_req->fes > SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER) { if (c2h_term_req->fes > SPDK_NVME_TCP_TERM_REQ_FES_INVALID_DATA_UNSUPPORTED_PARAMETER) {
SPDK_ERRLOG("Fatal Error Stauts(FES) is unknown for c2h_term_req pdu=%p\n", pdu); SPDK_ERRLOG("Fatal Error Stauts(FES) is unknown for c2h_term_req pdu=%p\n", pdu);
fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD; fes = SPDK_NVME_TCP_TERM_REQ_FES_INVALID_HEADER_FIELD;
@ -1153,8 +1149,8 @@ nvme_tcp_c2h_term_req_hdr_handle(struct nvme_tcp_qpair *tqpair,
} }
/* set the data buffer */ /* set the data buffer */
pdu->data = (uint8_t *)pdu->hdr.raw + c2h_term_req->common.hlen; nvme_tcp_pdu_set_data(pdu, (uint8_t *)pdu->hdr.raw + c2h_term_req->common.hlen,
pdu->data_len = c2h_term_req->common.plen - c2h_term_req->common.hlen; c2h_term_req->common.plen - c2h_term_req->common.hlen);
nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD); nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
return; return;
end: end:
@ -1209,8 +1205,7 @@ nvme_tcp_c2h_data_hdr_handle(struct nvme_tcp_qpair *tqpair, struct nvme_tcp_pdu
} }
nvme_tcp_pdu_set_data_buf(pdu, tcp_req); nvme_tcp_pdu_set_data_buf(pdu, tcp_req, c2h_data->datal);
pdu->data_len = c2h_data->datal;
pdu->ctx = tcp_req; pdu->ctx = tcp_req;
nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD); nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
@ -1243,7 +1238,6 @@ spdk_nvme_tcp_send_h2c_data(struct nvme_tcp_req *tcp_req)
rsp_pdu = &tcp_req->send_pdu; rsp_pdu = &tcp_req->send_pdu;
memset(rsp_pdu, 0, sizeof(*rsp_pdu)); memset(rsp_pdu, 0, sizeof(*rsp_pdu));
nvme_tcp_pdu_set_data_buf(rsp_pdu, tcp_req);
h2c_data = &rsp_pdu->hdr.h2c_data; h2c_data = &rsp_pdu->hdr.h2c_data;
h2c_data->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_H2C_DATA; h2c_data->common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_H2C_DATA;
@ -1253,7 +1247,7 @@ spdk_nvme_tcp_send_h2c_data(struct nvme_tcp_req *tcp_req)
h2c_data->datao = tcp_req->datao; h2c_data->datao = tcp_req->datao;
h2c_data->datal = spdk_min(tcp_req->r2tl_remain, tqpair->maxh2cdata); h2c_data->datal = spdk_min(tcp_req->r2tl_remain, tqpair->maxh2cdata);
rsp_pdu->data_len = h2c_data->datal; nvme_tcp_pdu_set_data_buf(rsp_pdu, tcp_req, h2c_data->datal);
tcp_req->r2tl_remain -= h2c_data->datal; tcp_req->r2tl_remain -= h2c_data->datal;
if (tqpair->host_hdgst_enable) { if (tqpair->host_hdgst_enable) {

View File

@ -1286,15 +1286,14 @@ spdk_nvmf_tcp_send_c2h_term_req(struct spdk_nvmf_tcp_qpair *tqpair, struct nvme_
DSET32(&c2h_term_req->fei, error_offset); DSET32(&c2h_term_req->fei, error_offset);
} }
rsp_pdu->data = (uint8_t *)rsp_pdu->hdr.raw + c2h_term_req_hdr_len;
copy_len = pdu->hdr.common.hlen; copy_len = pdu->hdr.common.hlen;
if (copy_len > SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE) { if (copy_len > SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE) {
copy_len = SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE; copy_len = SPDK_NVME_TCP_TERM_REQ_ERROR_DATA_MAX_SIZE;
} }
/* Copy the error info into the buffer */ /* Copy the error info into the buffer */
memcpy((uint8_t *)rsp_pdu->data, pdu->hdr.raw, copy_len); memcpy((uint8_t *)rsp_pdu->hdr.raw + c2h_term_req_hdr_len, pdu->hdr.raw, copy_len);
rsp_pdu->data_len = copy_len; nvme_tcp_pdu_set_data(rsp_pdu, (uint8_t *)rsp_pdu->hdr.raw + c2h_term_req_hdr_len, copy_len);
/* Contain the header of the wrong received pdu */ /* Contain the header of the wrong received pdu */
c2h_term_req->common.plen = c2h_term_req->common.hlen + copy_len; c2h_term_req->common.plen = c2h_term_req->common.hlen + copy_len;
@ -1417,10 +1416,9 @@ spdk_nvmf_tcp_h2c_data_hdr_handle(struct spdk_nvmf_tcp_transport *ttransport,
} }
pdu->ctx = tcp_req; pdu->ctx = tcp_req;
pdu->data_len = h2c_data->datal;
iov_index = pdu->hdr.h2c_data.datao / ttransport->transport.opts.io_unit_size; iov_index = pdu->hdr.h2c_data.datao / ttransport->transport.opts.io_unit_size;
pdu->data = tcp_req->req.iov[iov_index].iov_base + (pdu->hdr.h2c_data.datao % nvme_tcp_pdu_set_data(pdu, tcp_req->req.iov[iov_index].iov_base + (pdu->hdr.h2c_data.datao %
ttransport->transport.opts.io_unit_size); ttransport->transport.opts.io_unit_size), h2c_data->datal);
spdk_nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD); spdk_nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
return; return;
@ -1597,8 +1595,8 @@ spdk_nvmf_tcp_h2c_term_req_hdr_handle(struct spdk_nvmf_tcp_qpair *tqpair,
} }
/* set the data buffer */ /* set the data buffer */
pdu->data = (uint8_t *)pdu->hdr.raw + h2c_term_req->common.hlen; nvme_tcp_pdu_set_data(pdu, (uint8_t *)pdu->hdr.raw + h2c_term_req->common.hlen,
pdu->data_len = h2c_term_req->common.plen - h2c_term_req->common.hlen; h2c_term_req->common.plen - h2c_term_req->common.hlen);
spdk_nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD); spdk_nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
return; return;
end: end:
@ -2260,8 +2258,7 @@ spdk_nvmf_tcp_send_c2h_data(struct spdk_nvmf_tcp_qpair *tqpair,
c2h_data->common.plen = plen; c2h_data->common.plen = plen;
rsp_pdu->data = tcp_req->req.iov[iov_index].iov_base + offset; nvme_tcp_pdu_set_data(rsp_pdu, tcp_req->req.iov[iov_index].iov_base + offset, c2h_data->datal);
rsp_pdu->data_len = c2h_data->datal;
tcp_req->c2h_data_offset += c2h_data->datal; tcp_req->c2h_data_offset += c2h_data->datal;
if (iov_index == (tcp_req->req.iovcnt - 1) && (tcp_req->c2h_data_offset == tcp_req->req.length)) { if (iov_index == (tcp_req->req.iovcnt - 1) && (tcp_req->c2h_data_offset == tcp_req->req.length)) {
@ -2366,8 +2363,7 @@ spdk_nvmf_tcp_pdu_set_buf_from_req(struct spdk_nvmf_tcp_qpair *tqpair,
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "Not need to send r2t for tcp_req(%p) on tqpair=%p\n", tcp_req, SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "Not need to send r2t for tcp_req(%p) on tqpair=%p\n", tcp_req,
tqpair); tqpair);
/* No need to send r2t, contained in the capsuled data */ /* No need to send r2t, contained in the capsuled data */
pdu->data = tcp_req->req.data; nvme_tcp_pdu_set_data(pdu, tcp_req->req.data, tcp_req->req.length);
pdu->data_len = tcp_req->req.length;
spdk_nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD); spdk_nvmf_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
spdk_nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER); spdk_nvmf_tcp_req_set_state(tcp_req, TCP_REQUEST_STATE_TRANSFERRING_HOST_TO_CONTROLLER);
} }