Fork us on GitHub Follow us on Facebook Follow us on Twitter

Ignore:
Timestamp:
2011-07-24T18:09:09Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
1bfae13, 358dc13, eff10e03
Parents:
582fe388
Message:

Allow simpler passing around / processing of SCSI commands by creating
scsi_cmd_t structure which holds input and output arguments of a SCSI
command and is loosely modeled after the SAM-4 Execute Command procedure
call.

File:
1 edited

Legend:

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

    r582fe388 rde3432b  
    5858 * @param tag           Command block wrapper tag (automatically compared
    5959 *                      with answer)
    60  * @param cmd           Command block
    61  * @param cmd_size      Command block size in bytes
    62  * @param ddir          Direction in which data will be transferred
    63  * @param dbuf          Data send/receive buffer
    64  * @param dbuf_size     Size of the data buffer
    65  * @param xferred_size  Number of bytes actually transferred
    66  * @param cmd_status    Command status
     60 * @param cmd           SCSI command
    6761 *
    6862 * @return              Error code
    6963 */
    70 static int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, const void *cmd,
    71     size_t cmd_size, usb_direction_t ddir, void *dbuf, size_t dbuf_size,
    72     size_t *xferred_size, cmd_status_t *cmd_status)
     64int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, scsi_cmd_t *cmd)
    7365{
    7466        int rc;
     
    7769        usb_pipe_t *bulk_in_pipe = mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe;
    7870        usb_pipe_t *bulk_out_pipe = mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe;
     71        usb_direction_t ddir;
     72        void *dbuf;
     73        size_t dbuf_size;
     74
     75        if (cmd->data_out != NULL && cmd->data_in == NULL) {
     76                ddir = USB_DIRECTION_OUT;
     77                dbuf = (void *)cmd->data_out;
     78                dbuf_size = cmd->data_out_size;
     79        } else if (cmd->data_out == NULL && cmd->data_in != NULL) {
     80                ddir = USB_DIRECTION_IN;
     81                dbuf = cmd->data_in;
     82                dbuf_size = cmd->data_in_size;
     83        } else {
     84                assert(false);
     85        }
    7986
    8087        /* Prepare CBW - command block wrapper */
    8188        usb_massstor_cbw_t cbw;
    8289        usb_massstor_cbw_prepare(&cbw, tag, dbuf_size, ddir, mfun->lun,
    83             cmd_size, cmd);
     90            cmd->cdb_size, cmd->cdb);
    8491
    8592        /* Send the CBW. */
     
    148155        switch (csw.dCSWStatus) {
    149156        case cbs_passed:
    150                 *cmd_status = CMDS_GOOD;
     157                cmd->status = CMDS_GOOD;
    151158                break;
    152159        case cbs_failed:
    153160                MASTLOG("Command failed\n");
    154                 *cmd_status = CMDS_FAILED;
     161                cmd->status = CMDS_FAILED;
    155162                break;
    156163        case cbs_phase_error:
     
    177184         */
    178185
    179         if (xferred_size != NULL)
    180                 *xferred_size = dbuf_size - residue;
     186        if (ddir == USB_DIRECTION_IN)
     187                cmd->rcvd_size = dbuf_size - residue;
    181188
    182189        return retval;
    183 }
    184 
    185 /** Perform data-in command.
    186  *
    187  * @param mfun          Mass storage function
    188  * @param tag           Command block wrapper tag (automatically compared with
    189  *                      answer)
    190  * @param cmd           CDB (Command Descriptor)
    191  * @param cmd_size      CDB length in bytes
    192  * @param dbuf          Data receive buffer
    193  * @param dbuf_size     Data receive buffer size in bytes
    194  * @param proc_size     Number of bytes actually processed by device
    195  * @param cmd_status    Command status
    196  *
    197  * @return Error code
    198  */
    199 int usb_massstor_data_in(usbmast_fun_t *mfun, uint32_t tag, const void *cmd,
    200     size_t cmd_size, void *dbuf, size_t dbuf_size, size_t *proc_size,
    201     cmd_status_t *cmd_status)
    202 {
    203         return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_IN,
    204             dbuf, dbuf_size, proc_size, cmd_status);
    205 }
    206 
    207 /** Perform data-out command.
    208  *
    209  * @param mfun          Mass storage function
    210  * @param tag           Command block wrapper tag (automatically compared with
    211  *                      answer)
    212  * @param cmd           CDB (Command Descriptor)
    213  * @param cmd_size      CDB length in bytes
    214  * @param data          Command data
    215  * @param data_size     Size of @a data in bytes
    216  * @param proc_size     Number of bytes actually processed by device
    217  * @param cmd_status    Command status
    218  *
    219  * @return Error code
    220  */
    221 int usb_massstor_data_out(usbmast_fun_t *mfun, uint32_t tag, const void *cmd,
    222     size_t cmd_size, const void *data, size_t data_size, size_t *proc_size,
    223     cmd_status_t *cmd_status)
    224 {
    225         return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_OUT,
    226             (void *) data, data_size, proc_size, cmd_status);
    227190}
    228191
Note: See TracChangeset for help on using the changeset viewer.