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

Changeset dd8b6a8 in mainline


Ignore:
Timestamp:
2014-08-27T23:56:16Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
95fe55c
Parents:
f27f3fd
Message:

Add synchronize cache operation to block layer and usbmast.

Location:
uspace
Files:
10 edited

Legend:

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

    rf27f3fd rdd8b6a8  
    8585static int usbmast_bd_close(bd_srv_t *);
    8686static int usbmast_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
     87static int usbmast_bd_sync_cache(bd_srv_t *, aoff64_t, size_t);
    8788static int usbmast_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
    8889static int usbmast_bd_get_block_size(bd_srv_t *, size_t *);
     
    9394        .close = usbmast_bd_close,
    9495        .read_blocks = usbmast_bd_read_blocks,
     96        .sync_cache = usbmast_bd_sync_cache,
    9597        .write_blocks = usbmast_bd_write_blocks,
    9698        .get_block_size = usbmast_bd_get_block_size,
     
    338340}
    339341
     342/** Synchronize blocks to nonvolatile storage. */
     343static int usbmast_bd_sync_cache(bd_srv_t *bd, uint64_t ba, size_t cnt)
     344{
     345        usbmast_fun_t *mfun = bd_srv_usbmast(bd);
     346
     347        return usbmast_sync_cache(mfun, ba, cnt);
     348}
     349
    340350/** Write blocks to the device. */
    341351static int usbmast_bd_write_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt,
  • uspace/drv/bus/usb/usbmast/scsi_ms.c

    rf27f3fd rdd8b6a8  
    383383}
    384384
     385/** Perform SCSI Synchronize Cache command on USB mass storage device.
     386 *
     387 * @param mfun          Mass storage function
     388 * @param ba            Address of first block
     389 * @param nblocks       Number of blocks to read
     390 * @param data          Data to write
     391 *
     392 * @return              Error code
     393 */
     394int usbmast_sync_cache(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks)
     395{
     396        scsi_cmd_t cmd;
     397        scsi_cdb_sync_cache_10_t cdb;
     398        int rc;
     399
     400        if (ba > UINT32_MAX)
     401                return ELIMIT;
     402
     403        if (nblocks > UINT16_MAX)
     404                return ELIMIT;
     405
     406        memset(&cdb, 0, sizeof(cdb));
     407        cdb.op_code = SCSI_CMD_SYNC_CACHE_10;
     408        cdb.lba = host2uint32_t_be(ba);
     409        cdb.numlb = host2uint16_t_be(nblocks);
     410
     411        memset(&cmd, 0, sizeof(cmd));
     412        cmd.cdb = &cdb;
     413        cmd.cdb_size = sizeof(cdb);
     414
     415        rc = usbmast_run_cmd(mfun, &cmd);
     416
     417        if (rc != EOK) {
     418                usb_log_error("Synchronize Cache (10) transport failed, device %s: %s.\n",
     419                   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
     420                return rc;
     421        }
     422
     423        if (cmd.status != CMDS_GOOD) {
     424                usb_log_error("Synchronize Cache (10) command failed, device %s.\n",
     425                   ddf_dev_get_name(mfun->mdev->ddf_dev));
     426                return EIO;
     427        }
     428
     429        return EOK;
     430}
     431
    385432/**
    386433 * @}
  • uspace/drv/bus/usb/usbmast/scsi_ms.h

    rf27f3fd rdd8b6a8  
    6464extern int usbmast_read(usbmast_fun_t *, uint64_t, size_t, void *);
    6565extern int usbmast_write(usbmast_fun_t *, uint64_t, size_t, const void *);
     66extern int usbmast_sync_cache(usbmast_fun_t *, uint64_t, size_t);
    6667extern const char *usbmast_scsi_dev_type_str(unsigned);
    6768
  • uspace/lib/block/block.c

    rf27f3fd rdd8b6a8  
    194194        if (devcon->cache)
    195195                (void) block_cache_fini(service_id);
     196       
     197        (void)bd_sync_cache(devcon->bd, 0, 0);
    196198       
    197199        devcon_remove(devcon);
  • uspace/lib/c/generic/bd.c

    rf27f3fd rdd8b6a8  
    150150}
    151151
     152int bd_sync_cache(bd_t *bd, aoff64_t ba, size_t cnt)
     153{
     154        async_exch_t *exch = async_exchange_begin(bd->sess);
     155
     156        int rc = async_req_3_0(exch, BD_SYNC_CACHE, LOWER32(ba),
     157            UPPER32(ba), cnt);
     158        async_exchange_end(exch);
     159
     160        return rc;
     161}
     162
    152163int bd_get_block_size(bd_t *bd, size_t *rbsize)
    153164{
  • uspace/lib/c/generic/bd_srv.c

    rf27f3fd rdd8b6a8  
    128128}
    129129
     130static void bd_sync_cache_srv(bd_srv_t *srv, ipc_callid_t callid,
     131    ipc_call_t *call)
     132{
     133        aoff64_t ba;
     134        size_t cnt;
     135        int rc;
     136
     137        ba = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
     138        cnt = IPC_GET_ARG3(*call);
     139
     140        if (srv->srvs->ops->sync_cache == NULL) {
     141                async_answer_0(callid, ENOTSUP);
     142                return;
     143        }
     144
     145        rc = srv->srvs->ops->sync_cache(srv, ba, cnt);
     146        async_answer_0(callid, rc);
     147}
     148
    130149static void bd_write_blocks_srv(bd_srv_t *srv, ipc_callid_t callid,
    131150    ipc_call_t *call)
     
    244263                        bd_read_toc_srv(srv, callid, &call);
    245264                        break;
     265                case BD_SYNC_CACHE:
     266                        bd_sync_cache_srv(srv, callid, &call);
     267                        break;
    246268                case BD_WRITE_BLOCKS:
    247269                        bd_write_blocks_srv(srv, callid, &call);
  • uspace/lib/c/include/bd.h

    rf27f3fd rdd8b6a8  
    4848extern int bd_read_toc(bd_t *, uint8_t, void *, size_t);
    4949extern int bd_write_blocks(bd_t *, aoff64_t, size_t, const void *, size_t);
     50extern int bd_sync_cache(bd_t *, aoff64_t, size_t);
    5051extern int bd_get_block_size(bd_t *, size_t *);
    5152extern int bd_get_num_blocks(bd_t *, aoff64_t *);
  • uspace/lib/c/include/bd_srv.h

    rf27f3fd rdd8b6a8  
    6262        int (*read_blocks)(bd_srv_t *, aoff64_t, size_t, void *, size_t);
    6363        int (*read_toc)(bd_srv_t *, uint8_t, void *, size_t);
     64        int (*sync_cache)(bd_srv_t *, aoff64_t, size_t);
    6465        int (*write_blocks)(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
    6566        int (*get_block_size)(bd_srv_t *, size_t *);
  • uspace/lib/c/include/ipc/bd.h

    rf27f3fd rdd8b6a8  
    4242        BD_GET_NUM_BLOCKS,
    4343        BD_READ_BLOCKS,
     44        BD_SYNC_CACHE,
    4445        BD_WRITE_BLOCKS,
    4546        BD_READ_TOC
  • uspace/lib/scsi/include/scsi/sbc.h

    rf27f3fd rdd8b6a8  
    5050        SCSI_CMD_READ_CAPACITY_16       = 0x9e,
    5151
     52        SCSI_CMD_SYNC_CACHE_10          = 0x35,
     53        SCSI_CMD_SYNC_CACHE_16          = 0x91,
     54
    5255        SCSI_CMD_WRITE_6                = 0x0a,
    5356        SCSI_CMD_WRITE_10               = 0x2a,
     
    131134} scsi_read_capacity_10_data_t;
    132135
     136/** SCSI Synchronize Cache (10) command */
     137typedef struct {
     138        /** Operation code (SCSI_CMD_SYNC_CACHE_10) */
     139        uint8_t op_code;
     140        /** Reserved, Sync_NV, Immed, Reserved */
     141        uint8_t flags;
     142        /** Logical block address */
     143        uint32_t lba;
     144        /** Reserved, Group Number */
     145        uint8_t group_no;
     146        /** Number of Logical Blocks */
     147        uint16_t numlb;
     148        /** Control */
     149        uint8_t control;
     150} __attribute__((packed)) scsi_cdb_sync_cache_10_t;
     151
     152/** SCSI Synchronize Cache (16) command */
     153typedef struct {
     154        /** Operation code (SCSI_CMD_SYNC_CACHE_16) */
     155        uint8_t op_code;
     156        /** Reserved, Sync_NV, Immed, Reserved */
     157        uint8_t flags;
     158        /** Logical block address */
     159        uint64_t lba;
     160        /** Number of Logical Blocks */
     161        uint32_t numlb;
     162        /** Reserved, Group Number */
     163        uint8_t group_no;
     164        /** Control */
     165        uint8_t control;
     166} __attribute__((packed)) scsi_cdb_sync_cache_16_t;
     167
    133168/** SCSI Write (10) command */
    134169typedef struct {
Note: See TracChangeset for help on using the changeset viewer.