source: mainline/uspace/lib/scsi/include/scsi/spc.h@ dcb74c0a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dcb74c0a was dcb74c0a, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Add function to str.c to convert space-padded ASCII to standard string
representation. Use for decoding SCSI strings.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libscsi
30 * @{
31 */
32/**
33 * @file SCSI Primary Commands.
34 */
35
36#ifndef LIBSCSI_SPC_H_
37#define LIBSCSI_SPC_H_
38
39#include <stdint.h>
40#include <str.h>
41
42/** SCSI command codes defined in SCSI-SPC */
43enum scsi_cmd_spc {
44 SCSI_CMD_INQUIRY = 0x12
45};
46
47/** SCSI Inquiry command */
48typedef struct {
49 /** Operation code (12h, SCSI_CMD_INQUIRY) */
50 uint8_t op_code;
51 /** Reserved:7-2, obsolete:1, evpd:0 */
52 uint8_t evpd;
53 /* Page Code */
54 uint8_t page_code;
55 /* Allocation Length */
56 uint16_t alloc_len;
57 /* Control */
58 uint8_t control;
59} __attribute__((packed)) scsi_cdb_inquiry_t;
60
61/** Minimum size of inquiry data required since SCSI-2 */
62#define SCSI_STD_INQUIRY_DATA_MIN_SIZE 36
63
64/** Standard inquiry data.
65 *
66 * Returned for Inquiry command with evpd bit cleared.
67 */
68typedef struct {
69 /** Peripheral qualifier, Peripheral device type */
70 uint8_t pqual_devtype;
71 /** RMB, reserved */
72 uint8_t rmb;
73 /** Version */
74 uint8_t version;
75 /** Obsolete, NormACA, HiSup, Response Data Format */
76 uint8_t aca_hisup_rdf;
77 /** Additional Length */
78 uint8_t additional_len;
79 /** SCCS, ACC, TPGS, 3PC, Reserved, Protect */
80 uint8_t cap1;
81 /** Obsolete, EncServ, VS, MuliP, Obsolete, Addr16 */
82 uint8_t cap2;
83 /** Obsolete, WBus16, Sync, Obsolete, CmdQue, VS */
84 uint8_t cap3;
85
86 /** Vendor string */
87 uint8_t vendor[8];
88 /** Product string */
89 uint8_t product[16];
90 /** Revision string */
91 uint8_t revision[4];
92
93 /* End of required data */
94} scsi_std_inquiry_data_t;
95
96/** Size of struct or union member. */
97#define SCSI_MEMBER_SIZE(type, member) \
98 (sizeof(((type *)0) -> member))
99
100/** Size of string buffer needed to hold converted inquiry vendor string */
101#define SCSI_INQ_VENDOR_STR_BUFSIZE \
102 SPASCII_STR_BUFSIZE(SCSI_MEMBER_SIZE(scsi_std_inquiry_data_t, vendor))
103
104/** Size of string buffer needed to hold converted inquiry product string */
105#define SCSI_INQ_PRODUCT_STR_BUFSIZE \
106 SPASCII_STR_BUFSIZE(SCSI_MEMBER_SIZE(scsi_std_inquiry_data_t, product))
107
108/** Size of string buffer needed to hold converted inquiry revision string */
109#define SCSI_INQ_REVISION_STR_BUFSIZE \
110 SPASCII_STR_BUFSIZE(SCSI_MEMBER_SIZE(scsi_std_inquiry_data_t, revision))
111
112/** Bits in scsi_std_inquiry_data_t.pqual_devtype */
113enum scsi_pqual_devtype_bits {
114 /* Peripheral qualifier */
115 SCSI_PQDT_PQUAL_h = 7,
116 SCSI_PQDT_PQUAL_l = 5,
117
118 /* Peripheral device type */
119 SCSI_PQDT_DEV_TYPE_h = 4,
120 SCSI_PQDT_DEV_TYPE_l = 0
121};
122
123/** Bits in scsi_std_inquiry_data_t.rmb */
124enum scsi_rmb_bits {
125 SCSI_RMB_RMB = 7
126};
127
128/** SCSI peripheral device type */
129enum scsi_device_type {
130 SCSI_DEV_BLOCK = 0x00,
131 SCSI_DEV_STREAM = 0x01,
132 SCSI_DEV_CD_DVD = 0x05,
133 SCSI_DEV_CHANGER = 0x08,
134 SCSI_DEV_ENCLOSURE = 0x0d,
135 SCSI_DEV_OSD = 0x11,
136
137 SCSI_DEV_LIMIT = 0x20
138};
139
140extern const char *scsi_dev_type_str[SCSI_DEV_LIMIT];
141extern const char *scsi_get_dev_type_str(unsigned);
142
143#endif
144
145/** @}
146 */
Note: See TracBrowser for help on using the repository browser.