diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index 52fc709dd862..3c8840089cd5 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -274,6 +274,7 @@ struct hisi_hba { struct workqueue_struct *wq; int slot_index_count; + int last_slot_index; unsigned long *slot_index_tags; unsigned long reject_stp_links_msk; diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 66388741e73c..796fdfc73c75 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -195,11 +195,18 @@ static int hisi_sas_slot_index_alloc(struct hisi_hba *hisi_hba, int *slot_idx) unsigned int index; void *bitmap = hisi_hba->slot_index_tags; - index = find_first_zero_bit(bitmap, hisi_hba->slot_index_count); - if (index >= hisi_hba->slot_index_count) - return -SAS_QUEUE_FULL; + index = find_next_zero_bit(bitmap, hisi_hba->slot_index_count, + hisi_hba->last_slot_index + 1); + if (index >= hisi_hba->slot_index_count) { + index = find_next_zero_bit(bitmap, hisi_hba->slot_index_count, + 0); + if (index >= hisi_hba->slot_index_count) + return -SAS_QUEUE_FULL; + } hisi_sas_slot_index_set(hisi_hba, index); *slot_idx = index; + hisi_hba->last_slot_index = index; + return 0; }