Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | * Copyright (c) 2016 Xilinx, Inc |
| 6 | * Written by Michal Simek |
| 7 | * |
| 8 | * Based on ahci-uclass.c |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
Patrick Delaunay | 8131335 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 11 | #define LOG_CATEGORY UCLASS_SCSI |
| 12 | |
Varadarajan Narayanan | 5308c80 | 2025-05-13 14:47:07 +0530 | [diff] [blame^] | 13 | #include <blk.h> |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 14 | #include <dm.h> |
Varadarajan Narayanan | 5308c80 | 2025-05-13 14:47:07 +0530 | [diff] [blame^] | 15 | #include <part.h> |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 16 | #include <scsi.h> |
| 17 | |
Simon Glass | c4dfa89 | 2017-06-14 21:28:43 -0600 | [diff] [blame] | 18 | int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb) |
| 19 | { |
| 20 | struct scsi_ops *ops = scsi_get_ops(dev); |
| 21 | |
| 22 | if (!ops->exec) |
| 23 | return -ENOSYS; |
| 24 | |
| 25 | return ops->exec(dev, pccb); |
| 26 | } |
| 27 | |
Varadarajan Narayanan | 5308c80 | 2025-05-13 14:47:07 +0530 | [diff] [blame^] | 28 | int scsi_get_blk_by_uuid(const char *uuid, |
| 29 | struct blk_desc **blk_desc_ptr, |
| 30 | struct disk_partition *part_info_ptr) |
| 31 | { |
| 32 | static int is_scsi_scanned; |
| 33 | struct blk_desc *blk; |
| 34 | int i, ret; |
| 35 | |
| 36 | if (!is_scsi_scanned) { |
| 37 | scsi_scan(false /* no verbose */); |
| 38 | is_scsi_scanned = 1; |
| 39 | } |
| 40 | |
| 41 | for (i = 0; i < blk_find_max_devnum(UCLASS_SCSI) + 1; i++) { |
| 42 | ret = blk_get_desc(UCLASS_SCSI, i, &blk); |
| 43 | if (ret) |
| 44 | continue; |
| 45 | |
| 46 | ret = part_get_info_by_uuid(blk, uuid, part_info_ptr); |
| 47 | if (ret > 0) { |
| 48 | *blk_desc_ptr = blk; |
| 49 | return 0; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return -1; |
| 54 | } |
| 55 | |
Simon Glass | c4dfa89 | 2017-06-14 21:28:43 -0600 | [diff] [blame] | 56 | int scsi_bus_reset(struct udevice *dev) |
| 57 | { |
| 58 | struct scsi_ops *ops = scsi_get_ops(dev); |
| 59 | |
| 60 | if (!ops->bus_reset) |
| 61 | return -ENOSYS; |
| 62 | |
| 63 | return ops->bus_reset(dev); |
| 64 | } |
| 65 | |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 66 | UCLASS_DRIVER(scsi) = { |
| 67 | .id = UCLASS_SCSI, |
| 68 | .name = "scsi", |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 69 | .per_device_plat_auto = sizeof(struct scsi_plat), |
Michal Simek | c886f35 | 2016-09-08 15:06:45 +0200 | [diff] [blame] | 70 | }; |