Changeset 9e195e2c in mainline for uspace/drv/usbmast/mast.c


Ignore:
Timestamp:
2011-05-12T09:03:00Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d59d0bb
Parents:
456aea3 (diff), c372e03 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmast/mast.c

    r456aea3 r9e195e2c  
    4040#include <str_error.h>
    4141#include <usb/debug.h>
     42#include <usb/request.h>
    4243
    4344bool usb_mast_verbose = true;
     
    6364 * @return Error code.
    6465 */
    65 int usb_massstor_data_in(usb_pipe_t *bulk_in_pipe, usb_pipe_t *bulk_out_pipe,
     66int usb_massstor_data_in(usb_device_t *dev,
     67    size_t bulk_in_pipe_index, size_t bulk_out_pipe_index,
    6668    uint32_t tag, uint8_t lun, void *cmd, size_t cmd_size,
    6769    void *in_buffer, size_t in_buffer_size, size_t *received_size)
     
    6971        int rc;
    7072        size_t act_size;
     73        usb_pipe_t *bulk_in_pipe = dev->pipes[bulk_in_pipe_index].pipe;
     74        usb_pipe_t *bulk_out_pipe = dev->pipes[bulk_out_pipe_index].pipe;
    7175
    7276        /* Prepare CBW - command block wrapper */
     
    135139}
    136140
     141/** Perform bulk-only mass storage reset.
     142 *
     143 * @param dev Device to be reseted.
     144 * @return Error code.
     145 */
     146int usb_massstor_reset(usb_device_t *dev)
     147{
     148        return usb_control_request_set(&dev->ctrl_pipe,
     149            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     150            0xFF, 0, dev->interface_no, NULL, 0);
     151}
     152
     153/** Perform complete reset recovery of bulk-only mass storage.
     154 *
     155 * Notice that no error is reported because if this fails, the error
     156 * would reappear on next transaction somehow.
     157 *
     158 * @param dev Device to be reseted.
     159 * @param bulk_in_idx Index of bulk in pipe.
     160 * @param bulk_out_idx Index of bulk out pipe.
     161 */
     162void usb_massstor_reset_recovery(usb_device_t *dev,
     163    size_t bulk_in_idx, size_t bulk_out_idx)
     164{
     165        /* We would ignore errors here because if this fails
     166         * we are doomed anyway and any following transaction would fail.
     167         */
     168        usb_massstor_reset(dev);
     169        usb_pipe_clear_halt(&dev->ctrl_pipe, dev->pipes[bulk_in_idx].pipe);
     170        usb_pipe_clear_halt(&dev->ctrl_pipe, dev->pipes[bulk_out_idx].pipe);
     171}
     172
     173/** Get max LUN of a mass storage device.
     174 *
     175 * @see usb_masstor_get_lun_count
     176 *
     177 * @warning Error from this command does not necessarily indicate malfunction
     178 * of the device. Device does not need to support this request.
     179 * You shall rather use usb_masstor_get_lun_count.
     180 *
     181 * @param dev Mass storage device.
     182 * @return Error code of maximum LUN (index, not count).
     183 */
     184int usb_massstor_get_max_lun(usb_device_t *dev)
     185{
     186        uint8_t max_lun;
     187        size_t data_recv_len;
     188        int rc = usb_control_request_get(&dev->ctrl_pipe,
     189            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     190            0xFE, 0, dev->interface_no, &max_lun, 1, &data_recv_len);
     191        if (rc != EOK) {
     192                return rc;
     193        }
     194        if (data_recv_len != 1) {
     195                return EEMPTY;
     196        }
     197        return (int) max_lun;
     198}
     199
     200/** Get number of LUNs supported by mass storage device.
     201 *
     202 * @warning This function hides any error during the request
     203 * (typically that shall not be a problem).
     204 *
     205 * @param dev Mass storage device.
     206 * @return Number of LUNs.
     207 */
     208size_t usb_masstor_get_lun_count(usb_device_t *dev)
     209{
     210        int max_lun = usb_massstor_get_max_lun(dev);
     211        if (max_lun < 0) {
     212                max_lun = 1;
     213        } else {
     214                max_lun++;
     215        }
     216
     217        return (size_t) max_lun;
     218}
     219
    137220/**
    138221 * @}
Note: See TracChangeset for help on using the changeset viewer.