]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/irdma: Switch to using the crc32c library
authorEric Biggers <ebiggers@google.com>
Fri, 7 Feb 2025 04:08:16 +0000 (20:08 -0800)
committerLeon Romanovsky <leon@kernel.org>
Fri, 14 Feb 2025 06:56:45 +0000 (01:56 -0500)
Now that the crc32c() library function directly takes advantage of
architecture-specific optimizations, it is unnecessary to go through the
crypto API.  Just use crc32c().  This is much simpler, and it improves
performance due to eliminating the crypto API overhead.

Note that for crc32c the equivalent of crypto_shash_digest() is
cpu_to_le32(~crc32c(~0, ...)), considering that crypto_shash_digest()
had before and inversions as well as a cpu_to_le32() built-in.  This
means that this driver is using u32 for fixed-endian types; this patch
does not try to fix that but rather just keep the exact same behavior.

Link: https://lore.kernel.org/r/20250207033643.59904-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Link: https://patch.msgid.link/20250207040816.69163-1-ebiggers@kernel.org
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/irdma/Kconfig
drivers/infiniband/hw/irdma/main.h
drivers/infiniband/hw/irdma/osdep.h
drivers/infiniband/hw/irdma/puda.c
drivers/infiniband/hw/irdma/puda.h
drivers/infiniband/hw/irdma/utils.c

index b6f9c41bca51db1dcc83162fa0db8a269a1d8bf9..5f49a58590ed7a6609c731b9fb93311578bcead5 100644 (file)
@@ -7,6 +7,7 @@ config INFINIBAND_IRDMA
        depends on ICE && I40E
        select GENERIC_ALLOCATOR
        select AUXILIARY_BUS
+       select CRC32
        help
          This is an Intel(R) Ethernet Protocol Driver for RDMA driver
          that support E810 (iWARP/RoCE) and X722 (iWARP) network devices.
index 9f0ed6e844711105cd7b013f6ac92e9ac28698d5..0705ef3d72a938078c7532cb7d904bb4602fa96e 100644 (file)
@@ -30,7 +30,6 @@
 #endif
 #include <linux/auxiliary_bus.h>
 #include <linux/net/intel/iidc.h>
-#include <crypto/hash.h>
 #include <rdma/ib_smi.h>
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_pack.h>
index ddf02a462efa2c0f4fd480a846992882e9b6dbf9..4b4f78288d12e09bb7c1af7e4d6555341ed51d17 100644 (file)
@@ -6,7 +6,6 @@
 #include <linux/pci.h>
 #include <linux/bitfield.h>
 #include <linux/net/intel/iidc.h>
-#include <crypto/hash.h>
 #include <rdma/ib_verbs.h>
 
 #define STATS_TIMER_DELAY      60000
@@ -43,15 +42,12 @@ enum irdma_status_code irdma_vf_wait_vchnl_resp(struct irdma_sc_dev *dev);
 bool irdma_vf_clear_to_send(struct irdma_sc_dev *dev);
 void irdma_add_dev_ref(struct irdma_sc_dev *dev);
 void irdma_put_dev_ref(struct irdma_sc_dev *dev);
-int irdma_ieq_check_mpacrc(struct shash_desc *desc, void *addr, u32 len,
-                          u32 val);
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val);
 struct irdma_sc_qp *irdma_ieq_get_qp(struct irdma_sc_dev *dev,
                                     struct irdma_puda_buf *buf);
 void irdma_send_ieq_ack(struct irdma_sc_qp *qp);
 void irdma_ieq_update_tcpip_info(struct irdma_puda_buf *buf, u16 len,
                                 u32 seqnum);
