Skip to content

Commit be9742c

Browse files
nvme-tcp: add basic support for the C2HTermReq PDU
JIRA: https://issues.redhat.com/browse/RHEL-72531 Previously, the NVMe/TCP host driver did not handle the C2HTermReq PDU, instead printing "unsupported pdu type (3)" when received. This patch adds support for processing the C2HTermReq PDU, allowing the driver to print the Fatal Error Status field. Example of output: nvme nvme4: Received C2HTermReq (FES = Invalid PDU Header Field) Signed-off-by: Maurizio Lombardi <mlombard@redhat.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Keith Busch <kbusch@kernel.org> (cherry picked from commit 84e0090) Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
1 parent f035a3d commit be9742c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

drivers/nvme/host/tcp.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,40 @@ static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue,
760760
return 0;
761761
}
762762

763+
static void nvme_tcp_handle_c2h_term(struct nvme_tcp_queue *queue,
764+
struct nvme_tcp_term_pdu *pdu)
765+
{
766+
u16 fes;
767+
const char *msg;
768+
u32 plen = le32_to_cpu(pdu->hdr.plen);
769+
770+
static const char * const msg_table[] = {
771+
[NVME_TCP_FES_INVALID_PDU_HDR] = "Invalid PDU Header Field",
772+
[NVME_TCP_FES_PDU_SEQ_ERR] = "PDU Sequence Error",
773+
[NVME_TCP_FES_HDR_DIGEST_ERR] = "Header Digest Error",
774+
[NVME_TCP_FES_DATA_OUT_OF_RANGE] = "Data Transfer Out Of Range",
775+
[NVME_TCP_FES_R2T_LIMIT_EXCEEDED] = "R2T Limit Exceeded",
776+
[NVME_TCP_FES_UNSUPPORTED_PARAM] = "Unsupported Parameter",
777+
};
778+
779+
if (plen < NVME_TCP_MIN_C2HTERM_PLEN ||
780+
plen > NVME_TCP_MAX_C2HTERM_PLEN) {
781+
dev_err(queue->ctrl->ctrl.device,
782+
"Received a malformed C2HTermReq PDU (plen = %u)\n",
783+
plen);
784+
return;
785+
}
786+
787+
fes = le16_to_cpu(pdu->fes);
788+
if (fes && fes < ARRAY_SIZE(msg_table))
789+
msg = msg_table[fes];
790+
else
791+
msg = "Unknown";
792+
793+
dev_err(queue->ctrl->ctrl.device,
794+
"Received C2HTermReq (FES = %s)\n", msg);
795+
}
796+
763797
static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb,
764798
unsigned int *offset, size_t *len)
765799
{
@@ -781,6 +815,15 @@ static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb,
781815
return 0;
782816

783817
hdr = queue->pdu;
818+
if (unlikely(hdr->type == nvme_tcp_c2h_term)) {
819+
/*
820+
* C2HTermReq never includes Header or Data digests.
821+
* Skip the checks.
822+
*/
823+
nvme_tcp_handle_c2h_term(queue, (void *)queue->pdu);
824+
return -EINVAL;
825+
}
826+
784827
if (queue->hdr_digest) {
785828
ret = nvme_tcp_verify_hdgst(queue, queue->pdu, hdr->hlen);
786829
if (unlikely(ret))

include/linux/nvme-tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define NVME_TCP_ADMIN_CCSZ SZ_8K
1414
#define NVME_TCP_DIGEST_LENGTH 4
1515
#define NVME_TCP_MIN_MAXH2CDATA 4096
16+
#define NVME_TCP_MIN_C2HTERM_PLEN 24
17+
#define NVME_TCP_MAX_C2HTERM_PLEN 152
1618

1719
enum nvme_tcp_pfv {
1820
NVME_TCP_PFV_1_0 = 0x0,

0 commit comments

Comments
 (0)