RDMA/rxe: Move ICRC checking to a subroutine
authorBob Pearson <rpearsonhpe@gmail.com>
Wed, 7 Jul 2021 04:00:33 +0000 (23:00 -0500)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 16 Jul 2021 15:43:33 +0000 (12:43 -0300)
Move the code in rxe_recv() that checks the ICRC on incoming packets to a
subroutine rxe_check_icrc() and move that to rxe_icrc.c.

Link: https://lore.kernel.org/r/20210707040040.15434-2-rpearsonhpe@gmail.com
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
Reviewed-by: Zhu Yanjun <zyjzyj2000@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/sw/rxe/rxe_icrc.c
drivers/infiniband/sw/rxe/rxe_loc.h
drivers/infiniband/sw/rxe/rxe_recv.c

index 66b2aad54bb7d1fa572969bfd0fc4810ff18dcf3..d067841214be72bf73b0de568d446372de4751a1 100644 (file)
@@ -67,3 +67,41 @@ u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
                        rxe_opcode[pkt->opcode].length - RXE_BTH_BYTES);
        return crc;
 }
+
+/**
+ * rxe_icrc_check() - Compute ICRC for a packet and compare to the ICRC
+ *                   delivered in the packet.
+ * @skb: packet buffer
+ * @pkt: packet info
+ *
+ * Return: 0 if the values match else an error
+ */
+int rxe_icrc_check(struct sk_buff *skb, struct rxe_pkt_info *pkt)
+{
+       __be32 *icrcp;
+       u32 pkt_icrc;
+       u32 icrc;
+
+       icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
+       pkt_icrc = be32_to_cpu(*icrcp);
+
+       icrc = rxe_icrc_hdr(pkt, skb);
+       icrc = rxe_crc32(pkt->rxe, icrc, (u8 *)payload_addr(pkt),
+                               payload_size(pkt) + bth_pad(pkt));
+       icrc = (__force u32)cpu_to_be32(~icrc);
+
+       if (unlikely(icrc != pkt_icrc)) {
+               if (skb->protocol == htons(ETH_P_IPV6))
+                       pr_warn_ratelimited("bad ICRC from %pI6c\n",
+                                           &ipv6_hdr(skb)->saddr);
+               else if (skb->protocol == htons(ETH_P_IP))
+                       pr_warn_ratelimited("bad ICRC from %pI4\n",
+                                           &ip_hdr(skb)->saddr);
+               else
+                       pr_warn_ratelimited("bad ICRC from unknown\n");
+
+               return -EINVAL;
+       }
+
+       return 0;
+}
index 1ddb20855dee7621d4cd56f137b3413b24a4a8f0..015777e31ec9f141911dcf3b91de24798a571224 100644 (file)
@@ -193,7 +193,9 @@ int rxe_completer(void *arg);
 int rxe_requester(void *arg);
 int rxe_responder(void *arg);
 
+/* rxe_icrc.c */
 u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb);
+int rxe_icrc_check(struct sk_buff *skb, struct rxe_pkt_info *pkt);
 
 void rxe_resp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb);
 
index 7a49e27da23a9ad202bce3f35d05aa7ca703c52a..6a6cc1fa90e4b1c04e1794ee975f7c2e9839b35d 100644 (file)
@@ -361,8 +361,6 @@ void rxe_rcv(struct sk_buff *skb)
        int err;
        struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
        struct rxe_dev *rxe = pkt->rxe;
-       __be32 *icrcp;
-       u32 calc_icrc, pack_icrc;
 
        if (unlikely(skb->len < RXE_BTH_BYTES))
                goto drop;
@@ -384,26 +382,9 @@ void rxe_rcv(struct sk_buff *skb)
        if (unlikely(err))
                goto drop;
 
-       /* Verify ICRC */
-       icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
-       pack_icrc = be32_to_cpu(*icrcp);
-
-       calc_icrc = rxe_icrc_hdr(pkt, skb);
-       calc_icrc = rxe_crc32(rxe, calc_icrc, (u8 *)payload_addr(pkt),
-                             payload_size(pkt) + bth_pad(pkt));
-       calc_icrc = (__force u32)cpu_to_be32(~calc_icrc);
-       if (unlikely(calc_icrc != pack_icrc)) {
-               if (skb->protocol == htons(ETH_P_IPV6))
-                       pr_warn_ratelimited("bad ICRC from %pI6c\n",
-                                           &ipv6_hdr(skb)->saddr);
-               else if (skb->protocol == htons(ETH_P_IP))
-                       pr_warn_ratelimited("bad ICRC from %pI4\n",
-                                           &ip_hdr(skb)->saddr);
-               else
-                       pr_warn_ratelimited("bad ICRC from unknown\n");
-
+       err = rxe_icrc_check(skb, pkt);
+       if (unlikely(err))
                goto drop;
-       }
 
        rxe_counter_inc(rxe, RXE_CNT_RCVD_PKTS);