blk: Switch over to using uclass IDs
We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.
Drop the if_type values and use the uclass ones instead.
Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c
index 1a2c3c2..167b5a3 100644
--- a/drivers/ata/dwc_ahsata.c
+++ b/drivers/ata/dwc_ahsata.c
@@ -880,7 +880,7 @@
device_find_first_child(dev, &blk);
if (!blk) {
ret = blk_create_devicef(dev, "dwc_ahsata_blk", "blk",
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;
diff --git a/drivers/ata/fsl_sata.c b/drivers/ata/fsl_sata.c
index 6db4247..972101b 100644
--- a/drivers/ata/fsl_sata.c
+++ b/drivers/ata/fsl_sata.c
@@ -888,7 +888,7 @@
for (i = 0; i < nr_ports; i++) {
snprintf(sata_name, sizeof(sata_name), "fsl_sata%d", i);
ret = blk_create_devicef(dev, "sata_fsl_blk", sata_name,
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;
diff --git a/drivers/ata/sata.c b/drivers/ata/sata.c
index 0e6c8cd..604c721 100644
--- a/drivers/ata/sata.c
+++ b/drivers/ata/sata.c
@@ -79,7 +79,7 @@
for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
memset(&sata_dev_desc[i], 0, sizeof(struct blk_desc));
- sata_dev_desc[i].if_type = IF_TYPE_SATA;
+ sata_dev_desc[i].if_type = UCLASS_AHCI;
sata_dev_desc[i].devnum = i;
sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index a187796..18c7a66 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -1076,7 +1076,7 @@
for (i = 0; i < nr_ports; i++) {
ret = blk_create_devicef(dev, "sata_mv_blk", "blk",
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
continue;
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 7065154..b5e150d 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -730,7 +730,7 @@
for (i = sata_info.portbase; i < sata_info.maxport; i++) {
snprintf(sata_name, sizeof(sata_name), "sil_sata%d", i);
ret = blk_create_devicef(dev, "sata_sil_blk", sata_name,
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index a68158c..436af76 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -21,33 +21,19 @@
enum uclass_id id;
const char *name;
} if_typename_str[] = {
- { IF_TYPE_IDE, "ide" },
- { IF_TYPE_SCSI, "scsi" },
- { IF_TYPE_USB, "usb" },
- { IF_TYPE_MMC, "mmc" },
- { IF_TYPE_SCSI, "sata" },
- { IF_TYPE_HOST, "host" },
- { IF_TYPE_NVME, "nvme" },
- { IF_TYPE_EFI_MEDIA, "efi" },
- { IF_TYPE_EFI_LOADER, "efiloader" },
- { IF_TYPE_VIRTIO, "virtio" },
- { IF_TYPE_PVBLOCK, "pvblock" },
+ { UCLASS_IDE, "ide" },
+ { UCLASS_SCSI, "scsi" },
+ { UCLASS_USB, "usb" },
+ { UCLASS_MMC, "mmc" },
+ { UCLASS_AHCI, "sata" },
+ { UCLASS_ROOT, "host" },
+ { UCLASS_NVME, "nvme" },
+ { UCLASS_EFI_MEDIA, "efi" },
+ { UCLASS_EFI_LOADER, "efiloader" },
+ { UCLASS_VIRTIO, "virtio" },
+ { UCLASS_PVBLOCK, "pvblock" },
};
-static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
- [IF_TYPE_IDE] = UCLASS_IDE,
- [IF_TYPE_SCSI] = UCLASS_SCSI,
- [IF_TYPE_USB] = UCLASS_MASS_STORAGE,
- [IF_TYPE_MMC] = UCLASS_MMC,
- [IF_TYPE_SATA] = UCLASS_AHCI,
- [IF_TYPE_HOST] = UCLASS_ROOT,
- [IF_TYPE_NVME] = UCLASS_NVME,
- [IF_TYPE_EFI_MEDIA] = UCLASS_EFI_MEDIA,
- [IF_TYPE_EFI_LOADER] = UCLASS_EFI_LOADER,
- [IF_TYPE_VIRTIO] = UCLASS_VIRTIO,
- [IF_TYPE_PVBLOCK] = UCLASS_PVBLOCK,
-};
-
static enum if_type if_typename_to_iftype(const char *if_typename)
{
int i;
@@ -57,12 +43,32 @@
return if_typename_str[i].id;
}
- return IF_TYPE_UNKNOWN;
+ return UCLASS_INVALID;
}
static enum uclass_id if_type_to_uclass_id(enum if_type if_type)
{
- return if_type_uclass_id[if_type];
+ /*
+ * This strange adjustment is used because we use UCLASS_MASS_STORAGE
+ * for USB storage devices, so need to return this as the uclass to
+ * use for USB. In fact USB_UCLASS is for USB controllers, not
+ * peripherals.
+ *
+ * The name of the UCLASS_MASS_STORAGE uclass driver is
+ * "usb_mass_storage", but we want to use "usb" in things like the
+ * 'part list' command and when showing interfaces.
+ *
+ * So for now we have this one-way conversion.
+ *
+ * The fix for this is possibly to:
+ * - rename UCLASS_MASS_STORAGE name to "usb"
+ * - rename UCLASS_USB name to "usb_ctlr"
+ * - use UCLASS_MASS_STORAGE instead of UCLASS_USB in if_typename_str
+ */
+ if (if_type == UCLASS_USB)
+ return UCLASS_MASS_STORAGE;
+
+ return if_type;
}
const char *blk_get_if_type_name(enum if_type if_type)
@@ -70,7 +76,7 @@
int i;
for (i = 0; i < ARRAY_SIZE(if_typename_str); i++) {
- if ((int)if_typename_str[i].id == if_type)
+ if (if_typename_str[i].id == if_type)
return if_typename_str[i].name;
}
@@ -105,7 +111,7 @@
int ret;
type = if_typename_to_iftype(if_typename);
- if (type == IF_TYPE_UNKNOWN) {
+ if (type == UCLASS_INVALID) {
debug("%s: Unknown interface type '%s'\n", __func__,
if_typename);
return NULL;
diff --git a/drivers/block/efi_blk.c b/drivers/block/efi_blk.c
index 9d25ecb..917a19f 100644
--- a/drivers/block/efi_blk.c
+++ b/drivers/block/efi_blk.c
@@ -94,7 +94,7 @@
struct udevice *blk;
int ret;
- ret = blk_create_devicef(dev, "efi_block", "blk", IF_TYPE_EFI_MEDIA,
+ ret = blk_create_devicef(dev, "efi_block", "blk", UCLASS_EFI_MEDIA,
dev_seq(dev), plat->blkio->media->block_size,
plat->blkio->media->last_block, &blk);
if (ret) {
diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 6bc48e3..73da29a 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -537,7 +537,7 @@
/* Select device
*/
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
- dev_desc->if_type = IF_TYPE_IDE;
+ dev_desc->if_type = UCLASS_IDE;
#ifdef CONFIG_ATAPI
retries = 0;
@@ -752,7 +752,7 @@
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
- ide_dev_desc[i].if_type = IF_TYPE_IDE;
+ ide_dev_desc[i].if_type = UCLASS_IDE;
ide_dev_desc[i].devnum = i;
ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
ide_dev_desc[i].blksz = 0;
@@ -1110,7 +1110,7 @@
if (!blksz)
continue;
ret = blk_create_devicef(udev, "ide_blk", name,
- IF_TYPE_IDE, i,
+ UCLASS_IDE, i,
blksz, size, &blk_dev);
if (ret)
return ret;
@@ -1144,7 +1144,7 @@
#else
U_BOOT_LEGACY_BLK(ide) = {
.if_typename = "ide",
- .if_type = IF_TYPE_IDE,
+ .if_type = UCLASS_IDE,
.max_devs = CONFIG_SYS_IDE_MAXDEVICE,
.desc = ide_dev_desc,
};
diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
index 1388498..2de12e0 100644
--- a/drivers/block/sandbox.c
+++ b/drivers/block/sandbox.c
@@ -98,7 +98,7 @@
int ret, fd;
/* Remove and unbind the old device, if any */
- ret = blk_get_device(IF_TYPE_HOST, devnum, &dev);
+ ret = blk_get_device(UCLASS_ROOT, devnum, &dev);
if (ret == 0) {
ret = device_remove(dev, DM_REMOVE_NORMAL);
if (ret)
@@ -135,7 +135,7 @@
}
}
ret = blk_create_device(gd->dm_root, "sandbox_host_blk", str,
- IF_TYPE_HOST, devnum, 512,
+ UCLASS_ROOT, devnum, 512,
os_lseek(fd, 0, OS_SEEK_END) / 512, &dev);
if (ret)
goto err_file;
@@ -150,7 +150,7 @@
goto err_file;
}
- desc = blk_get_devnum_by_type(IF_TYPE_HOST, devnum);
+ desc = blk_get_devnum_by_type(UCLASS_ROOT, devnum);
desc->removable = removable;
snprintf(desc->vendor, BLK_VEN_SIZE, "U-Boot");
snprintf(desc->product, BLK_PRD_SIZE, "hostfile");
@@ -192,7 +192,7 @@
}
struct blk_desc *blk_dev = &host_dev->blk_dev;
- blk_dev->if_type = IF_TYPE_HOST;
+ blk_dev->if_type = UCLASS_ROOT;
blk_dev->priv = host_dev;
blk_dev->blksz = 512;
blk_dev->lba = os_lseek(host_dev->fd, 0, OS_SEEK_END) / blk_dev->blksz;
@@ -216,7 +216,7 @@
struct udevice *dev;
int ret;
- ret = blk_get_device(IF_TYPE_HOST, devnum, &dev);
+ ret = blk_get_device(UCLASS_ROOT, devnum, &dev);
if (ret)
return ret;
*blk_devp = dev_get_uclass_plat(dev);
@@ -263,7 +263,7 @@
#else
U_BOOT_LEGACY_BLK(sandbox_host) = {
.if_typename = "host",
- .if_type = IF_TYPE_HOST,
+ .if_type = UCLASS_ROOT,
.max_devs = SANDBOX_HOST_MAX_DEVICES,
.get_dev = host_get_dev_err,
};
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index a91da97..f583208 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -52,7 +52,7 @@
if (dfu->data.mmc.hw_partition >= 0) {
part_num_bkp = mmc_get_blk_desc(mmc)->hwpart;
- ret = blk_select_hwpart_devnum(IF_TYPE_MMC,
+ ret = blk_select_hwpart_devnum(UCLASS_MMC,
dfu->data.mmc.dev_num,
dfu->data.mmc.hw_partition);
if (ret)
@@ -77,14 +77,14 @@
if (n != blk_count) {
pr_err("MMC operation failed");
if (dfu->data.mmc.hw_partition >= 0)
- blk_select_hwpart_devnum(IF_TYPE_MMC,
+ blk_select_hwpart_devnum(UCLASS_MMC,
dfu->data.mmc.dev_num,
part_num_bkp);
return -EIO;
}
if (dfu->data.mmc.hw_partition >= 0) {
- ret = blk_select_hwpart_devnum(IF_TYPE_MMC,
+ ret = blk_select_hwpart_devnum(UCLASS_MMC,
dfu->data.mmc.dev_num,
part_num_bkp);
if (ret)
diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index 688bdc0..b1bd4ae 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -290,7 +290,7 @@
struct udevice *dev, *mmc_dev;
int ret;
- ret = blk_find_device(IF_TYPE_MMC, dev_num, &dev);
+ ret = blk_find_device(UCLASS_MMC, dev_num, &dev);
if (ret) {
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
@@ -308,12 +308,12 @@
int get_mmc_num(void)
{
- return max((blk_find_max_devnum(IF_TYPE_MMC) + 1), 0);
+ return max((blk_find_max_devnum(UCLASS_MMC) + 1), 0);
}
int mmc_get_next_devnum(void)
{
- return blk_find_max_devnum(IF_TYPE_MMC);
+ return blk_find_max_devnum(UCLASS_MMC);
}
int mmc_get_blk(struct udevice *dev, struct udevice **blkp)
@@ -411,8 +411,8 @@
/* Use the fixed index with aliases node's index */
debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
- ret = blk_create_devicef(dev, "mmc_blk", "blk", IF_TYPE_MMC,
- dev_seq(dev), 512, 0, &bdev);
+ ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
+ dev_seq(dev), 512, 0, &bdev);
if (ret) {
debug("Cannot create block device\n");
return ret;
diff --git a/drivers/mmc/mmc_legacy.c b/drivers/mmc/mmc_legacy.c
index a05da6c..4e0891e 100644
--- a/drivers/mmc/mmc_legacy.c
+++ b/drivers/mmc/mmc_legacy.c
@@ -132,7 +132,7 @@
.dsr_imp = 0,
.dsr = 0xffffffff,
.block_dev = {
- .if_type = IF_TYPE_MMC,
+ .if_type = UCLASS_MMC,
.removable = 1,
.devnum = 0,
.block_read = mmc_bread,
@@ -194,7 +194,7 @@
mmc->dsr = 0xffffffff;
/* Setup the universal parts of the block interface just once */
bdesc = mmc_get_blk_desc(mmc);
- bdesc->if_type = IF_TYPE_MMC;
+ bdesc->if_type = UCLASS_MMC;
bdesc->removable = 1;
bdesc->devnum = mmc_get_next_devnum();
bdesc->block_read = mmc_bread;
@@ -254,7 +254,7 @@
U_BOOT_LEGACY_BLK(mmc) = {
.if_typename = "mmc",
- .if_type = IF_TYPE_MMC,
+ .if_type = UCLASS_MMC,
.max_devs = -1,
.get_dev = mmc_get_dev,
.select_hwpart = mmc_select_hwpartp,
diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index eab94c7..5b7aeeb 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -85,7 +85,7 @@
if (!mmc)
return -1;
- err = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_num,
+ err = blk_select_hwpart_devnum(UCLASS_MMC, dev_num,
block_dev->hwpart);
if (err < 0)
return -1;
@@ -203,7 +203,7 @@
if (!mmc)
return 0;
- err = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_num, block_dev->hwpart);
+ err = blk_select_hwpart_devnum(UCLASS_MMC, dev_num, block_dev->hwpart);
if (err < 0)
return 0;
diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index 31cf700..3510f79 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -880,7 +880,7 @@
sprintf(name, "blk#%d", i);
/* The real blksz and size will be set by nvme_blk_probe() */
- ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
+ ret = blk_create_devicef(udev, "nvme-blk", name, UCLASS_NVME,
-1, 512, 0, &ns_udev);
if (ret)
goto free_id;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 78d729d..99be5ae 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -456,7 +456,7 @@
{
dev_desc->lba = 0;
dev_desc->blksz = 0;
- dev_desc->if_type = IF_TYPE_SCSI;
+ dev_desc->if_type = UCLASS_SCSI;
dev_desc->devnum = devnum;
dev_desc->part_type = PART_TYPE_UNKNOWN;
@@ -574,8 +574,8 @@
* block devices created
*/
snprintf(str, sizeof(str), "id%dlun%d", id, lun);
- ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1,
- bd.blksz, bd.lba, &bdev);
+ ret = blk_create_devicef(dev, "scsi_blk", str, UCLASS_SCSI, -1,
+ bd.blksz, bd.lba, &bdev);
if (ret) {
debug("Can't create device\n");
return ret;
@@ -638,7 +638,7 @@
if (verbose)
printf("scanning bus for devices...\n");
- blk_unbind_all(IF_TYPE_SCSI);
+ blk_unbind_all(UCLASS_SCSI);
ret = uclass_get(UCLASS_SCSI, &uc);
if (ret)
@@ -707,7 +707,7 @@
#else
U_BOOT_LEGACY_BLK(scsi) = {
.if_typename = "scsi",
- .if_type = IF_TYPE_SCSI,
+ .if_type = UCLASS_SCSI,
.max_devs = SCSI_MAX_DEVICE,
.desc = scsi_dev_desc,
};
diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
index cf5e0a0..5bc1375 100644
--- a/drivers/tee/optee/rpmb.c
+++ b/drivers/tee/optee/rpmb.c
@@ -48,7 +48,7 @@
if (!priv->rpmb_mmc)
return;
- rc = blk_select_hwpart_devnum(IF_TYPE_MMC, priv->rpmb_dev_id,
+ rc = blk_select_hwpart_devnum(UCLASS_MMC, priv->rpmb_dev_id,
priv->rpmb_original_part);
if (rc)
debug("%s: blk_select_hwpart_devnum() failed: %d\n",
@@ -88,7 +88,7 @@
priv->rpmb_original_part = mmc_get_blk_desc(mmc)->hwpart;
- rc = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_id, MMC_PART_RPMB);
+ rc = blk_select_hwpart_devnum(UCLASS_MMC, dev_id, MMC_PART_RPMB);
if (rc) {
debug("Device id %d: cannot select RPMB partition: %d\n",
dev_id, rc);
diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c
index 3ff74f4..9710b79 100644
--- a/drivers/virtio/virtio_blk.c
+++ b/drivers/virtio/virtio_blk.c
@@ -75,14 +75,14 @@
struct blk_desc *desc = dev_get_uclass_plat(dev);
int devnum;
- desc->if_type = IF_TYPE_VIRTIO;
+ desc->if_type = UCLASS_VIRTIO;
/*
* Initialize the devnum to -ENODEV. This is to make sure that
* blk_next_free_devnum() works as expected, since the default
* value 0 is a valid devnum.
*/
desc->devnum = -ENODEV;
- devnum = blk_next_free_devnum(IF_TYPE_VIRTIO);
+ devnum = blk_next_free_devnum(UCLASS_VIRTIO);
if (devnum < 0)
return devnum;
desc->devnum = devnum;
diff --git a/drivers/xen/pvblock.c b/drivers/xen/pvblock.c
index c25c3ea..1090e52 100644
--- a/drivers/xen/pvblock.c
+++ b/drivers/xen/pvblock.c
@@ -665,14 +665,14 @@
struct blk_desc *desc = dev_get_uclass_plat(udev);
int devnum;
- desc->if_type = IF_TYPE_PVBLOCK;
+ desc->if_type = UCLASS_PVBLOCK;
/*
* Initialize the devnum to -ENODEV. This is to make sure that
* blk_next_free_devnum() works as expected, since the default
* value 0 is a valid devnum.
*/
desc->devnum = -ENODEV;
- devnum = blk_next_free_devnum(IF_TYPE_PVBLOCK);
+ devnum = blk_next_free_devnum(UCLASS_PVBLOCK);
if (devnum < 0)
return devnum;
desc->devnum = devnum;
@@ -804,7 +804,7 @@
const char *class_name;
class_name = uclass_get_name(UCLASS_PVBLOCK);
- for (blk_first_device(IF_TYPE_PVBLOCK, &udev); udev;
+ for (blk_first_device(UCLASS_PVBLOCK, &udev); udev;
blk_next_device(&udev), first = false) {
struct blk_desc *desc = dev_get_uclass_plat(udev);