Skip to content

Commit 4501ea5

Browse files
ipylypivmartinkpetersen
authored andcommitted
scsi: pm8001: Initialize devices in pm8001_alloc_dev()
Devices can be allocated and freed at runtime. For example during a soft reset all devices are freed and reallocated upon discovery. Currently the driver fully initializes devices once in pm8001_alloc(). Allows initialization steps to happen during runtime, avoiding any leftover states from the device being freed. Signed-off-by: Igor Pylypiv <ipylypiv@google.com> Signed-off-by: Terrence Adams <tadamsjr@google.com> Link: https://lore.kernel.org/r/20241021201828.1378858-1-tadamsjr@google.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent c8d81a4 commit 4501ea5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

drivers/scsi/pm8001/pm8001_init.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,6 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
451451
}
452452
for (i = 0; i < PM8001_MAX_DEVICES; i++) {
453453
pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
454-
pm8001_ha->devices[i].id = i;
455-
pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
456-
atomic_set(&pm8001_ha->devices[i].running_req, 0);
457454
}
458455
pm8001_ha->flags = PM8001F_INIT_TIME;
459456
return 0;

drivers/scsi/pm8001/pm8001_sas.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,13 @@ void pm8001_ccb_task_free(struct pm8001_hba_info *pm8001_ha,
572572
pm8001_ccb_free(pm8001_ha, ccb);
573573
}
574574

575+
static void pm8001_init_dev(struct pm8001_device *pm8001_dev, int id)
576+
{
577+
pm8001_dev->id = id;
578+
pm8001_dev->device_id = PM8001_MAX_DEVICES;
579+
atomic_set(&pm8001_dev->running_req, 0);
580+
}
581+
575582
/**
576583
* pm8001_alloc_dev - find a empty pm8001_device
577584
* @pm8001_ha: our hba card information
@@ -580,9 +587,11 @@ static struct pm8001_device *pm8001_alloc_dev(struct pm8001_hba_info *pm8001_ha)
580587
{
581588
u32 dev;
582589
for (dev = 0; dev < PM8001_MAX_DEVICES; dev++) {
583-
if (pm8001_ha->devices[dev].dev_type == SAS_PHY_UNUSED) {
584-
pm8001_ha->devices[dev].id = dev;
585-
return &pm8001_ha->devices[dev];
590+
struct pm8001_device *pm8001_dev = &pm8001_ha->devices[dev];
591+
592+
if (pm8001_dev->dev_type == SAS_PHY_UNUSED) {
593+
pm8001_init_dev(pm8001_dev, dev);
594+
return pm8001_dev;
586595
}
587596
}
588597
if (dev == PM8001_MAX_DEVICES) {
@@ -613,9 +622,7 @@ struct pm8001_device *pm8001_find_dev(struct pm8001_hba_info *pm8001_ha,
613622

614623
void pm8001_free_dev(struct pm8001_device *pm8001_dev)
615624
{
616-
u32 id = pm8001_dev->id;
617625
memset(pm8001_dev, 0, sizeof(*pm8001_dev));
618-
pm8001_dev->id = id;
619626
pm8001_dev->dev_type = SAS_PHY_UNUSED;
620627
pm8001_dev->device_id = PM8001_MAX_DEVICES;
621628
pm8001_dev->sas_device = NULL;

0 commit comments

Comments
 (0)