Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <mlombard@redhat.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Keith Busch <kbusch@kernel.org>

authored by

Maurizio Lombardi and committed by
Keith Busch
84e00904 fcd87544

+45
+43
drivers/nvme/host/tcp.c
··· 763 763 return 0; 764 764 } 765 765 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 + 766 800 static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb, 767 801 unsigned int *offset, size_t *len) 768 802 { ··· 818 784 return 0; 819 785 820 786 hdr = queue->pdu; 787 + if (unlikely(hdr->type == nvme_tcp_c2h_term)) { 788 + /* 789 + * C2HTermReq never includes Header or Data digests. 790 + * Skip the checks. 791 + */ 792 + nvme_tcp_handle_c2h_term(queue, (void *)queue->pdu); 793 + return -EINVAL; 794 + } 795 + 821 796 if (queue->hdr_digest) { 822 797 ret = nvme_tcp_verify_hdgst(queue, queue->pdu, hdr->hlen); 823 798 if (unlikely(ret))
+2
include/linux/nvme-tcp.h
··· 13 13 #define NVME_TCP_ADMIN_CCSZ SZ_8K 14 14 #define NVME_TCP_DIGEST_LENGTH 4 15 15 #define NVME_TCP_MIN_MAXH2CDATA 4096 16 + #define NVME_TCP_MIN_C2HTERM_PLEN 24 17 + #define NVME_TCP_MAX_C2HTERM_PLEN 152 16 18 17 19 enum nvme_tcp_pfv { 18 20 NVME_TCP_PFV_1_0 = 0x0,