2024-03-08 11:44:25

by John Garry

[permalink] [raw]
Subject: [PATCH v2 1/6] scsi: libsas: Add LIBSAS_SHT_BASE

There is much duplication in the scsi_host_template structure for the
drivers which use libsas.

Similar to how a standard template is used in libata with __ATA_BASE_SHT,
create a standard template in LIBSAS_SHT_BASE.

Don't set a default for max_sectors at SCSI_DEFAULT_MAX_SECTORS, as
scsi_host_alloc() will default to this value automatically.

Even though some drivers don't set proc_name, it won't make much difference
to set as DRV_NAME.

Also add LIBSAS_SHT_BASE_NO_SLAVE_INIT for the hisi_sas drivers which have
custom .slave_alloc and .slave_configure methods.

Reviewed-by: Jason Yan <[email protected]>
Signed-off-by: John Garry <[email protected]>
---
include/scsi/libsas.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)

diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index f5257103fdb6..de842602f47e 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -726,4 +726,33 @@ void sas_notify_port_event(struct asd_sas_phy *phy, enum port_event event,
void sas_notify_phy_event(struct asd_sas_phy *phy, enum phy_event event,
gfp_t gfp_flags);

+#define __LIBSAS_SHT_BASE \
+ .module = THIS_MODULE, \
+ .name = DRV_NAME, \
+ .proc_name = DRV_NAME, \
+ .queuecommand = sas_queuecommand, \
+ .dma_need_drain = ata_scsi_dma_need_drain, \
+ .target_alloc = sas_target_alloc, \
+ .change_queue_depth = sas_change_queue_depth, \
+ .bios_param = sas_bios_param, \
+ .this_id = -1, \
+ .eh_device_reset_handler = sas_eh_device_reset_handler, \
+ .eh_target_reset_handler = sas_eh_target_reset_handler, \
+ .target_destroy = sas_target_destroy, \
+ .ioctl = sas_ioctl, \
+
+#ifdef CONFIG_COMPAT
+#define _LIBSAS_SHT_BASE __LIBSAS_SHT_BASE \
+ .compat_ioctl = sas_ioctl,
+#else
+#define _LIBSAS_SHT_BASE __LIBSAS_SHT_BASE
+#endif
+
+#define LIBSAS_SHT_BASE _LIBSAS_SHT_BASE \
+ .slave_configure = sas_slave_configure, \
+ .slave_alloc = sas_slave_alloc, \
+
+#define LIBSAS_SHT_BASE_NO_SLAVE_INIT _LIBSAS_SHT_BASE
+
+
#endif /* _SASLIB_H_ */
--
2.31.1



2024-03-08 19:41:54

by Igor Pylypiv

[permalink] [raw]
Subject: Re: [PATCH v2 1/6] scsi: libsas: Add LIBSAS_SHT_BASE

On Fri, Mar 08, 2024 at 11:43:34AM +0000, John Garry wrote:
> There is much duplication in the scsi_host_template structure for the
> drivers which use libsas.
>
> Similar to how a standard template is used in libata with __ATA_BASE_SHT,
> create a standard template in LIBSAS_SHT_BASE.
>
> Don't set a default for max_sectors at SCSI_DEFAULT_MAX_SECTORS, as
> scsi_host_alloc() will default to this value automatically.
>
> Even though some drivers don't set proc_name, it won't make much difference
> to set as DRV_NAME.
>
> Also add LIBSAS_SHT_BASE_NO_SLAVE_INIT for the hisi_sas drivers which have
> custom .slave_alloc and .slave_configure methods.

Looks like libata drivers have no problem overriding default values that were
set by __ATA_BASE_SHT. For example __ATA_BASE_SHT sets .can_queue .sdev_attrs
and then AHCI_SHT overrides those with AHCI specific values:

#define AHCI_SHT(drv_name) \
ATA_NCQ_SHT(drv_name), \
.can_queue = AHCI_MAX_CMDS, \
.sg_tablesize = AHCI_MAX_SG, \
.dma_boundary = AHCI_DMA_BOUNDARY, \
.shost_attrs = ahci_shost_attrs, \
.sdev_attrs = ahci_sdev_attrs

Perhaps there is no need for LIBSAS_SHT_BASE_NO_SLAVE_INIT since hisi_sas
can use LIBSAS_SHT_BASE with .slave_alloc and .slave_configure overrides?

Similarly hisi_sas and pm8001 can override the default ".sg_tablesize = SG_ALL".

Thanks,
Igor

>
> Reviewed-by: Jason Yan <[email protected]>
> Signed-off-by: John Garry <[email protected]>
> ---
> include/scsi/libsas.h | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
> index f5257103fdb6..de842602f47e 100644
> --- a/include/scsi/libsas.h
> +++ b/include/scsi/libsas.h
> @@ -726,4 +726,33 @@ void sas_notify_port_event(struct asd_sas_phy *phy, enum port_event event,
> void sas_notify_phy_event(struct asd_sas_phy *phy, enum phy_event event,
> gfp_t gfp_flags);
>
> +#define __LIBSAS_SHT_BASE \
> + .module = THIS_MODULE, \
> + .name = DRV_NAME, \
> + .proc_name = DRV_NAME, \
> + .queuecommand = sas_queuecommand, \
> + .dma_need_drain = ata_scsi_dma_need_drain, \
> + .target_alloc = sas_target_alloc, \
> + .change_queue_depth = sas_change_queue_depth, \
> + .bios_param = sas_bios_param, \
> + .this_id = -1, \
> + .eh_device_reset_handler = sas_eh_device_reset_handler, \
> + .eh_target_reset_handler = sas_eh_target_reset_handler, \
> + .target_destroy = sas_target_destroy, \
> + .ioctl = sas_ioctl, \
> +
> +#ifdef CONFIG_COMPAT
> +#define _LIBSAS_SHT_BASE __LIBSAS_SHT_BASE \
> + .compat_ioctl = sas_ioctl,
> +#else
> +#define _LIBSAS_SHT_BASE __LIBSAS_SHT_BASE
> +#endif
> +
> +#define LIBSAS_SHT_BASE _LIBSAS_SHT_BASE \
> + .slave_configure = sas_slave_configure, \
> + .slave_alloc = sas_slave_alloc, \
> +
> +#define LIBSAS_SHT_BASE_NO_SLAVE_INIT _LIBSAS_SHT_BASE
> +
> +
> #endif /* _SASLIB_H_ */
> --
> 2.31.1
>

2024-03-10 10:03:33

by John Garry

[permalink] [raw]
Subject: Re: [PATCH v2 1/6] scsi: libsas: Add LIBSAS_SHT_BASE

On 08/03/2024 19:41, Igor Pylypiv wrote:
>> Even though some drivers don't set proc_name, it won't make much difference
>> to set as DRV_NAME.
>>
>> Also add LIBSAS_SHT_BASE_NO_SLAVE_INIT for the hisi_sas drivers which have
>> custom .slave_alloc and .slave_configure methods.
> Looks like libata drivers have no problem overriding default values that were
> set by __ATA_BASE_SHT. For example __ATA_BASE_SHT sets .can_queue .sdev_attrs
> and then AHCI_SHT overrides those with AHCI specific values:
>
> #define AHCI_SHT(drv_name) \
> ATA_NCQ_SHT(drv_name), \

which tag are you looking at here?

That looks like an old definition of AHCI_SHT().

There was a significant change for this in the following:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/ata/ahci.h?h=v5.14&id=071e86fe2872e7442e42ad26f71cd6bde55344f8

Thanks,
John

2024-03-10 20:06:02

by Igor Pylypiv

[permalink] [raw]
Subject: Re: [PATCH v2 1/6] scsi: libsas: Add LIBSAS_SHT_BASE

On Sun, Mar 10, 2024 at 10:02:42AM +0000, John Garry wrote:
> On 08/03/2024 19:41, Igor Pylypiv wrote:
> > > Even though some drivers don't set proc_name, it won't make much difference
> > > to set as DRV_NAME.
> > >
> > > Also add LIBSAS_SHT_BASE_NO_SLAVE_INIT for the hisi_sas drivers which have
> > > custom .slave_alloc and .slave_configure methods.
> > Looks like libata drivers have no problem overriding default values that were
> > set by __ATA_BASE_SHT. For example __ATA_BASE_SHT sets .can_queue .sdev_attrs
> > and then AHCI_SHT overrides those with AHCI specific values:
> >
> > #define AHCI_SHT(drv_name) \
> > ATA_NCQ_SHT(drv_name), \
>
> which tag are you looking at here?
>
> That looks like an old definition of AHCI_SHT().
>
> There was a significant change for this in the following:
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/ata/ahci.h?h=v5.14&id=071e86fe2872e7442e42ad26f71cd6bde55344f8

Oh, my bad. I had some old kernel version checked out. Please disregard.

Reviewed-by: Igor Pylypiv <[email protected]>

Thanks,
Igor

>
> Thanks,
> John