-void irdma_free_hash_desc(struct shash_desc *hash_desc);
-int irdma_init_hash_desc(struct shash_desc **hash_desc);
 int irdma_puda_get_tcpip_info(struct irdma_puda_cmpl_info *info,
                              struct irdma_puda_buf *buf);
 int irdma_cqp_sds_cmd(struct irdma_sc_dev *dev,
index 7e3f9bca2c235edb3d2edc91838988f74971f963..694e5a9ed15d0fa633827ec2ae56a96328e1b5da 100644 (file)
@@ -923,8 +923,6 @@ void irdma_puda_dele_rsrc(struct irdma_sc_vsi *vsi, enum puda_rsrc_type type,
 
        switch (rsrc->cmpl) {
        case PUDA_HASH_CRC_COMPLETE:
-               irdma_free_hash_desc(rsrc->hash_desc);
-               fallthrough;
        case PUDA_QP_CREATED:
                irdma_qp_rem_qos(&rsrc->qp);
 
@@ -1095,15 +1093,12 @@ int irdma_puda_create_rsrc(struct irdma_sc_vsi *vsi,
                goto error;
 
        if (info->type == IRDMA_PUDA_RSRC_TYPE_IEQ) {
-               if (!irdma_init_hash_desc(&rsrc->hash_desc)) {
-                       rsrc->check_crc = true;
-                       rsrc->cmpl = PUDA_HASH_CRC_COMPLETE;
-                       ret = 0;
-               }
+               rsrc->check_crc = true;
+               rsrc->cmpl = PUDA_HASH_CRC_COMPLETE;
        }
 
        irdma_sc_ccq_arm(&rsrc->cq);
-       return ret;
+       return 0;
 
 error:
        irdma_puda_dele_rsrc(vsi, info->type, false);
@@ -1396,8 +1391,8 @@ static int irdma_ieq_handle_partial(struct irdma_puda_rsrc *ieq,
        crcptr = txbuf->data + fpdu_len - 4;
        mpacrc = *(u32 *)crcptr;
        if (ieq->check_crc) {
-               status = irdma_ieq_check_mpacrc(ieq->hash_desc, txbuf->data,
-                                               (fpdu_len - 4), mpacrc);
+               status = irdma_ieq_check_mpacrc(txbuf->data, fpdu_len - 4,
+                                               mpacrc);
                if (status) {
                        ibdev_dbg(to_ibdev(ieq->dev), "IEQ: error bad crc\n");
                        goto error;
@@ -1465,8 +1460,8 @@ static int irdma_ieq_process_buf(struct irdma_puda_rsrc *ieq,
                crcptr = datap + fpdu_len - 4;
                mpacrc = *(u32 *)crcptr;
                if (ieq->check_crc)
-                       ret = irdma_ieq_check_mpacrc(ieq->hash_desc, datap,
-                                                    fpdu_len - 4, mpacrc);
+                       ret = irdma_ieq_check_mpacrc(datap, fpdu_len - 4,
+                                                    mpacrc);
                if (ret) {
                        list_add(&buf->list, rxlist);
                        ibdev_dbg(to_ibdev(ieq->dev),
index bc6d9514c9c103376776146bc9291b7db2d87521..2fc638f2b14343ed1ebff4e10b32c95d5d502d9a 100644 (file)
@@ -119,7 +119,6 @@ struct irdma_puda_rsrc {
        u32 rx_wqe_idx;
        u32 rxq_invalid_cnt;
        u32 tx_wqe_avail_cnt;
-       struct shash_desc *hash_desc;
        struct list_head txpend;
        struct list_head bufpool; /* free buffers pool list for recv and xmit */
        u32 alloc_buf_count;
@@ -163,10 +162,8 @@ struct irdma_sc_qp *irdma_ieq_get_qp(struct irdma_sc_dev *dev,
                                     struct irdma_puda_buf *buf);
 int irdma_puda_get_tcpip_info(struct irdma_puda_cmpl_info *info,
                              struct irdma_puda_buf *buf);
-int irdma_ieq_check_mpacrc(struct shash_desc *desc, void *addr, u32 len, u32 val);
-int irdma_init_hash_desc(struct shash_desc **desc);
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val);
 void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
-void irdma_free_hash_desc(struct shash_desc *desc);
 void irdma_ieq_update_tcpip_info(struct irdma_puda_buf *buf, u16 len, u32 seqnum);
 int irdma_cqp_qp_create_cmd(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
 int irdma_cqp_cq_create_cmd(struct irdma_sc_dev *dev, struct irdma_sc_cq *cq);
index 0e594122baa786710507d7755370aa92e2b28b88..e73b14fd95ef1fe0a86fc2a02ef6dc893b2a7899 100644 (file)
@@ -1273,58 +1273,15 @@ void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp)
        irdma_gen_ae(rf, qp, &info, false);
 }
 
-/**
- * irdma_init_hash_desc - initialize hash for crc calculation
- * @desc: cryption type
- */
-int irdma_init_hash_desc(struct shash_desc **desc)
-{
-       struct crypto_shash *tfm;
-       struct shash_desc *tdesc;
-
-       tfm = crypto_alloc_shash("crc32c", 0, 0);
-       if (IS_ERR(tfm))
-               return -EINVAL;
-
-       tdesc = kzalloc(sizeof(*tdesc) + crypto_shash_descsize(tfm),
-                       GFP_KERNEL);
-       if (!tdesc) {
-               crypto_free_shash(tfm);
-               return -EINVAL;
-       }
-
-       tdesc->tfm = tfm;
-       *desc = tdesc;
-
-       return 0;
-}
-
-/**
- * irdma_free_hash_desc - free hash desc
- * @desc: to be freed
- */
-void irdma_free_hash_desc(struct shash_desc *desc)
-{
-       if (desc) {
-               crypto_free_shash(desc->tfm);
-               kfree(desc);
-       }
-}
-
 /**
  * irdma_ieq_check_mpacrc - check if mpa crc is OK
- * @desc: desc for hash
  * @addr: address of buffer for crc
  * @len: length of buffer
  * @val: value to be compared
  */
-int irdma_ieq_check_mpacrc(struct shash_desc *desc, void *addr, u32 len,
-                          u32 val)
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val)
 {
-       u32 crc = 0;
-
-       crypto_shash_digest(desc, addr, len, (u8 *)&crc);
-       if (crc != val)
+       if ((__force u32)cpu_to_le32(~crc32c(~0, addr, len)) != val)
                return -EINVAL;
 
        return 0;