Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: scsi.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)scsi.fth 1.1 07/01/04 | |
43 | purpose: USB Mass Storage Device Driver | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | \ See license at end of file | |
46 | ||
47 | headers | |
48 | hex | |
49 | ||
50 | 0 value max-lun | |
51 | 0 instance value lun | |
52 | ||
53 | USB_ERR_STALL constant bus-reset | |
54 | ||
55 | defer execute-command-hook ' noop to execute-command-hook | |
56 | defer init-execute-command ' noop to init-execute-command | |
57 | ||
58 | ||
59 | \ Class specific >dr-request constants | |
60 | h# ff constant DEV_RESET | |
61 | h# fe constant GET_MAX_LUN | |
62 | ||
63 | \ Command Block Wrapper | |
64 | struct | |
65 | 4 field >cbw-sig | |
66 | 4 field >cbw-tag | |
67 | 4 field >cbw-dlen | |
68 | 1 field >cbw-flag | |
69 | 1 field >cbw-lun | |
70 | 1 field >cbw-cblen | |
71 | h# 10 field >cbw-cb | |
72 | constant /cbw | |
73 | ||
74 | \ >cbw-flag definitions | |
75 | 80 constant cbw-flag-in | |
76 | 00 constant cbw-flag-out | |
77 | ||
78 | \ Command Status Wrapper | |
79 | struct | |
80 | 4 field >csw-sig | |
81 | 4 field >csw-tag | |
82 | 4 field >csw-dlen | |
83 | 1 field >csw-stat | |
84 | constant /csw | |
85 | ||
86 | h# 43425355 constant cbw-signature \ little-endian | |
87 | h# 53425355 constant csw-signature \ little-endian | |
88 | ||
89 | 0 value cbw-tag | |
90 | 0 value cbw | |
91 | 0 value csw | |
92 | ||
93 | : init-cbw ( -- ) | |
94 | cbw /cbw erase | |
95 | cbw-signature cbw >cbw-sig le-l! | |
96 | cbw-tag 1+ to cbw-tag | |
97 | cbw-tag cbw >cbw-tag le-l! | |
98 | ; | |
99 | : alloc-bulk ( -- ) | |
100 | cbw 0= if /cbw dma-alloc to cbw then | |
101 | csw 0= if /csw dma-alloc to csw then | |
102 | ; | |
103 | : free-bulk ( -- ) | |
104 | cbw if cbw /cbw dma-free 0 to cbw then | |
105 | csw if csw /csw dma-free 0 to csw then | |
106 | ; | |
107 | ||
108 | 1 buffer: max-lun-buf | |
109 | ||
110 | : get-max-lun ( -- ) | |
111 | max-lun-buf 1 my-address ( interface ) 0 DR_IN DR_CLASS DR_INTERFACE or or | |
112 | GET_MAX_LUN control-get if ( actual usberr ) | |
113 | drop 0 | |
114 | else | |
115 | ( actual ) if max-lun-buf c@ else 0 then | |
116 | then | |
117 | to max-lun | |
118 | ; | |
119 | ||
120 | : init ( -- ) | |
121 | init | |
122 | init-execute-command | |
123 | alloc-bulk | |
124 | device set-target | |
125 | configuration set-config if ." Failed to set storage configuration" cr then | |
126 | get-max-lun | |
127 | free-bulk | |
128 | ; | |
129 | ||
130 | : transport-reset ( -- ) | |
131 | 0 0 my-address ( interface ) 0 DR_OUT DR_CLASS DR_INTERFACE or or | |
132 | DEV_RESET control-set-nostat drop | |
133 | \ XXX Wait until devices does not NAK anymore | |
134 | bulk-in-pipe h# 80 or unstall-pipe | |
135 | bulk-out-pipe unstall-pipe | |
136 | ; | |
137 | ||
138 | : wrap-cbw ( data-len dir cmd-adr,len -- cbw-adr,len ) | |
139 | init-cbw ( data-len dir cmd-adr,len ) | |
140 | cbw >r ( data-len dir cmd-adr,len ) ( R: cbw ) | |
141 | dup r@ >cbw-cblen c! ( data-len dir cmd-adr,len ) ( R: cbw ) | |
142 | r@ >cbw-cb swap move ( data-len dir ) ( R: cbw ) | |
143 | if cbw-flag-in else cbw-flag-out then ( data-len cbw-flag ) ( R: cbw ) | |
144 | r@ >cbw-flag c! ( data-len ) ( R: cbw ) | |
145 | r@ >cbw-dlen le-l! ( ) ( R: cbw ) | |
146 | lun r@ >cbw-lun c! ( ) ( R: cbw ) | |
147 | r> /cbw ( cbw-adr,len ) | |
148 | ; | |
149 | ||
150 | : (get-csw) ( -- len usberr ) csw /csw bulk-in-pipe bulk-in ; | |
151 | : get-csw ( -- len usberr ) | |
152 | (get-csw) dup if 2drop (get-csw) then | |
153 | ; | |
154 | ||
155 | d# 15,000 constant bulk-timeout | |
156 | ||
157 | : (execute-command) ( data-adr,len dir cbw-adr,len -- hwresult | statbyte 0 ) | |
158 | debug? if | |
159 | 2dup " dump" evaluate cr | |
160 | then | |
161 | ||
162 | bulk-out-pipe bulk-out ( data-adr,len dir usberr ) | |
163 | USB_ERR_CRC invert and ( data-adr,len dir usberr' ) | |
164 | ?dup if nip nip nip exit then ( data-adr,len dir ) | |
165 | ||
166 | over if | |
167 | if ( data-adr,len ) | |
168 | bulk-in-pipe bulk-in 2drop ( ) | |
169 | else | |
170 | bulk-out-pipe bulk-out drop ( ) | |
171 | then | |
172 | else ( data-adr,len dir ) | |
173 | drop 2drop ( ) | |
174 | then | |
175 | ||
176 | get-csw ( len usberr ) | |
177 | ?dup if nip exit then | |
178 | debug? if | |
179 | csw /csw " dump" evaluate cr | |
180 | then | |
181 | ||
182 | drop csw >csw-stat c@ ( cswStatus ) | |
183 | case | |
184 | 0 of 0 0 endof \ No error | |
185 | 1 of 2 0 endof \ Error, "check condition" | |
186 | 2 of transport-reset \ Phase error, reset recovery | |
187 | USB_ERR_STALL endof | |
188 | ( default ) 0 0 rot \ Reserved error | |
189 | endcase | |
190 | ; | |
191 | ||
192 | external | |
193 | ||
194 | : execute-command ( data-adr,len dir cmd-adr,len -- hwresult | statbyte 0 ) | |
195 | execute-command-hook | |
196 | over c@ h# 1b = 2 pick 4 + c@ 1 = and >r \ Start command? | |
197 | 2over 2swap wrap-cbw ( data-adr,len dir cbw-adr,len ) | |
198 | (execute-command) | |
199 | r> if dup 0= if nip 0 then then \ Fake ok | |
200 | ; | |
201 | ||
202 | \ SUN Note - Scsi unit address is two cells, target and lun | |
203 | : set-address ( target lun -- ) | |
204 | drop 0 max max-lun min to lun | |
205 | device set-target | |
206 | ; | |
207 | : set-timeout ( n -- ) bulk-timeout max set-bulk-in-timeout ; | |
208 | ||
209 | : reopen-hardware ( -- ok? ) true ; | |
210 | : open-hardware ( -- ok? ) alloc-bulk reopen-hardware ; | |
211 | : reclose-hardware ( -- ) ; | |
212 | : close-hardware ( -- ) free-bulk ; | |
213 | ||
214 | : reset ( -- ) transport-reset ; | |
215 | ||
216 | : selftest ( -- 0 | error-code ) 0 ; | |
217 | ||
218 | headers | |
219 | ||
220 | \ LICENSE_BEGIN | |
221 | \ Copyright (c) 2006 FirmWorks | |
222 | \ | |
223 | \ Permission is hereby granted, free of charge, to any person obtaining | |
224 | \ a copy of this software and associated documentation files (the | |
225 | \ "Software"), to deal in the Software without restriction, including | |
226 | \ without limitation the rights to use, copy, modify, merge, publish, | |
227 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
228 | \ permit persons to whom the Software is furnished to do so, subject to | |
229 | \ the following conditions: | |
230 | \ | |
231 | \ The above copyright notice and this permission notice shall be | |
232 | \ included in all copies or substantial portions of the Software. | |
233 | \ | |
234 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
235 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
236 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
237 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
238 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
239 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
240 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
241 | \ | |
242 | \ LICENSE_END |