Skip to content

Commit 84e0090

Browse files
maurizio-lombardikeithbusch
authored andcommitted
nvme-tcp: add basic support for the C2HTermReq PDU
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 <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent fcd8754 commit 84e0090

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
@@ -763,6 +763,40 @@ static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue,
763763
return 0;
764764
}
765765

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

786820
hdr = queue->pdu;
821+
if (unlikely(hdr->type == nvme_tcp_c2h_term)) {
822+
/*
823+
* C2HTermReq never includes Header or Data digests.
824+
* Skip the checks.
825+
*/
826+
nvme_tcp_handle_c2h_term(queue, (void *)queue->pdu);
827+
return -EINVAL;
828+
}
829+
787830
if (queue->hdr_digest) {
788831
ret = nvme_tcp_verify_hdgst(queue, queue->pdu, hdr->hlen);
789832
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)