Changeset 7190bbc in mainline


Ignore:
Timestamp:
2011-07-15T20:22:32Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e6b32a8
Parents:
89d3f3c7
Message:

Use usbmast_fun_t in more parts of the driver.

Location:
uspace/drv/bus/usb/usbmast
Files:
1 added
5 edited

Legend:

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

    r89d3f3c7 r7190bbc  
    4242#include "bo_trans.h"
    4343#include "cmdw.h"
     44#include "usbmast.h"
    4445
    4546bool usb_mast_verbose = false;
     
    5455/** Send command via bulk-only transport.
    5556 *
     57 * @param mfun          Mass storage function
    5658 * @param tag           Command block wrapper tag (automatically compared
    5759 *                      with answer)
     
    6668 * @return              Error code
    6769 */
    68 static int usb_massstor_cmd(usb_device_t *dev, uint32_t tag, uint8_t lun,
     70static int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, uint8_t lun,
    6971    const void *cmd, size_t cmd_size, usb_direction_t ddir, void *dbuf,
    7072    size_t dbuf_size, size_t *xferred_size)
     
    7274        int rc;
    7375        size_t act_size;
    74         usb_pipe_t *bulk_in_pipe = dev->pipes[BULK_IN_EP].pipe;
    75         usb_pipe_t *bulk_out_pipe = dev->pipes[BULK_OUT_EP].pipe;
     76        usb_pipe_t *bulk_in_pipe = mfun->usb_dev->pipes[BULK_IN_EP].pipe;
     77        usb_pipe_t *bulk_out_pipe = mfun->usb_dev->pipes[BULK_OUT_EP].pipe;
    7678
    7779        /* Prepare CBW - command block wrapper */
     
    165167/** Perform data-in command.
    166168 *
     169 * @param mfun          Mass storage function
    167170 * @param tag           Command block wrapper tag (automatically compared with
    168171 *                      answer)
     
    176179 * @return Error code
    177180 */
    178 int usb_massstor_data_in(usb_device_t *dev, uint32_t tag, uint8_t lun,
     181int usb_massstor_data_in(usbmast_fun_t *mfun, uint32_t tag, uint8_t lun,
    179182    const void *cmd, size_t cmd_size, void *dbuf, size_t dbuf_size, size_t *proc_size)
    180183{
    181         return usb_massstor_cmd(dev, tag, lun, cmd, cmd_size, USB_DIRECTION_IN,
     184        return usb_massstor_cmd(mfun, tag, lun, cmd, cmd_size, USB_DIRECTION_IN,
    182185            dbuf, dbuf_size, proc_size);
    183186}
     
    185188/** Perform data-out command.
    186189 *
     190 * @param mfun          Mass storage function
    187191 * @param tag           Command block wrapper tag (automatically compared with
    188192 *                      answer)
     
    196200 * @return Error code
    197201 */
    198 int usb_massstor_data_out(usb_device_t *dev, uint32_t tag, uint8_t lun,
     202int usb_massstor_data_out(usbmast_fun_t *mfun, uint32_t tag, uint8_t lun,
    199203    const void *cmd, size_t cmd_size, const void *data, size_t data_size,
    200204    size_t *proc_size)
    201205{
    202         return usb_massstor_cmd(dev, tag, lun, cmd, cmd_size, USB_DIRECTION_OUT,
     206        return usb_massstor_cmd(mfun, tag, lun, cmd, cmd_size, USB_DIRECTION_OUT,
    203207            (void *) data, data_size, proc_size);
    204208}
     
    206210/** Perform bulk-only mass storage reset.
    207211 *
    208  * @param dev Device to be reseted.
    209  * @return Error code.
    210  */
    211 int usb_massstor_reset(usb_device_t *dev)
    212 {
    213         return usb_control_request_set(&dev->ctrl_pipe,
     212 * @param mfun          Mass storage function
     213 * @return              Error code
     214 */
     215int usb_massstor_reset(usbmast_fun_t *mfun)
     216{
     217        return usb_control_request_set(&mfun->usb_dev->ctrl_pipe,
    214218            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    215             0xFF, 0, dev->interface_no, NULL, 0);
     219            0xFF, 0, mfun->usb_dev->interface_no, NULL, 0);
    216220}
    217221
     
    221225 * would reappear on next transaction somehow.
    222226 *
    223  * @param dev Device to be reseted.
    224  */
    225 void usb_massstor_reset_recovery(usb_device_t *dev)
     227 * @param mfun          Mass storage function
     228 */
     229void usb_massstor_reset_recovery(usbmast_fun_t *mfun)
    226230{
    227231        /* We would ignore errors here because if this fails
    228232         * we are doomed anyway and any following transaction would fail.
    229233         */
    230         usb_massstor_reset(dev);
    231         usb_pipe_clear_halt(&dev->ctrl_pipe, dev->pipes[BULK_IN_EP].pipe);
    232         usb_pipe_clear_halt(&dev->ctrl_pipe, dev->pipes[BULK_OUT_EP].pipe);
     234        usb_massstor_reset(mfun);
     235        usb_pipe_clear_halt(&mfun->usb_dev->ctrl_pipe,
     236            mfun->usb_dev->pipes[BULK_IN_EP].pipe);
     237        usb_pipe_clear_halt(&mfun->usb_dev->ctrl_pipe,
     238            mfun->usb_dev->pipes[BULK_OUT_EP].pipe);
    233239}
    234240
     
    241247 * You shall rather use usb_masstor_get_lun_count.
    242248 *
    243  * @param dev Mass storage device.
    244  * @return Error code of maximum LUN (index, not count).
    245  */
    246 int usb_massstor_get_max_lun(usb_device_t *dev)
     249 * @param mfun          Mass storage function
     250 * @return              Error code of maximum LUN (index, not count)
     251 */
     252int usb_massstor_get_max_lun(usbmast_fun_t *mfun)
    247253{
    248254        uint8_t max_lun;
    249255        size_t data_recv_len;
    250         int rc = usb_control_request_get(&dev->ctrl_pipe,
     256        int rc = usb_control_request_get(&mfun->usb_dev->ctrl_pipe,
    251257            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    252             0xFE, 0, dev->interface_no, &max_lun, 1, &data_recv_len);
     258            0xFE, 0, mfun->usb_dev->interface_no, &max_lun, 1, &data_recv_len);
    253259        if (rc != EOK) {
    254260                return rc;
     
    265271 * (typically that shall not be a problem).
    266272 *
    267  * @param dev Mass storage device.
    268  * @return Number of LUNs.
    269  */
    270 size_t usb_masstor_get_lun_count(usb_device_t *dev)
    271 {
    272         int max_lun = usb_massstor_get_max_lun(dev);
     273 * @param mfun          Mass storage function
     274 * @return              Number of LUNs
     275 */
     276size_t usb_masstor_get_lun_count(usbmast_fun_t *mfun)
     277{
     278        int max_lun = usb_massstor_get_max_lun(mfun);
    273279        if (max_lun < 0) {
    274280                max_lun = 1;
  • uspace/drv/bus/usb/usbmast/bo_trans.h

    r89d3f3c7 r7190bbc  
    4242#include <usb/dev/pipes.h>
    4343#include <usb/dev/driver.h>
     44#include "usbmast.h"
    4445
    4546#define BULK_IN_EP 0
    4647#define BULK_OUT_EP 1
    4748
    48 extern int usb_massstor_data_in(usb_device_t *, uint32_t, uint8_t, const void *,
    49     size_t, void *, size_t, size_t *);
    50 extern int usb_massstor_data_out(usb_device_t *, uint32_t, uint8_t, const void *,
    51     size_t, const void *, size_t, size_t *);
    52 extern int usb_massstor_reset(usb_device_t *);
    53 extern void usb_massstor_reset_recovery(usb_device_t *);
    54 extern int usb_massstor_get_max_lun(usb_device_t *);
    55 extern size_t usb_masstor_get_lun_count(usb_device_t *);
     49extern int usb_massstor_data_in(usbmast_fun_t *, uint32_t, uint8_t,
     50    const void *, size_t, void *, size_t, size_t *);
     51extern int usb_massstor_data_out(usbmast_fun_t *, uint32_t, uint8_t,
     52    const void *, size_t, const void *, size_t, size_t *);
     53extern int usb_massstor_reset(usbmast_fun_t *);
     54extern void usb_massstor_reset_recovery(usbmast_fun_t *);
     55extern int usb_massstor_get_max_lun(usbmast_fun_t *);
     56extern size_t usb_masstor_get_lun_count(usbmast_fun_t *);
    5657
    5758#endif
  • uspace/drv/bus/usb/usbmast/main.c

    r89d3f3c7 r7190bbc  
    4848#include "bo_trans.h"
    4949#include "scsi_ms.h"
     50#include "usbmast.h"
    5051
    5152#define NAME "usbmast"
     
    7778};
    7879
    79 /** Mass storage function.
    80  *
    81  * Serves as soft state for function/LUN.
    82  */
    83 typedef struct {
    84         /** DDF function */
    85         ddf_fun_t *ddf_fun;
    86         /** Total number of blocks. */
    87         uint64_t nblocks;
    88         /** Block size in bytes. */
    89         size_t block_size;
    90         /** USB device function belongs to */
    91         usb_device_t *usb_dev;
    92 } usbmast_fun_t;
    93 
    9480static void usbmast_bd_connection(ipc_callid_t iid, ipc_call_t *icall,
    9581    void *arg);
     
    114100                goto error;
    115101        }
     102
     103        msfun->usb_dev = dev;
    116104
    117105        fun = ddf_fun_create(dev->ddf_dev, fun_exposed, fun_name);
     
    136124
    137125        usb_log_debug("Get LUN count...\n");
    138         size_t lun_count = usb_masstor_get_lun_count(dev);
     126        size_t lun_count = usb_masstor_get_lun_count(msfun);
    139127
    140128        /* XXX Handle more than one LUN properly. */
     
    146134        usb_log_debug("Inquire...\n");
    147135        usbmast_inquiry_data_t inquiry;
    148         rc = usbmast_inquiry(dev, &inquiry);
     136        rc = usbmast_inquiry(msfun, &inquiry);
    149137        if (rc != EOK) {
    150138                usb_log_warning("Failed to inquire device `%s': %s.\n",
     
    166154        uint32_t nblocks, block_size;
    167155
    168         rc = usbmast_read_capacity(dev, &nblocks, &block_size);
     156        rc = usbmast_read_capacity(msfun, &nblocks, &block_size);
    169157        if (rc != EOK) {
    170158                usb_log_warning("Failed to read capacity, device `%s': %s.\n",
     
    179167        msfun->nblocks = nblocks;
    180168        msfun->block_size = block_size;
    181         msfun->usb_dev = dev;
    182169
    183170        rc = ddf_fun_bind(fun);
     
    252239                        ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
    253240                        cnt = IPC_GET_ARG3(call);
    254                         retval = usbmast_read(msfun->usb_dev, ba, cnt,
    255                             msfun->block_size, comm_buf);
     241                        retval = usbmast_read(msfun, ba, cnt, comm_buf);
    256242                        async_answer_0(callid, retval);
    257243                        break;
     
    259245                        ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
    260246                        cnt = IPC_GET_ARG3(call);
    261                         retval = usbmast_write(msfun->usb_dev, ba, cnt,
    262                             msfun->block_size, comm_buf);
     247                        retval = usbmast_write(msfun, ba, cnt, comm_buf);
    263248                        async_answer_0(callid, retval);
    264249                        break;
  • uspace/drv/bus/usb/usbmast/scsi_ms.c

    r89d3f3c7 r7190bbc  
    4949#include "bo_trans.h"
    5050#include "scsi_ms.h"
     51#include "usbmast.h"
    5152
    5253/** Get string representation for SCSI peripheral device type.
     
    6263/** Perform SCSI Inquiry command on USB mass storage device.
    6364 *
    64  * @param dev           USB device.
    65  * @param inquiry_result Where to store parsed inquiry result.
    66  * @return              Error code.
    67  */
    68 int usbmast_inquiry(usb_device_t *dev, usbmast_inquiry_data_t *inq_res)
     65 * @param mfun          Mass storage function
     66 * @param inquiry_result Where to store parsed inquiry result
     67 * @return              Error code
     68 */
     69int usbmast_inquiry(usbmast_fun_t *mfun, usbmast_inquiry_data_t *inq_res)
    6970{
    7071        scsi_std_inquiry_data_t inq_data;
     
    7778        cdb.alloc_len = host2uint16_t_be(sizeof(inq_data));
    7879
    79         rc = usb_massstor_data_in(dev, 0xDEADBEEF, 0, (uint8_t *) &cdb,
     80        rc = usb_massstor_data_in(mfun, 0xDEADBEEF, 0, (uint8_t *) &cdb,
    8081            sizeof(cdb), &inq_data, sizeof(inq_data), &response_len);
    8182
    8283        if (rc != EOK) {
    8384                usb_log_error("Inquiry failed, device %s: %s.\n",
    84                    dev->ddf_dev->name, str_error(rc));
     85                   mfun->usb_dev->ddf_dev->name, str_error(rc));
    8586                return rc;
    8687        }
     
    118119/** Perform SCSI Request Sense command on USB mass storage device.
    119120 *
    120  * @param dev           USB device
     121 * @param mfun          Mass storage function
    121122 * @param buf           Destination buffer
    122123 * @param size          Size of @a buf
     
    124125 * @return              Error code.
    125126 */
    126 int usbmast_request_sense(usb_device_t *dev, void *buf, size_t size)
     127int usbmast_request_sense(usbmast_fun_t *mfun, void *buf, size_t size)
    127128{
    128129        scsi_cdb_request_sense_t cdb;
     
    134135        cdb.alloc_len = min(size, SCSI_SENSE_DATA_MAX_SIZE);
    135136
    136         rc = usb_massstor_data_in(dev, 0xDEADBEEF, 0, (uint8_t *) &cdb,
     137        rc = usb_massstor_data_in(mfun, 0xDEADBEEF, 0, (uint8_t *) &cdb,
    137138            sizeof(cdb), buf, size, &data_len);
    138139
    139140        if (rc != EOK) {
    140141                usb_log_error("Request Sense failed, device %s: %s.\n",
    141                    dev->ddf_dev->name, str_error(rc));
     142                   mfun->usb_dev->ddf_dev->name, str_error(rc));
    142143                return rc;
    143144        }
     
    154155/** Perform SCSI Read Capacity command on USB mass storage device.
    155156 *
    156  * @param dev           USB device.
    157  * @param nblocks       Output, number of blocks.
    158  * @param block_size    Output, block size in bytes.
     157 * @param mfun          Mass storage function
     158 * @param nblocks       Output, number of blocks
     159 * @param block_size    Output, block size in bytes
    159160 *
    160161 * @return              Error code.
    161162 */
    162 int usbmast_read_capacity(usb_device_t *dev, uint32_t *nblocks,
     163int usbmast_read_capacity(usbmast_fun_t *mfun, uint32_t *nblocks,
    163164    uint32_t *block_size)
    164165{
     
    171172        cdb.op_code = SCSI_CMD_READ_CAPACITY_10;
    172173
    173         rc = usb_massstor_data_in(dev, 0xDEADBEEF, 0, (uint8_t *) &cdb,
     174        rc = usb_massstor_data_in(mfun, 0xDEADBEEF, 0, (uint8_t *) &cdb,
    174175            sizeof(cdb), &data, sizeof(data), &data_len);
    175176
    176177        if (rc != EOK) {
    177178                usb_log_error("Read Capacity (10) failed, device %s: %s.\n",
    178                    dev->ddf_dev->name, str_error(rc));
     179                   mfun->usb_dev->ddf_dev->name, str_error(rc));
    179180                return rc;
    180181        }
     
    194195/** Perform SCSI Read command on USB mass storage device.
    195196 *
    196  * @param dev           USB device.
    197  * @param ba            Address of first block.
    198  * @param nblocks       Number of blocks to read.
    199  * @param bsize         Block size.
    200  *
    201  * @return              Error code.
    202  */
    203 int usbmast_read(usb_device_t *dev, uint64_t ba, size_t nblocks, size_t bsize,
    204     void *buf)
     197 * @param mfun          Mass storage function
     198 * @param ba            Address of first block
     199 * @param nblocks       Number of blocks to read
     200 *
     201 * @return              Error code
     202 */
     203int usbmast_read(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks, void *buf)
    205204{
    206205        scsi_cdb_read_12_t cdb;
     
    213212                return ELIMIT;
    214213
    215         if ((uint64_t)nblocks * bsize > UINT32_MAX)
     214        if ((uint64_t)nblocks * mfun->block_size > UINT32_MAX)
    216215                return ELIMIT;
    217216
     
    221220        cdb.xfer_len = host2uint32_t_be(nblocks);
    222221
    223         rc = usb_massstor_data_in(dev, 0xDEADBEEF, 0, (uint8_t *) &cdb,
    224             sizeof(cdb), buf, nblocks * bsize, &data_len);
     222        rc = usb_massstor_data_in(mfun, 0xDEADBEEF, 0, (uint8_t *) &cdb,
     223            sizeof(cdb), buf, nblocks * mfun->block_size, &data_len);
    225224
    226225        if (rc != EOK) {
    227226                usb_log_error("Read (12) failed, device %s: %s.\n",
    228                    dev->ddf_dev->name, str_error(rc));
    229                 return rc;
    230         }
    231 
    232         if (data_len < nblocks * bsize) {
     227                   mfun->usb_dev->ddf_dev->name, str_error(rc));
     228                return rc;
     229        }
     230
     231        if (data_len < nblocks * mfun->block_size) {
    233232                usb_log_error("SCSI Read response too short (%zu).\n",
    234233                    data_len);
     
    241240/** Perform SCSI Write command on USB mass storage device.
    242241 *
    243  * @param dev           USB device
     242 * @param mfun          Mass storage function
    244243 * @param ba            Address of first block
    245244 * @param nblocks       Number of blocks to read
    246  * @param bsize         Block size
    247245 * @param data          Data to write
    248246 *
    249247 * @return              Error code
    250248 */
    251 int usbmast_write(usb_device_t *dev, uint64_t ba, size_t nblocks, size_t bsize,
     249int usbmast_write(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks,
    252250    const void *data)
    253251{
     
    256254        int rc;
    257255
    258         /* XXX Need softstate to store block size. */
    259 
    260256        if (ba > UINT32_MAX)
    261257                return ELIMIT;
    262258
    263         if ((uint64_t)nblocks * bsize > UINT32_MAX)
     259        if ((uint64_t)nblocks * mfun->block_size > UINT32_MAX)
    264260                return ELIMIT;
    265261
     
    269265        cdb.xfer_len = host2uint32_t_be(nblocks);
    270266
    271         rc = usb_massstor_data_out(dev, 0xDEADBEEF, 0, (uint8_t *) &cdb,
    272             sizeof(cdb), data, nblocks * bsize, &sent_len);
     267        rc = usb_massstor_data_out(mfun, 0xDEADBEEF, 0, (uint8_t *) &cdb,
     268            sizeof(cdb), data, nblocks * mfun->block_size, &sent_len);
    273269
    274270        if (rc != EOK) {
    275271                usb_log_error("Write (12) failed, device %s: %s.\n",
    276                    dev->ddf_dev->name, str_error(rc));
    277                 return rc;
    278         }
    279 
    280         if (sent_len < nblocks * bsize) {
     272                   mfun->usb_dev->ddf_dev->name, str_error(rc));
     273                return rc;
     274        }
     275
     276        if (sent_len < nblocks * mfun->block_size) {
    281277                usb_log_error("SCSI Write not all bytes transferred (%zu).\n",
    282278                    sent_len);
  • uspace/drv/bus/usb/usbmast/scsi_ms.h

    r89d3f3c7 r7190bbc  
    5959} usbmast_inquiry_data_t;
    6060
    61 extern int usbmast_inquiry(usb_device_t *, usbmast_inquiry_data_t *);
    62 extern int usbmast_request_sense(usb_device_t *, void *, size_t);
    63 extern int usbmast_read_capacity(usb_device_t *, uint32_t *, uint32_t *);
    64 extern int usbmast_read(usb_device_t *, uint64_t, size_t, size_t, void *);
    65 extern int usbmast_write(usb_device_t *, uint64_t, size_t, size_t,
    66     const void *);
     61extern int usbmast_inquiry(usbmast_fun_t *, usbmast_inquiry_data_t *);
     62extern int usbmast_request_sense(usbmast_fun_t *, void *, size_t);
     63extern int usbmast_read_capacity(usbmast_fun_t *, uint32_t *, uint32_t *);
     64extern int usbmast_read(usbmast_fun_t *, uint64_t, size_t, void *);
     65extern int usbmast_write(usbmast_fun_t *, uint64_t, size_t, const void *);
    6766extern const char *usbmast_scsi_dev_type_str(unsigned);
    6867
Note: See TracChangeset for help on using the changeset viewer.