]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/nusb/disk/ums.h
add nusb/cam
[plan9front.git] / sys / src / cmd / nusb / disk / ums.h
1 /*
2  * mass storage transport protocols and subclasses,
3  * from usb mass storage class specification overview rev 1.2
4  */
5
6 typedef struct Umsc Umsc;
7 typedef struct Ums Ums;
8 typedef struct Cbw Cbw;                 /* command block wrapper */
9 typedef struct Csw Csw;                 /* command status wrapper */
10 typedef struct Part Part;
11
12 enum
13 {
14         Protocbi =      0,      /* control/bulk/interrupt; mainly floppies */
15         Protocb =       1,      /*   "  with no interrupt; mainly floppies */
16         Protobulk =     0x50,   /* bulk only */
17
18         Subrbc =        1,      /* reduced blk cmds */
19         Subatapi =      2,      /* cd/dvd using sff-8020i or mmc-2 cmd blks */
20         Subqic  =       3,      /* QIC-157 tapes */
21         Subufi =        4,      /* floppy */
22         Sub8070 =       5,      /* removable media, atapi-like */
23         Subscsi =       6,      /* scsi transparent cmd set */
24         Subisd200 =     7,      /* ISD200 ATA */
25         Subdev =        0xff,   /* use device's value */
26
27         Umsreset =      0xFF,
28         Getmaxlun =     0xFE,
29
30 //      Maxlun          = 256,
31         Maxlun          = 32,
32
33         CMreset = 1,
34
35         Pcmd = 0,
36         Pdata,
37         Pstatus,
38
39         CbwLen          = 31,
40         CbwDataIn       = 0x80,
41         CbwDataOut      = 0x00,
42         CswLen          = 13,
43         CswOk           = 0,
44         CswFailed       = 1,
45         CswPhaseErr     = 2,
46         
47         Maxparts                = 16,
48 };
49
50 /*
51  * corresponds to a lun.
52  * these are ~600+Maxiosize bytes each; ScsiReq is not tiny.
53  */
54
55 struct Part
56 {
57         int id;
58         int inuse;
59         int vers;
60         ulong mode;
61         char    *name;
62         vlong offset;           /* in lbsize units */
63         vlong length;           /* in lbsize units */
64 };
65
66
67 struct Umsc
68 {
69         ScsiReq;
70         char name[40];
71         uvlong  blocks;
72         vlong   capacity;
73
74         /* from setup */
75         char    *bufp;
76         long    off;            /* offset within a block */
77         long    nb;             /* byte count */
78
79         QLock;
80
81         /* partitions */
82         Part part[Maxparts];
83
84         uchar   rawcmd[16];
85         uchar   phase;
86         char    *inq;
87         Ums     *ums;
88         char    buf[Maxiosize];
89 };
90
91 struct Ums
92 {
93         Dev     *epin;
94         Dev     *epout;
95         Umsc    *lun;
96         uchar   maxlun;
97         int     seq;
98         int     nerrs;
99         int     wrongresidues;
100 };
101
102 /*
103  * USB transparent SCSI devices
104  */
105 struct Cbw
106 {
107         char    signature[4];           /* "USBC" */
108         long    tag;
109         long    datalen;
110         uchar   flags;
111         uchar   lun;
112         uchar   len;
113         char    command[16];
114 };
115
116 struct Csw
117 {
118         char    signature[4];           /* "USBS" */
119         long    tag;
120         long    dataresidue;
121         uchar   status;
122 };