[PATCH v1 1/3] scsi: Implement get_blk() function
Heinrich Schuchardt
xypron.glpk at gmx.de
Tue Apr 1 18:29:31 CEST 2025
On 01.04.25 10:00, Varadarajan Narayanan wrote:
> Add a function to obtain the block device for SCSI.
>
> Signed-off-by: Varadarajan Narayanan <quic_varada at quicinc.com>
> ---
> drivers/scsi/scsi-uclass.c | 30 ++++++++++++++++++++++++++++++
> include/scsi.h | 12 ++++++++++++
> 2 files changed, 42 insertions(+)
>
> diff --git a/drivers/scsi/scsi-uclass.c b/drivers/scsi/scsi-uclass.c
> index 1ee8236c05c..c2e34082bce 100644
> --- a/drivers/scsi/scsi-uclass.c
> +++ b/drivers/scsi/scsi-uclass.c
> @@ -10,7 +10,9 @@
>
> #define LOG_CATEGORY UCLASS_SCSI
>
> +#include <blk.h>
> #include <dm.h>
> +#include <part.h>
> #include <scsi.h>
>
> int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
> @@ -23,6 +25,34 @@ int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb)
> return ops->exec(dev, pccb);
> }
>
> +int scsi_get_blk(const char *partition_name,
> + struct blk_desc **blk_desc_ptr,
> + struct disk_partition *part_info_ptr)
> +{
> + static int is_scsi_scanned;
> + struct blk_desc *blk;
> + int i, ret;
> +
> + if (!is_scsi_scanned) {
> + scsi_scan(false /* no verbose */);
> + is_scsi_scanned = 1;
> + }
> +
> + for (i = 0; i < blk_find_max_devnum(UCLASS_SCSI) + 1; i++) {
> + ret = blk_get_desc(UCLASS_SCSI, i, &blk);
> + if (ret)
> + continue;
> +
> + ret = part_get_info_by_name(blk, partition_name, part_info_ptr);
> + if (ret > 0) {
> + *blk_desc_ptr = blk;
> + return 0;
> + }
> + }
> +
> + return -1;
> +}
> +
> int scsi_bus_reset(struct udevice *dev)
> {
> struct scsi_ops *ops = scsi_get_ops(dev);
> diff --git a/include/scsi.h b/include/scsi.h
> index b18ae37b861..1ba55516588 100644
> --- a/include/scsi.h
> +++ b/include/scsi.h
> @@ -9,6 +9,7 @@
> #include <asm/cache.h>
> #include <bouncebuf.h>
> #include <linux/dma-direction.h>
> +#include <part.h>
>
> struct udevice;
>
> @@ -349,6 +350,17 @@ int scsi_scan(bool verbose);
> */
> int scsi_scan_dev(struct udevice *dev, bool verbose);
>
> +/**
> + * scsi_get_blk() - Provides SCSI partition information.
> + *
> + * @partition_name: Partition name for fetching its info
Partition names cannot be expected to be unique.
UUIDs should be.
Best regards
Heinrich
> + * @blk_desc_ptr: Provides the blk descriptor
> + * @part_info_ptr: Provides partition info
> + */
> +int scsi_get_blk(const char *partition_name,
> + struct blk_desc **blk_desc_ptr,
> + struct disk_partition *part_info_ptr);
> +
> #define SCSI_IDENTIFY 0xC0 /* not used */
>
> /* Hardware errors */
More information about the U-Boot
mailing list