\ ========== Copyright Header Begin ==========================================
\ Hypervisor Software File: scsi.fth
\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
\ - Do no alter or remove copyright notices
\ - Redistribution and use of this software in source and binary forms, with
\ or without modification, are permitted provided that the following
\ - Redistribution of source code must retain the above copyright notice,
\ this list of conditions and the following disclaimer.
\ - Redistribution in binary form must reproduce the above copyright notice,
\ this list of conditions and the following disclaimer in the
\ documentation and/or other materials provided with the distribution.
\ Neither the name of Sun Microsystems, Inc. or the names of contributors
\ may be used to endorse or promote products derived from this software
\ without specific prior written permission.
\ This software is provided "AS IS," without a warranty of any kind.
\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\ You acknowledge that this software is not designed, licensed or
\ intended for use in the design, construction, operation or maintenance of
\ ========== Copyright Header End ============================================
id: @(#)scsi.fth 1.1 07/01/04
purpose: USB Mass Storage Device Driver
copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
\ See license at end of file
USB_ERR_STALL constant bus-reset
defer execute-command-hook ' noop to execute-command-hook
defer init-execute-command ' noop to init-execute-command
\ Class specific >dr-request constants
h# fe constant GET_MAX_LUN
h# 43425355 constant cbw-signature \ little-endian
h# 53425355 constant csw-signature \ little-endian
cbw-signature cbw >cbw-sig le-l!
cbw-tag cbw >cbw-tag le-l!
cbw 0= if /cbw dma-alloc to cbw then
csw 0= if /csw dma-alloc to csw then
cbw if cbw /cbw dma-free 0 to cbw then
csw if csw /csw dma-free 0 to csw then
max-lun-buf 1 my-address ( interface ) 0 DR_IN DR_CLASS DR_INTERFACE or or
GET_MAX_LUN control-get if ( actual usberr )
( actual ) if max-lun-buf c@ else 0 then
configuration set-config if ." Failed to set storage configuration" cr then
0 0 my-address ( interface ) 0 DR_OUT DR_CLASS DR_INTERFACE or or
DEV_RESET control-set-nostat drop
\ XXX Wait until devices does not NAK anymore
bulk-in-pipe h# 80 or unstall-pipe
bulk-out-pipe unstall-pipe
: wrap-cbw ( data-len dir cmd-adr,len -- cbw-adr,len )
init-cbw ( data-len dir cmd-adr,len )
cbw >r ( data-len dir cmd-adr,len ) ( R: cbw )
dup r@ >cbw-cblen c! ( data-len dir cmd-adr,len ) ( R: cbw )
r@ >cbw-cb swap move ( data-len dir ) ( R: cbw )
if cbw-flag-in else cbw-flag-out then ( data-len cbw-flag ) ( R: cbw )
r@ >cbw-flag c! ( data-len ) ( R: cbw )
r@ >cbw-dlen le-l! ( ) ( R: cbw )
lun r@ >cbw-lun c! ( ) ( R: cbw )
: (get-csw) ( -- len usberr ) csw /csw bulk-in-pipe bulk-in ;
: get-csw ( -- len usberr )
(get-csw) dup if 2drop (get-csw) then
d# 15,000 constant bulk-timeout
: (execute-command) ( data-adr,len dir cbw-adr,len -- hwresult | statbyte 0 )
bulk-out-pipe bulk-out ( data-adr,len dir usberr )
USB_ERR_CRC invert and ( data-adr,len dir usberr' )
?dup if nip nip nip exit then ( data-adr,len dir )
bulk-in-pipe bulk-in 2drop ( )
bulk-out-pipe bulk-out drop ( )
else ( data-adr,len dir )
csw /csw " dump" evaluate cr
drop csw >csw-stat c@ ( cswStatus )
0 of 0 0 endof \ No error
1 of 2 0 endof \ Error, "check condition"
2 of transport-reset \ Phase error, reset recovery
( default ) 0 0 rot \ Reserved error
: execute-command ( data-adr,len dir cmd-adr,len -- hwresult | statbyte 0 )
over c@ h# 1b = 2 pick 4 + c@ 1 = and >r \ Start command?
2over 2swap wrap-cbw ( data-adr,len dir cbw-adr,len )
r> if dup 0= if nip 0 then then \ Fake ok
\ SUN Note - Scsi unit address is two cells, target and lun
: set-address ( target lun -- )
drop 0 max max-lun min to lun
: set-timeout ( n -- ) bulk-timeout max set-bulk-in-timeout ;
: reopen-hardware ( -- ok? ) true ;
: open-hardware ( -- ok? ) alloc-bulk reopen-hardware ;
: reclose-hardware ( -- ) ;
: close-hardware ( -- ) free-bulk ;
: reset ( -- ) transport-reset ;
: selftest ( -- 0 | error-code ) 0 ;
\ Copyright (c) 2006 FirmWorks
\ Permission is hereby granted, free of charge, to any person obtaining
\ a copy of this software and associated documentation files (the
\ "Software"), to deal in the Software without restriction, including
\ without limitation the rights to use, copy, modify, merge, publish,
\ distribute, sublicense, and/or sell copies of the Software, and to
\ permit persons to whom the Software is furnished to do so, subject to
\ the following conditions:
\ The above copyright notice and this permission notice shall be
\ included in all copies or substantial portions of the Software.
\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.