Changeset 0feaae4 in mainline


Ignore:
Timestamp:
2011-07-02T17:21:50Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
239e7e10
Parents:
2429e4a
Message:

Factor out standard SCSI code from usbmast to a separate SCSI library.

Location:
uspace
Files:
2 added
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    r2429e4a r0feaae4  
    165165        lib/block \
    166166        lib/clui \
     167        lib/scsi \
    167168        lib/softint \
    168169        lib/softfloat \
  • uspace/Makefile.common

    r2429e4a r0feaae4  
    120120LIBNET_PREFIX = $(LIB_PREFIX)/net
    121121
     122LIBSCSI_PREFIX = $(LIB_PREFIX)/scsi
     123
    122124ifeq ($(STATIC_NEEDED),y)
    123125        STATIC_BUILD = y
  • uspace/drv/bus/usb/usbmast/Makefile

    r2429e4a r0feaae4  
    3232        $(LIBUSBDEV_PREFIX)/libusbdev.a \
    3333        $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
     34        $(LIBDRV_PREFIX)/libdrv.a \
     35        $(LIBSCSI_PREFIX)/libscsi.a
    3536
    3637EXTRA_CFLAGS += \
    3738        -I$(LIBUSB_PREFIX)/include \
    3839        -I$(LIBUSBDEV_PREFIX)/include \
    39         -I$(LIBDRV_PREFIX)/include
     40        -I$(LIBDRV_PREFIX)/include \
     41        -I$(LIBSCSI_PREFIX)/include
    4042
    4143BINARY = usbmast
  • uspace/drv/bus/usb/usbmast/inquiry.c

    r2429e4a r0feaae4  
    4242#include <str.h>
    4343#include <ctype.h>
     44#include <scsi/spc.h>
    4445#include "cmds.h"
    45 #include "scsi.h"
    4646#include "mast.h"
    4747
     
    5454#define INQUIRY_RESPONSE_LENGTH 36
    5555
    56 #define STR_UNKNOWN "<unknown>"
    57 
    58 /** String constants for SCSI peripheral device types. */
    59 static const char *str_peripheral_device_types[] = {
    60         "direct-access device",
    61         "sequential-access device",
    62         "printer device",
    63         "processor device",
    64         "write-once device",
    65         "CDROM device",
    66         "scanner device",
    67         "optical memory device",
    68         "medium changer",
    69         "communications device",
    70         "graphic arts pre-press device",
    71         "graphic arts pre-press device",
    72         "storage array controller device",
    73         "enclosure services device",
    74         "simplified direct-access device",
    75         "optical card reader/writer device",
    76         "bridging expander",
    77         "object-based storage device",
    78         "automation driver interface",
    79         STR_UNKNOWN, // 0x13
    80         STR_UNKNOWN, // 0x14
    81         STR_UNKNOWN, // 0x15
    82         STR_UNKNOWN, // 0x16
    83         STR_UNKNOWN, // 0x17
    84         STR_UNKNOWN, // 0x18
    85         STR_UNKNOWN, // 0x19
    86         STR_UNKNOWN, // 0x1A
    87         STR_UNKNOWN, // 0x1B
    88         STR_UNKNOWN, // 0x1C
    89         STR_UNKNOWN, // 0x1D
    90         "well-known logical unit",
    91         "uknown or no device state"
    92 };
    93 #define str_peripheral_device_types_count \
    94         (sizeof(str_peripheral_device_types)/sizeof(str_peripheral_device_types[0]))
    95 
    9656/** Get string representation for SCSI peripheral device type.
    97  *
    98  * See for example here for a list
    99  * http://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type.
    10057 *
    10158 * @param type SCSI peripheral device type code.
    10259 * @return String representation.
    10360 */
    104 const char *usb_str_masstor_scsi_peripheral_device_type(int type)
     61const char *usb_str_masstor_scsi_peripheral_device_type(unsigned type)
    10562{
    106         if ((type < 0)
    107             || ((size_t)type >= str_peripheral_device_types_count)) {
    108                 return STR_UNKNOWN;
    109         }
    110         return str_peripheral_device_types[type];
     63        return scsi_get_dev_type_str(type);
    11164}
    11265
     
    13689    usb_massstor_inquiry_result_t *inquiry_result)
    13790{
    138         scsi_cmd_inquiry_t inquiry = {
    139                 .op_code = 0x12,
    140                 .lun_evpd = 0,
     91        scsi_cdb_inquiry_t inquiry = {
     92                .op_code = SCSI_CMD_INQUIRY,
     93                .evpd = 0,
    14194                .page_code = 0,
    142                 .alloc_length = host2uint16_t_be(INQUIRY_RESPONSE_LENGTH),
    143                 .ctrl = 0
     95                .alloc_len = host2uint16_t_be(INQUIRY_RESPONSE_LENGTH),
     96                .control = 0
    14497        };
    14598        size_t response_len;
  • uspace/drv/bus/usb/usbmast/main.c

    r2429e4a r0feaae4  
    4141#include <str_error.h>
    4242#include "cmds.h"
    43 #include "scsi.h"
    4443#include "mast.h"
    4544
     
    107106            (size_t) dev->pipes[BULK_OUT_EP].descriptor->max_packet_size);
    108107
     108/*      usb_log_debug("Get LUN count...\n");
    109109        size_t lun_count = usb_masstor_get_lun_count(dev);
    110 
     110  */ size_t lun_count=1;
     111        usb_log_debug("Inquire...\n");
    111112        usb_massstor_inquiry_result_t inquiry;
    112113        rc = usb_massstor_inquiry(dev, BULK_IN_EP, BULK_OUT_EP, &inquiry);
    113114        if (rc != EOK) {
    114                 usb_log_warning("Failed to inquiry device `%s': %s.\n",
     115                usb_log_warning("Failed to inquire device `%s': %s.\n",
    115116                    dev->ddf_dev->name, str_error(rc));
    116117                return EOK;
  • uspace/drv/bus/usb/usbmast/mast.h

    r2429e4a r0feaae4  
    6565int usb_massstor_inquiry(usb_device_t *, size_t, size_t,
    6666    usb_massstor_inquiry_result_t *);
    67 const char *usb_str_masstor_scsi_peripheral_device_type(int);
     67const char *usb_str_masstor_scsi_peripheral_device_type(unsigned);
    6868
    6969#endif
  • uspace/lib/scsi/include/scsi/spc.h

    r2429e4a r0feaae4  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup drvusbmast
     29/** @addtogroup libscsi
    3030 * @{
    3131 */
    32 /** @file
    33  * SCSI related structures.
     32/**
     33 * @file SCSI Primary Commands.
    3434 */
    3535
    36 #ifndef USB_USBMAST_SCSI_H_
    37 #define USB_USBMAST_SCSI_H_
     36#ifndef LIBSCSI_SPC_H_
     37#define LIBSCSI_SPC_H_
    3838
    39 #include <sys/types.h>
    40 #include <usb/usb.h>
     39#include <stdint.h>
    4140
     41/** SCSI command codes defined in SCSI-SPC */
     42enum scsi_cmd_spc {
     43        SCSI_CMD_INQUIRY        = 0x12
     44};
     45
     46/** SCSI Inquiry command */
    4247typedef struct {
     48        /** Operation code (12h, SCSI_CMD_INQUIRY) */
    4349        uint8_t op_code;
    44         uint8_t lun_evpd;
     50        /** Reserved:7-2, obsolete:1, evpd:0 */
     51        uint8_t evpd;
     52        /* Page Code */
    4553        uint8_t page_code;
    46         uint16_t alloc_length;
    47         uint8_t ctrl;
    48 } __attribute__((packed)) scsi_cmd_inquiry_t;
     54        /* Allocation Length */
     55        uint16_t alloc_len;
     56        /* Control */
     57        uint8_t control;
     58} __attribute__((packed)) scsi_cdb_inquiry_t;
     59
     60/** SCSI peripheral device type */
     61enum scsi_device_type {
     62        SCSI_DEV_BLOCK          = 0x00,
     63        SCSI_DEV_STREAM         = 0x01,
     64        SCSI_DEV_CD_DVD         = 0x05,
     65        SCSI_DEV_CHANGER        = 0x08,
     66        SCSI_DEV_ENCLOSURE      = 0x0d,
     67        SCSI_DEV_OSD            = 0x11,
     68
     69        SCSI_DEV_LIMIT          = 0x20
     70};
     71
     72extern const char *scsi_dev_type_str[SCSI_DEV_LIMIT];
     73extern const char *scsi_get_dev_type_str(unsigned);
    4974
    5075#endif
    5176
    52 /**
    53  * @}
     77/** @}
    5478 */
Note: See TracChangeset for help on using the changeset viewer.