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

Changeset 35b8bfe in mainline


Ignore:
Timestamp:
2014-08-16T13:05:28Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
3abf70c7
Parents:
8820544
Message:

ATAPI commands correspond to SCSI SPC, SBC and MMC commands (with a few quirks) so use libscsi.

Location:
uspace
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/ata_bd/ata_bd.c

    r8820544 r35b8bfe  
    5454#include <bd_srv.h>
    5555#include <fibril_synch.h>
     56#include <scsi/mmc.h>
    5657#include <scsi/sbc.h>
     58#include <scsi/spc.h>
    5759#include <stdint.h>
    5860#include <str.h>
     
    343345        identify_data_t idata;
    344346        uint8_t model[40];
    345         ata_inquiry_data_t inq_data;
     347        scsi_std_inquiry_data_t inq_data;
    346348        size_t isize;
    347349        uint16_t w;
     
    472474
    473475                /* Check device type. */
    474                 if (INQUIRY_PDEV_TYPE(inq_data.pdev_type) != PDEV_TYPE_CDROM)
     476                if (INQUIRY_PDEV_TYPE(inq_data.pqual_devtype) != SCSI_DEV_CD_DVD)
    475477                        ddf_msg(LVL_WARN, "Peripheral device type is not CD-ROM.");
    476478
     
    831833    size_t *rcvd_size)
    832834{
    833         ata_pcmd_inquiry_t cp;
     835        uint8_t cpb[12];
     836        scsi_cdb_inquiry_t *cp = (scsi_cdb_inquiry_t *)cpb;
    834837        int rc;
    835838
    836         memset(&cp, 0, sizeof(cp));
    837 
    838         cp.opcode = PCMD_INQUIRY;
    839         cp.alloc_len = min(obuf_size, 0xff); /* Allocation length */
    840 
    841         rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, rcvd_size);
     839        memset(cpb, 0, sizeof(cpb));
     840
     841        /*
     842         * For SFF 8020 compliance the inquiry must be padded to 12 bytes
     843         * and allocation length must fit in one byte.
     844         */
     845        cp->op_code = SCSI_CMD_INQUIRY;
     846
     847        /* Allocation length */
     848        cp->alloc_len = host2uint16_t_be(min(obuf_size, 0xff));
     849
     850        rc = ata_cmd_packet(disk, cpb, sizeof(cpb), obuf, obuf_size, rcvd_size);
    842851        if (rc != EOK)
    843852                return rc;
     
    894903    void *obuf, size_t obuf_size)
    895904{
    896         ata_pcmd_read_12_t cp;
     905        scsi_cdb_read_12_t cp;
    897906        int rc;
    898907
     
    902911        memset(&cp, 0, sizeof(cp));
    903912
    904         cp.opcode = PCMD_READ_12;
    905         cp.ba = host2uint32_t_be(ba);
    906         cp.nblocks = host2uint32_t_be(cnt);
     913        cp.op_code = SCSI_CMD_READ_12;
     914        cp.lba = host2uint32_t_be(ba);
     915        cp.xfer_len = host2uint32_t_be(cnt);
    907916
    908917        rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, NULL);
     
    933942    size_t obuf_size)
    934943{
    935         ata_pcmd_read_toc_t cp;
     944        uint8_t cpb[12];
     945        scsi_cdb_read_toc_t *cp = (scsi_cdb_read_toc_t *)cpb;
    936946        int rc;
    937947
    938         memset(&cp, 0, sizeof(cp));
    939 
    940         cp.opcode = PCMD_READ_TOC;
    941         cp.msf = 0;
    942         cp.format = 0x01; /* 0x01 = multi-session mode */
    943         cp.start = session;
    944         cp.size = host2uint16_t_be(obuf_size);
    945         cp.oldformat = 0x40; /* 0x01 = multi-session mode (shifted to MSB) */
    946        
    947         rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, NULL);
     948        memset(cpb, 0, sizeof(cpb));
     949
     950        cp->op_code = SCSI_CMD_READ_TOC;
     951        cp->msf = 0;
     952        cp->format = 0x01; /* 0x01 = multi-session mode */
     953        cp->track_sess_no = session;
     954        cp->alloc_len = host2uint16_t_be(obuf_size);
     955        cp->control = 0x40; /* 0x01 = multi-session mode (shifted to MSB) */
     956
     957        rc = ata_cmd_packet(disk, cpb, sizeof(cpb), obuf, obuf_size, NULL);
    948958        if (rc != EOK)
    949959                return rc;
    950        
     960
    951961        return EOK;
    952962}
  • uspace/drv/block/ata_bd/ata_hw.h

    r8820544 r35b8bfe  
    241241};
    242242
    243 /** ATA packet command codes. */
    244 enum ata_pkt_command {
    245         PCMD_INQUIRY            = 0x12,
    246         PCMD_READ_12            = 0xa8,
    247         PCMD_READ_TOC           = 0x43
    248 };
    249 
    250 /** ATAPI Inquiry command */
    251 typedef struct {
    252         uint8_t opcode;         /**< Operation code (PCMD_INQUIRY) */
    253         uint8_t _res0;
    254         uint8_t _res1;
    255         uint8_t _res2;
    256         uint8_t alloc_len;      /**< Allocation length */
    257         uint8_t _res3;
    258         uint8_t _res4;
    259         uint8_t _res5;
    260         uint32_t _res6;
    261 } __attribute__ ((packed)) ata_pcmd_inquiry_t;
    262 
    263 /** ATAPI Read(12) command */
    264 typedef struct {
    265         uint8_t opcode;         /**< Operation code (PCMD_READ_12) */
    266         uint8_t _res0;
    267         uint32_t ba;            /**< Starting block address */
    268         uint32_t nblocks;       /**< Number of blocks to transfer */
    269         uint8_t _res1;
    270         uint8_t _res2;
    271 } __attribute__ ((packed)) ata_pcmd_read_12_t;
    272 
    273 /** ATAPI Read TOC command */
    274 typedef struct {
    275         uint8_t opcode;         /**< Operation code (PCMD_READ_TOC) */
    276         uint8_t msf;            /**< 0x2 = MSF bit set */
    277         uint8_t format;         /**< low 3 bits */
    278         uint8_t _res0;
    279         uint8_t _res1;
    280         uint8_t _res2;
    281         uint8_t start;          /**< starting track/session number */
    282         uint16_t size;          /**< Allocation length */
    283         uint8_t oldformat;         /**< high 2 bits */
    284         uint8_t _res3;
    285         uint8_t _res4;
    286 } __attribute__ ((packed)) ata_pcmd_read_toc_t;
    287 
    288 /** Data returned from Inquiry command (mandatory part) */
    289 typedef struct {
    290         uint8_t pdev_type;      /** Reserved, Peripheral device type */
    291         uint8_t rmb;            /** RMB, Reserved */
    292         uint8_t std_version;    /** ISO version, ECMA version, ANSI version */
    293         uint8_t atapi_ver_rdf;  /** ATAPI version, Response data format */
    294         uint8_t additional_len; /** Additional length */
    295         uint8_t _res0;
    296         uint8_t _res1;
    297         uint8_t _res2;
    298         uint8_t vendor_id[8];   /** Vendor ID */
    299         uint8_t product_id[8];  /** Product ID */
    300         uint8_t product_rev[4]; /** Product revision level */
    301 } ata_inquiry_data_t;
    302 
    303 /** Extract value of ata_inquiry_data_t.pdev_type */
     243/** Extract value of device type from scsi_std_inquiry_data_t.pqual_devtype */
    304244#define INQUIRY_PDEV_TYPE(val) ((val) & 0x1f)
    305 
    306 /** Values for ata_inquiry_data_t.pdev_type */
    307 enum ata_pdev_type {
    308         PDEV_TYPE_CDROM         = 0x05
    309 };
    310245
    311246enum ata_pdev_signature {
  • uspace/lib/scsi/include/scsi/spc.h

    r8820544 r35b8bfe  
    4646};
    4747
    48 /** SCSI Inquiry command */
     48/** SCSI Inquiry command
     49 *
     50 * Note: for SFF 8020 the command must be zero-padded to 12 bytes
     51 * and alloc_len must be <= 0xff.
     52 */
    4953typedef struct {
    5054        /** Operation code (SCSI_CMD_INQUIRY) */
Note: See TracChangeset for help on using the changeset viewer.