]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
scsi: lpfc: Use the crc32c() function
authorEric Biggers <ebiggers@kernel.org>
Mon, 16 Mar 2026 22:36:31 +0000 (15:36 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 20 Mar 2026 01:46:49 +0000 (21:46 -0400)
lpfc_cgn_calc_crc32(data, size, crc) is really just an open-coded version
of ~crc32c(bitrev32(crc), data, size).  However, all callers pass crc ==
~0, so it can be simplified even further to just ~crc32c(~0, data, size).
Remove the crc argument and implement it that way.

While we're at it, also use proper types in the function prototype.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Link: https://patch.msgid.link/20260316223631.72361-1-ebiggers@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/Kconfig
drivers/scsi/lpfc/lpfc.h
drivers/scsi/lpfc/lpfc_crtn.h
drivers/scsi/lpfc/lpfc_els.c
drivers/scsi/lpfc/lpfc_init.c

index 19d0884479a247f1e91300bcfc1112e7b3ea5e46..f811ce473c2aba98d7cae6a3f596b20fa4a42841 100644 (file)
@@ -1151,6 +1151,7 @@ config SCSI_LPFC
        depends on NVME_TARGET_FC || NVME_TARGET_FC=n
        depends on NVME_FC || NVME_FC=n
        select CRC_T10DIF
+       select CRC32
        select IRQ_POLL
        help
           This lpfc driver supports the Emulex LightPulse
index 240ae6216c7c3e0492539d761fdbb0068575fb55..49ed55db1e4756e451744dac2729e9161868bdd0 100644 (file)
@@ -552,8 +552,6 @@ struct lpfc_cgn_info {
        );
 
        __le32   cgn_info_crc;
-#define LPFC_CGN_CRC32_MAGIC_NUMBER    0x1EDC6F41
-#define LPFC_CGN_CRC32_SEED            0xFFFFFFFF
 };
 
 #define LPFC_CGN_INFO_SZ       (sizeof(struct lpfc_cgn_info) -  \
index ddd6485f31be3d85a9f8e2ce4f7ae9e324950483..8a5b76bdea0612cdee9a2252b960971565ff86f0 100644 (file)
@@ -86,7 +86,7 @@ void lpfc_cmf_stop(struct lpfc_hba *phba);
 void lpfc_init_congestion_stat(struct lpfc_hba *phba);
 void lpfc_init_congestion_buf(struct lpfc_hba *phba);
 int lpfc_sli4_cgn_params_read(struct lpfc_hba *phba);
-uint32_t lpfc_cgn_calc_crc32(void *bufp, uint32_t sz, uint32_t seed);
+uint32_t lpfc_cgn_calc_crc32(const void *data, size_t size);
 int lpfc_config_cgn_signal(struct lpfc_hba *phba);
 int lpfc_issue_cmf_sync_wqe(struct lpfc_hba *phba, u32 ms, u64 total);
 void lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba);
index 10b3e6027a57a24d2e6eb64a1cf85cdba6923bd1..d70a4039a345cd3bed7944a26adf2297f82ad03c 100644 (file)
@@ -10301,10 +10301,8 @@ cleanup:
                                                cpu_to_le16(value);
                                        cp->cgn_warn_freq =
                                                cpu_to_le16(value);
-                                       crc = lpfc_cgn_calc_crc32
-                                               (cp,
-                                               LPFC_CGN_INFO_SZ,
-                                               LPFC_CGN_CRC32_SEED);
+                                       crc = lpfc_cgn_calc_crc32(
+                                               cp, LPFC_CGN_INFO_SZ);
                                        cp->cgn_info_crc = cpu_to_le32(crc);
                                }
 
index 704c59cc8892211ef099fb055245c2da8c073831..3bf522c7f099198ac1cd5cd1eda8dea61a67cd84 100644 (file)
@@ -22,6 +22,7 @@
  *******************************************************************/
 
 #include <linux/blkdev.h>
+#include <linux/crc32.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/idr.h>
@@ -5634,8 +5635,7 @@ lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag)
                cp->cgn_stat_npm = value;
        }
 
-       value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
-                                   LPFC_CGN_CRC32_SEED);
+       value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ);
        cp->cgn_info_crc = cpu_to_le32(value);
 }
 
@@ -5897,8 +5897,7 @@ lpfc_cmf_stats_timer(struct hrtimer *timer)
        cp->cgn_warn_freq = cpu_to_le16(value);
        cp->cgn_alarm_freq = cpu_to_le16(value);
 
-       lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
-                                    LPFC_CGN_CRC32_SEED);
+       lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ);
        cp->cgn_info_crc = cpu_to_le32(lvalue);
 
        hrtimer_forward_now(timer, ktime_set(0, LPFC_SEC_MIN * NSEC_PER_SEC));
@@ -7121,8 +7120,7 @@ lpfc_cgn_params_parse(struct lpfc_hba *phba,
                        cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0;
                        cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1;
                        cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2;
-                       crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ,
-                                                 LPFC_CGN_CRC32_SEED);
+                       crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ);
                        cp->cgn_info_crc = cpu_to_le32(crc);
                }
                spin_unlock_irq(&phba->hbalock);
@@ -13493,54 +13491,14 @@ lpfc_sli4_hba_unset(struct lpfc_hba *phba)
                phba->pport->work_port_events = 0;
 }
 
-static uint32_t
-lpfc_cgn_crc32(uint32_t crc, u8 byte)
-{
-       uint32_t msb = 0;
-       uint32_t bit;
-
-       for (bit = 0; bit < 8; bit++) {
-               msb = (crc >> 31) & 1;
-               crc <<= 1;
-
-               if (msb ^ (byte & 1)) {
-                       crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER;
-                       crc |= 1;
-               }
-               byte >>= 1;
-       }
-       return crc;
-}
-
-static uint32_t
-lpfc_cgn_reverse_bits(uint32_t wd)
-{
-       uint32_t result = 0;
-       uint32_t i;
-
-       for (i = 0; i < 32; i++) {
-               result <<= 1;
-               result |= (1 & (wd >> i));
-       }
-       return result;
-}
-
 /*
  * The routine corresponds with the algorithm the HBA firmware
  * uses to validate the data integrity.
  */
 uint32_t
-lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc)
+lpfc_cgn_calc_crc32(const void *data, size_t size)
 {
-       uint32_t  i;
-       uint32_t result;
-       uint8_t  *data = (uint8_t *)ptr;
-
-       for (i = 0; i < byteLen; ++i)
-               crc = lpfc_cgn_crc32(crc, data[i]);
-
-       result = ~lpfc_cgn_reverse_bits(crc);
-       return result;
+       return ~crc32c(~0, data, size);
 }
 
 void
@@ -13589,7 +13547,7 @@ lpfc_init_congestion_buf(struct lpfc_hba *phba)
 
        cp->cgn_warn_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
        cp->cgn_alarm_freq = cpu_to_le16(LPFC_FPIN_INIT_FREQ);
-       crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
+       crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ);
        cp->cgn_info_crc = cpu_to_le32(crc);
 
        phba->cgn_evt_timestamp = jiffies +
@@ -13612,7 +13570,7 @@ lpfc_init_congestion_stat(struct lpfc_hba *phba)
        memset(&cp->cgn_stat, 0, sizeof(cp->cgn_stat));
 
        lpfc_cgn_update_tstamp(phba, &cp->stat_start);
-       crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED);
+       crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ);
        cp->cgn_info_crc = cpu_to_le32(crc);
 }