scsi: hisi_sas: change slot index allocation mode
authorXiang Chen <chenxiang66@hisilicon.com>
Mon, 21 May 2018 10:09:14 +0000 (18:09 +0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 29 May 2018 02:40:31 +0000 (22:40 -0400)
Currently we find the lowest available empty bit in the IPTT bitmap to
allocate the IPTT for a command.

To reduce possibility of hitting unknown SoC bugs and also aid in the
debugging of those same bugs, change the allocation mode.

The next allocation method is to use the next free slot adjacent to the
most recently allocated slot, in a round-robin fashion.

Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/hisi_sas/hisi_sas.h
drivers/scsi/hisi_sas/hisi_sas_main.c

index 52fc709dd862e6b80672fe13b1f3e50fef1cc2fa..3c8840089cd50e0fe10cf4d94944c0a9fbae953a 100644 (file)
@@ -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;
 
index 66388741e73c1d082224f60b0b3fd4f1df6b0a74..796fdfc73c758f299c228148ecdf941c86cc607e 100644 (file)
@@ -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;
 }