tcp: refactor of header/data digest support check
Some functions performed incorrect header/data digest support check, align it with NVMEoF spec. Use a table to check if PDU supports digest depending on its type. Change-Id: I6170dd19ace017f37fda0a923f604732799460b9 Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/483375 Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Community-CI: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
48f38636ce
commit
9727aa281f
@ -169,6 +169,30 @@ enum nvme_tcp_qpair_state {
|
|||||||
NVME_TCP_QPAIR_STATE_EXITED = 4,
|
NVME_TCP_QPAIR_STATE_EXITED = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const bool g_nvme_tcp_hdgst[] = {
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_IC_REQ] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_IC_RESP] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD] = true,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_CAPSULE_RESP] = true,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_H2C_DATA] = true,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_C2H_DATA] = true,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_R2T] = true
|
||||||
|
};
|
||||||
|
|
||||||
|
static const bool g_nvme_tcp_ddgst[] = {
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_IC_REQ] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_IC_RESP] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD] = true,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_CAPSULE_RESP] = false,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_H2C_DATA] = true,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_C2H_DATA] = true,
|
||||||
|
[SPDK_NVME_TCP_PDU_TYPE_R2T] = false
|
||||||
|
};
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
nvme_tcp_pdu_calc_header_digest(struct nvme_tcp_pdu *pdu)
|
nvme_tcp_pdu_calc_header_digest(struct nvme_tcp_pdu *pdu)
|
||||||
{
|
{
|
||||||
@ -342,7 +366,6 @@ static int
|
|||||||
nvme_tcp_build_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu *pdu,
|
nvme_tcp_build_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu *pdu,
|
||||||
bool hdgst_enable, bool ddgst_enable, uint32_t *_mapped_length)
|
bool hdgst_enable, bool ddgst_enable, uint32_t *_mapped_length)
|
||||||
{
|
{
|
||||||
int enable_digest;
|
|
||||||
uint32_t hlen, plen;
|
uint32_t hlen, plen;
|
||||||
struct _nvme_tcp_sgl *sgl;
|
struct _nvme_tcp_sgl *sgl;
|
||||||
|
|
||||||
@ -353,17 +376,9 @@ nvme_tcp_build_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu *pdu,
|
|||||||
sgl = &pdu->sgl;
|
sgl = &pdu->sgl;
|
||||||
_nvme_tcp_sgl_init(sgl, iov, iovcnt, 0);
|
_nvme_tcp_sgl_init(sgl, iov, iovcnt, 0);
|
||||||
hlen = pdu->hdr->common.hlen;
|
hlen = pdu->hdr->common.hlen;
|
||||||
enable_digest = 1;
|
|
||||||
if (pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_REQ ||
|
|
||||||
pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_RESP ||
|
|
||||||
pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ ||
|
|
||||||
pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ) {
|
|
||||||
/* this PDU should be sent without digest */
|
|
||||||
enable_digest = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Header Digest */
|
/* Header Digest */
|
||||||
if (enable_digest && hdgst_enable) {
|
if (g_nvme_tcp_hdgst[pdu->hdr->common.pdu_type] && hdgst_enable) {
|
||||||
hlen += SPDK_NVME_TCP_DIGEST_LEN;
|
hlen += SPDK_NVME_TCP_DIGEST_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +413,7 @@ nvme_tcp_build_iovs(struct iovec *iov, int iovcnt, struct nvme_tcp_pdu *pdu,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Data Digest */
|
/* Data Digest */
|
||||||
if (enable_digest && ddgst_enable) {
|
if (g_nvme_tcp_ddgst[pdu->hdr->common.pdu_type] && ddgst_enable) {
|
||||||
plen += SPDK_NVME_TCP_DIGEST_LEN;
|
plen += SPDK_NVME_TCP_DIGEST_LEN;
|
||||||
_nvme_tcp_sgl_append(sgl, pdu->data_digest, SPDK_NVME_TCP_DIGEST_LEN);
|
_nvme_tcp_sgl_append(sgl, pdu->data_digest, SPDK_NVME_TCP_DIGEST_LEN);
|
||||||
}
|
}
|
||||||
@ -604,12 +619,8 @@ nvme_tcp_pdu_calc_psh_len(struct nvme_tcp_pdu *pdu, bool hdgst_enable)
|
|||||||
uint8_t psh_len, pdo, padding_len;
|
uint8_t psh_len, pdo, padding_len;
|
||||||
|
|
||||||
psh_len = pdu->hdr->common.hlen;
|
psh_len = pdu->hdr->common.hlen;
|
||||||
/* Only the following five type has header digest */
|
|
||||||
if (((pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD) ||
|
if (g_nvme_tcp_hdgst[pdu->hdr->common.pdu_type] && hdgst_enable) {
|
||||||
(pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_H2C_DATA) ||
|
|
||||||
(pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_CAPSULE_RESP) ||
|
|
||||||
(pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_C2H_DATA) ||
|
|
||||||
(pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_R2T)) && hdgst_enable) {
|
|
||||||
pdu->has_hdgst = true;
|
pdu->has_hdgst = true;
|
||||||
psh_len += SPDK_NVME_TCP_DIGEST_LEN;
|
psh_len += SPDK_NVME_TCP_DIGEST_LEN;
|
||||||
if (pdu->hdr->common.plen > psh_len) {
|
if (pdu->hdr->common.plen > psh_len) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*-
|
/*-
|
||||||
* BSD LICENSE
|
* BSD LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (c) Intel Corporation.
|
* Copyright (c) Intel Corporation. All rights reserved.
|
||||||
* All rights reserved.
|
* Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -318,27 +318,20 @@ nvme_tcp_qpair_write_pdu(struct nvme_tcp_qpair *tqpair,
|
|||||||
nvme_tcp_qpair_xfer_complete_cb cb_fn,
|
nvme_tcp_qpair_xfer_complete_cb cb_fn,
|
||||||
void *cb_arg)
|
void *cb_arg)
|
||||||
{
|
{
|
||||||
int enable_digest;
|
|
||||||
int hlen;
|
int hlen;
|
||||||
uint32_t crc32c;
|
uint32_t crc32c;
|
||||||
uint32_t mapped_length = 0;
|
uint32_t mapped_length = 0;
|
||||||
|
|
||||||
hlen = pdu->hdr->common.hlen;
|
hlen = pdu->hdr->common.hlen;
|
||||||
enable_digest = 1;
|
|
||||||
if (pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_REQ ||
|
|
||||||
pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_H2C_TERM_REQ) {
|
|
||||||
/* this PDU should be sent without digest */
|
|
||||||
enable_digest = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Header Digest */
|
/* Header Digest */
|
||||||
if (enable_digest && tqpair->host_hdgst_enable) {
|
if (g_nvme_tcp_hdgst[pdu->hdr->common.pdu_type] && tqpair->host_hdgst_enable) {
|
||||||
crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
|
crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
|
||||||
MAKE_DIGEST_WORD((uint8_t *)pdu->hdr->raw + hlen, crc32c);
|
MAKE_DIGEST_WORD((uint8_t *)pdu->hdr->raw + hlen, crc32c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data Digest */
|
/* Data Digest */
|
||||||
if (pdu->data_len > 0 && enable_digest && tqpair->host_ddgst_enable) {
|
if (pdu->data_len > 0 && g_nvme_tcp_ddgst[pdu->hdr->common.pdu_type] && tqpair->host_ddgst_enable) {
|
||||||
crc32c = nvme_tcp_pdu_calc_data_digest(pdu);
|
crc32c = nvme_tcp_pdu_calc_data_digest(pdu);
|
||||||
MAKE_DIGEST_WORD(pdu->data_digest, crc32c);
|
MAKE_DIGEST_WORD(pdu->data_digest, crc32c);
|
||||||
}
|
}
|
||||||
@ -1318,7 +1311,6 @@ nvme_tcp_read_pdu(struct nvme_tcp_qpair *tqpair, uint32_t *reaped)
|
|||||||
tqpair->host_ddgst_enable)) {
|
tqpair->host_ddgst_enable)) {
|
||||||
data_len += SPDK_NVME_TCP_DIGEST_LEN;
|
data_len += SPDK_NVME_TCP_DIGEST_LEN;
|
||||||
pdu->ddgst_enable = true;
|
pdu->ddgst_enable = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = nvme_tcp_read_payload_data(tqpair->sock, pdu);
|
rc = nvme_tcp_read_payload_data(tqpair->sock, pdu);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* BSD LICENSE
|
* BSD LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (c) Intel Corporation. All rights reserved.
|
* Copyright (c) Intel Corporation. All rights reserved.
|
||||||
* Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
|
* Copyright (c) 2019, 2020 Mellanox Technologies LTD. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -753,7 +753,6 @@ spdk_nvmf_tcp_qpair_write_pdu(struct spdk_nvmf_tcp_qpair *tqpair,
|
|||||||
nvme_tcp_qpair_xfer_complete_cb cb_fn,
|
nvme_tcp_qpair_xfer_complete_cb cb_fn,
|
||||||
void *cb_arg)
|
void *cb_arg)
|
||||||
{
|
{
|
||||||
int enable_digest;
|
|
||||||
int hlen;
|
int hlen;
|
||||||
uint32_t crc32c;
|
uint32_t crc32c;
|
||||||
uint32_t mapped_length = 0;
|
uint32_t mapped_length = 0;
|
||||||
@ -762,21 +761,15 @@ spdk_nvmf_tcp_qpair_write_pdu(struct spdk_nvmf_tcp_qpair *tqpair,
|
|||||||
assert(&tqpair->pdu_in_progress != pdu);
|
assert(&tqpair->pdu_in_progress != pdu);
|
||||||
|
|
||||||
hlen = pdu->hdr->common.hlen;
|
hlen = pdu->hdr->common.hlen;
|
||||||
enable_digest = 1;
|
|
||||||
if (pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_IC_RESP ||
|
|
||||||
pdu->hdr->common.pdu_type == SPDK_NVME_TCP_PDU_TYPE_C2H_TERM_REQ) {
|
|
||||||
/* this PDU should be sent without digest */
|
|
||||||
enable_digest = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Header Digest */
|
/* Header Digest */
|
||||||
if (enable_digest && tqpair->host_hdgst_enable) {
|
if (g_nvme_tcp_hdgst[pdu->hdr->common.pdu_type] && tqpair->host_hdgst_enable) {
|
||||||
crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
|
crc32c = nvme_tcp_pdu_calc_header_digest(pdu);
|
||||||
MAKE_DIGEST_WORD((uint8_t *)pdu->hdr->raw + hlen, crc32c);
|
MAKE_DIGEST_WORD((uint8_t *)pdu->hdr->raw + hlen, crc32c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data Digest */
|
/* Data Digest */
|
||||||
if (pdu->data_len > 0 && enable_digest && tqpair->host_ddgst_enable) {
|
if (pdu->data_len > 0 && g_nvme_tcp_ddgst[pdu->hdr->common.pdu_type] && tqpair->host_ddgst_enable) {
|
||||||
crc32c = nvme_tcp_pdu_calc_data_digest(pdu);
|
crc32c = nvme_tcp_pdu_calc_data_digest(pdu);
|
||||||
MAKE_DIGEST_WORD(pdu->data_digest, crc32c);
|
MAKE_DIGEST_WORD(pdu->data_digest, crc32c);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user