summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@kernel.org>2026-03-17 01:36:31 +0300
committerMartin K. Petersen <martin.petersen@oracle.com>2026-03-20 04:46:49 +0300
commit48b2de8505437805116a3dc51d5afa09308c6659 (patch)
tree6835833a5133ab8c647b9f32a99169da654157d8
parent98eff361647ecba893aadce8808729672604a102 (diff)
downloadlinux-48b2de8505437805116a3dc51d5afa09308c6659.tar.xz
scsi: lpfc: Use the crc32c() function
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>
-rw-r--r--drivers/scsi/Kconfig1
-rw-r--r--drivers/scsi/lpfc/lpfc.h2
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h2
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c6
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c58
5 files changed, 12 insertions, 57 deletions
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 19d0884479a2..f811ce473c2a 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -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
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index 240ae6216c7c..49ed55db1e47 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -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) - \
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index ddd6485f31be..8a5b76bdea06 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -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);
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 10b3e6027a57..d70a4039a345 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -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);
}
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 704c59cc8892..3bf522c7f099 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -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);
}