Changeset 71fa44c in mainline


Ignore:
Timestamp:
2011-07-03T11:27:37Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9e34750
Parents:
6430ac6
Message:

Implement Read Capacity command for USB mass storage.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmast/main.c

    r6430ac6 r71fa44c  
    126126            lun_count);
    127127
     128        uint32_t nblocks, block_size;
     129
     130        rc = usbmast_read_capacity(dev, &nblocks, &block_size);
     131        if (rc != EOK) {
     132                usb_log_warning("Failed to read capacity, device `%s': %s.\n",
     133                    dev->ddf_dev->name, str_error(rc));
     134                return EOK;
     135        }
     136
     137        usb_log_info("Read Capacity: nblocks=%" PRIu32 ", "
     138            "block_size=%" PRIu32 "\n", nblocks, block_size);
     139
    128140        return EOK;
    129141}
  • uspace/drv/bus/usb/usbmast/scsi_ms.c

    r6430ac6 r71fa44c  
    11/*
    22 * Copyright (c) 2011 Vojtech Horky
     3 * Copyright (c) 2011 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3536 */
    3637#include <bitops.h>
     38#include <byteorder.h>
     39#include <inttypes.h>
    3740#include <usb/dev/driver.h>
    3841#include <usb/debug.h>
    39 #include <usb/classes/classes.h>
    40 #include <usb/classes/massstor.h>
    4142#include <errno.h>
    4243#include <str_error.h>
    4344#include <str.h>
    44 #include <ctype.h>
     45#include <scsi/sbc.h>
    4546#include <scsi/spc.h>
    4647#include "cmds.h"
     
    5859}
    5960
    60 /** Perform SCSI INQUIRY command on USB mass storage device.
     61/** Perform SCSI Inquiry command on USB mass storage device.
    6162 *
    6263 * @param dev           USB device.
     
    6869        scsi_std_inquiry_data_t inq_data;
    6970        size_t response_len;
    70         scsi_cdb_inquiry_t inquiry = {
    71                 .op_code = SCSI_CMD_INQUIRY,
    72                 .evpd = 0,
    73                 .page_code = 0,
    74                 .alloc_len = host2uint16_t_be(sizeof(inq_data)),
    75                 .control = 0
    76         };
    77 
     71        scsi_cdb_inquiry_t cdb;
    7872        int rc;
    7973
    80         rc = usb_massstor_data_in(dev, 0xDEADBEEF, 0, (uint8_t *) &inquiry,
    81             sizeof(inquiry), &inq_data, sizeof(inq_data), &response_len);
     74        memset(&cdb, 0, sizeof(cdb));
     75        cdb.op_code = SCSI_CMD_INQUIRY;
     76        cdb.alloc_len = host2uint16_t_be(sizeof(inq_data));
     77
     78        rc = usb_massstor_data_in(dev, 0xDEADBEEF, 0, (uint8_t *) &cdb,
     79            sizeof(cdb), &inq_data, sizeof(inq_data), &response_len);
    8280
    8381        if (rc != EOK) {
    84                 usb_log_error("Failed to probe device %s using %s: %s.\n",
    85                    dev->ddf_dev->name, "SCSI:INQUIRY", str_error(rc));
     82                usb_log_error("Inquiry failed, device %s: %s.\n",
     83                   dev->ddf_dev->name, str_error(rc));
    8684                return rc;
    8785        }
    8886
    8987        if (response_len < SCSI_STD_INQUIRY_DATA_MIN_SIZE) {
    90                 usb_log_error("The SCSI inquiry response is too short.\n");
     88                usb_log_error("SCSI Inquiry response too short (%zu).\n",
     89                    response_len);
    9190                return EIO;
    9291        }
     
    116115}
    117116
     117/** Perform SCSI Read Capacity command on USB mass storage device.
     118 *
     119 * @param dev           USB device.
     120 * @param nblocks       Output, number of blocks.
     121 * @param block_size    Output, block size in bytes.
     122 *
     123 * @return              Error code.
     124 */
     125int usbmast_read_capacity(usb_device_t *dev, uint32_t *nblocks,
     126    uint32_t *block_size)
     127{
     128        scsi_cdb_read_capacity_10_t cdb;
     129        scsi_read_capacity_10_data_t data;
     130        size_t data_len;
     131        int rc;
     132
     133        memset(&cdb, 0, sizeof(cdb));
     134        cdb.op_code = SCSI_CMD_READ_CAPACITY_10;
     135
     136        rc = usb_massstor_data_in(dev, 0xDEADBEEF, 0, (uint8_t *) &cdb,
     137            sizeof(cdb), &data, sizeof(data), &data_len);
     138
     139        if (rc != EOK) {
     140                usb_log_error("Read Capacity (10) failed, device %s: %s.\n",
     141                   dev->ddf_dev->name, str_error(rc));
     142                return rc;
     143        }
     144
     145        if (data_len < sizeof(data)) {
     146                usb_log_error("SCSI Read Capacity response too short (%zu).\n",
     147                    data_len);
     148                return EIO;
     149        }
     150
     151        *nblocks = uint32_t_be2host(data.last_lba) + 1;
     152        *block_size = uint32_t_be2host(data.block_size);
     153
     154        return EOK;
     155}
     156
    118157/**
    119158 * @}
  • uspace/drv/bus/usb/usbmast/scsi_ms.h

    r6430ac6 r71fa44c  
    5959} usbmast_inquiry_data_t;
    6060
    61 int usbmast_inquiry(usb_device_t *, usbmast_inquiry_data_t *);
    62 const char *usbmast_scsi_dev_type_str(unsigned);
     61extern int usbmast_inquiry(usb_device_t *, usbmast_inquiry_data_t *);
     62extern int usbmast_read_capacity(usb_device_t *dev, uint32_t *, uint32_t *);
     63extern const char *usbmast_scsi_dev_type_str(unsigned);
    6364
    6465#endif
  • uspace/lib/scsi/include/scsi/sbc.h

    r6430ac6 r71fa44c  
    113113        /** Size of block in bytes */
    114114        uint32_t block_size;
    115 } scsi_read_capacity_10_data;
     115} scsi_read_capacity_10_data_t;
    116116
    117117/** SCSI Write (12) command */
Note: See TracChangeset for help on using the changeset viewer.