Author: wmb
Date: 2009-01-03 02:52:19 +0100 (Sat, 03 Jan 2009)
New Revision: 1057
Added:
ofw/inet/iscsi/
ofw/inet/iscsi/buffers.fth
ofw/inet/iscsi/debug.fth
ofw/inet/iscsi/ipackets.fth
ofw/inet/iscsi/keys.fth
ofw/inet/iscsi/loadiscsi.fth
ofw/inet/iscsi/low.fth
ofw/inet/iscsi/methods.fth
ofw/inet/iscsi/opackets.fth
ofw/inet/iscsi/scsi.fth
Modified:
cpu/x86/pc/biosload/fw.bth
Log:
Added iSCSI support package.
Modified: cpu/x86/pc/biosload/fw.bth
===================================================================
--- cpu/x86/pc/biosload/fw.bth 2008-12-30 02:31:29 UTC (rev 1056)
+++ cpu/x86/pc/biosload/fw.bth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -180,6 +180,12 @@
[then]
devalias nfs net//obp-tftp:last//nfs
+[ifdef] use-iscsi
+support-package: iscsi
+ fload ${BP}/ofw/inet/iscsi/loadiscsi.fth
+end-support-package
+[then]
+
fload ${BP}/ofw/inet/loadtcp.fth
support-package: http
Added: ofw/inet/iscsi/buffers.fth
===================================================================
--- ofw/inet/iscsi/buffers.fth (rev 0)
+++ ofw/inet/iscsi/buffers.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,233 @@
+purpose: iSCSI buffers
+\ See license at end of file
+
+hex
+
+\ structures for iscsi Protocol Data Units
+\ formats vary with request or response
+
+struct \ iscsi Basic Header Segment
+ \ 0
+ 1 field >opcode
+ 1 field >flags
+ 1 field >response
+ 1 field >status
+ \ 4
+ 1 field >AHSlen
+ 3 field >DSlen
+ \ 8
+ 0 field >LUN
+ 6 field >ISID
+ 2 field >TSIH
+ \ 16
+ 4 field >ITT
+ \ 20
+ 0 field >SNACK
+ 0 field >ExpDataLen
+ 0 field >CID
+ 0 field >RTT
+ 4 field >TTT
+ \ 24
+ 0 field >CmdSN
+ 4 field >StatSN
+ \ 28
+ 0 field >ExpCmdSN
+ 4 field >ExpStatSN
+ \ 32
+ 0 field >CDB
+ 0 field >RefCmdSN
+ 4 field >MaxCmdSN
+ \ 36
+ 0 field >Async
+ 0 field >LoginStat
+ 0 field >R2TSN
+ 0 field >ExpDataSN
+ 4 field >DataSN
+ \ 40
+ 0 field >BRRC
+ 0 field >Waittime
+ 0 field >BegRun
+ 4 field >BufferOffset
+ \ 44
+ 0 field >RunLen
+ 0 field >DDTlen
+ 4 field >RC
+ \ 48
+ 0 field >Data
+constant /bhs
+
+
+\ buffers for iscsi messages
+
+\ large data will be sent directly from the source address
+d# 1024 constant /max-pdu
+/max-pdu buffer: outbuf
+
+\ all incoming data goes to inbuf, so it must be large
+h# 4.0000 constant /max-transfer
+/max-transfer /bhs + buffer: inbuf
+
+
+0 value stage ( T C CSG NSG )
+: flags@ ( -- flags ) inbuf >flags c@ ;
+: flags! ( flags -- ) outbuf >flags c! ;
+
+0 [if]
+: update-stage ( -- )
+ flags@ h# 80 and 0= if exit then
+ \ transition
+ flags@ 3 and 1 = if
+ h# 87 to stage
+ then
+;
+[then]
+
+0 value dslen
+
+: !dslen ( -- )
+ dslen lwsplit ( lo hi )
+ outbuf >DSlen tuck c! 1+ be-w!
+;
+: @dslen ( -- dslen )
+ inbuf >AHSlen be-l@ h# 00ff.ffff and
+;
+
+
+\ get and set some fields
+
+\ XXX verify that this is the value that Solaris uses
+h# 4000.002A value isidh
+0 value isid
+: !isid ( -- )
+ outbuf >ISID isidh over be-l! isid swap 4 + be-w!
+;
+: ++isid ( -- ) isid 1+ to isid !isid ;
+
+0 value itt
+0 value ttt
+0 value cmdsn
+0 value expstatsn
+2variable lun
+
+: @ttt ( -- ) inbuf >TTT be-l@ to ttt ;
+: !ttt ( -- ) ttt outbuf >TTT be-l! ;
+: !itt ( -- ) itt outbuf >ITT be-l! ;
+: ++itt ( -- ) itt 1+ to itt !itt ;
+: !lun ( -- )
+ lun 2@ outbuf >LUN be-l!
+ outbuf >LUN 4 + be-l!
+;
+: @lun ( -- )
+ inbuf >LUN 4 + be-l@
+ inbuf >LUN be-l@
+ lun 2!
+;
+: .lun ( -- ) lun 2@ 8u.h ." ." 8u.h space ;
+
+: set-sn ( -- )
+ cmdsn outbuf >CmdSN be-l!
+ expstatsn outbuf >ExpStatSN be-l!
+;
+
+\ false value target-ready?
+: update-sn ( -- )
+ inbuf >ExpCmdSN be-l@ to cmdsn
+ inbuf >StatSN be-l@ 1+ to expstatsn
+
+ \ XXX use target-ready?, do nops if false
+ \ inbuf >maxcmdsn be-l@ cmdsn 1- <> to target-ready?
+;
+
+: init-pdu ( opcode -- )
+ 0 inbuf c!
+ outbuf /max-pdu erase
+ outbuf >opcode c!
+ set-sn
+ 0 to dslen !dslen
+;
+
+: read-more ( adr len -- actual )
+ wait-read dup 0< abort" read failed" ( sum actual )
+;
+: read-all ( adr total -- )
+ dup 0= if 2drop exit then
+
+ over + ( adr end ) >r ( adr )
+ begin dup r@ < while
+ dup r@ over - ( adr adr len ) read-more ( adr actual ) +
+ repeat
+ r> 2drop
+;
+
+defer get-pdu ( -- actual )
+: (get-pdu) ( -- actual )
+ inbuf /max-pdu erase \ helps debugging
+ inbuf /bhs read-all \ get the header
+ inbuf >data @dslen tuck 4 round-up read-all ( actual' )
+ /bhs + ( actual )
+ update-sn
+;
+' (get-pdu) to get-pdu
+
+defer send-pdu ( -- )
+: (send-pdu) ( -- )
+ !dslen
+ outbuf /bhs dslen + 4 round-up tcp-write
+ " flush-writes" $call-parent
+;
+' (send-pdu) to send-pdu
+
+\ send large data as if contiguous with BHS
+defer send-pdu+data ( a n -- )
+: (send-pdu+data) ( a n -- )
+ dup to dslen !dslen
+ outbuf /bhs tcp-write ( a n )
+ 4 round-up tcp-write
+ " flush-writes" $call-parent
+;
+' (send-pdu+data) to send-pdu+data
+
+\ append strings to the data segment
+: addnull ( -- )
+ /bhs dslen + 1+ /max-pdu > abort" Data Segment overrun"
+
+ 0 outbuf >Data dslen + c! \ append a null
+ dslen 1+ to dslen
+;
+: append ( a n -- )
+ dup /bhs + dslen + /max-pdu > abort" Data Segment overrun"
+
+ >r outbuf >Data dslen + r@ cmove
+ r> dslen + to dslen
+;
+: append0 ( a n -- )
+ dup /bhs + dslen + 1+ /max-pdu > abort" Data Segment overrun"
+
+ >r outbuf >Data dslen + r@ cmove
+ 0 outbuf >Data dslen + r@ + c! \ append a null
+ r> dslen + 1+ to dslen
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/buffers.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/debug.fth
===================================================================
--- ofw/inet/iscsi/debug.fth (rev 0)
+++ ofw/inet/iscsi/debug.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,287 @@
+purpose: iSCSI buffer dumps
+\ See license at end of file
+
+\ show field values
+: .op ( buf -- ) ." opcode " >opcode c@ .h ;
+: .flags ( buf -- ) ." flags " >flags c@ .h ;
+: .status ( buf -- ) ." status " >status c@ .h ;
+: .dsl ( buf -- ) ." DSlength " >AHSlen be-l@ h# 00ffffff and .d ;
+: .lun8 ( buf -- ) ." lun " >lun dup be-l@ 8u.h ." ." 4 + be-l@ 8u.h space ;
+: .isid ( buf -- ) ." isid " >isid dup 2+ be-l@ swap be-w@ (.12) type space ;
+: .tsih ( buf -- ) ." tsih " >tsih be-w@ .h ;
+: .itt ( buf -- ) ." itt " >itt be-l@ .h ;
+: .ttt ( buf -- ) ." ttt " >ttt be-l@ .h ;
+: .rtt ( buf -- ) ." rtt " >rtt be-l@ .h ;
+: .cid ( buf -- ) ." cid " >cid be-l@ .h ;
+: .edl ( buf -- ) ." Exp Data Length " >expdatalen be-l@ .h ;
+: .snack ( buf -- ) ." SNACK " >snack be-l@ .h ;
+: .cmdsn ( buf -- ) ." CmdSN " >cmdsn be-l@ .h ;
+: .statsn ( buf -- ) ." StatSN " >statsn be-l@ .h ;
+: .xcmdsn ( buf -- ) ." ExpCmdSN " >expcmdsn be-l@ .h ;
+: .xstatsn ( buf -- ) ." ExpStatSN " >expstatsn be-l@ .h ;
+: .refcmdsn ( buf -- ) ." RefCmdSN " >refcmdsn be-l@ .h ;
+: .maxcmdsn ( buf -- ) ." maxCmdSN " >maxcmdsn be-l@ .h ;
+: .r2tsn ( buf -- ) ." R2TSN " >r2tsn be-l@ .h ;
+: .xdatasn ( buf -- ) ." ExpDataSN " >expdatasn be-l@ .h ;
+: .datasn ( buf -- ) ." DataSN " >datasn be-l@ .h ;
+: .brrc ( buf -- ) ." BRRC " >brrc be-l@ .h ;
+: .rc ( buf -- ) ." RC " >rc be-l@ .h ;
+: .offset ( buf -- ) ." Buffer Offset " >bufferoffset be-l@ .h ;
+: .ddtl ( buf -- ) ." Desired Data Transfer Length " >DDTlen be-l@ .h ;
+
+: .ahsl ( buf -- )
+ >AHSlen c@ dup if
+ ." AHSlength " .h
+ else
+ drop
+ then
+;
+: .cdb ( buf -- ) cr ." CDB " >CDB h# 10 dump ;
+: .login-status ( buf -- )
+ ." login status " >loginstat dup be-w@ .h
+ c@
+ case
+ 0 of ." success" endof
+ 1 of ." target moved error" endof
+ 2 of ." initiator error" endof
+ 3 of ." target error" endof
+ ." unknown"
+ endcase
+ cr
+;
+
+\ display packets
+
+\ basic header segment
+: .bhs ( buf -- )
+ dup .op dup .flags
+ dup >opcode c@ h# 40 and if ." immediate " then
+ dup >flags c@ h# 80 and if ." final " then
+ dup .ahsl dup .dsl .itt cr
+;
+
+\ command pdu
+: .cmd ( -- buf )
+ outbuf dup .bhs dup .cmdsn dup .xstatsn cr
+;
+
+\ response pdu
+: .resp ( -- buf )
+ inbuf dup .bhs dup .statsn dup .xcmdsn dup .maxcmdsn cr
+;
+
+: .scsicmd ( -- )
+ ." SCSI Command " .cmd ( buf )
+ dup .lun8 dup .edl .cdb cr
+;
+: .scsiresp ( -- )
+ ." SCSI Response " .resp ( buf )
+ dup .snack dup .xdatasn dup .brrc .rc cr
+;
+: .tmfrq ( -- )
+ ." Task Request " .cmd ( buf )
+ dup .lun8 dup .rtt .refcmdsn cr
+;
+: .tmfr ( -- )
+ ." Task Response " .resp drop cr
+;
+: .scsidout ( -- )
+ ." SCSI Data Out " .cmd ( buf )
+ dup .lun8 dup .ttt dup .datasn
+ .offset cr
+;
+: .scsidin ( -- )
+ ." SCSI Data In " .resp ( buf )
+ dup .lun8 dup .ttt dup .datasn
+ dup .offset .rc cr
+;
+: .r2t ( -- )
+ ." Ready To Transfer " .resp ( buf )
+ dup .lun8 dup .ttt dup .r2tsn dup .offset .ddtl cr
+;
+: .async ( -- )
+ ." Async Event " .resp ( buf )
+ dup .lun8 ." type " >async c@ .h cr
+;
+: .textrq ( -- )
+ ." Text Request " .cmd ( buf )
+ dup .lun8 .ttt cr
+;
+: .textr ( -- )
+ ." Text Response " .resp ( buf )
+ dup .lun8 .ttt cr
+;
+: .loginrq ( -- )
+ ." Login Request " .cmd ( buf )
+ dup .isid dup .tsih .cid cr
+;
+: .login-response ( -- )
+ ." Login Response " .resp ( buf )
+ dup .isid dup .tsih cr ( buf )
+ .login-status ( )
+ flags@ dup 2 >> 3 and ." stage " . ( flags )
+ h# 80 and 0= if ." no " then ." transition " cr
+;
+: .logoutrq ( -- )
+ ." Logout Request " .cmd ( buf )
+ .cid cr
+;
+: .logoutr ( -- )
+ ." Logout Response " .resp ( buf )
+ dup >response c@ 0= if ." logout successful" cr then
+ >waittime ( wt )
+ ." time to wait " dup be-w@ .
+ ." time to retain " 2+ be-w@ . cr
+;
+: .snackrq ( -- )
+ ." SNACK Request " .cmd ( buf )
+ dup .lun8 dup .ttt
+ ." Begin Run " dup >begrun be-l@ .h
+ ." Run Length " >runlen be-l@ .h cr
+;
+: .reject ( -- )
+ ." Reject " .resp ( buf )
+ dup .datasn
+ ." reason " >response c@ .h cr
+;
+: .nopout ( -- )
+ ." NOP Out " .cmd ( buf )
+ dup .lun8 .ttt cr
+;
+: .nopin ( -- )
+ ." NOP In " .resp ( buf )
+ dup .lun8 .ttt cr
+;
+
+\ display the data segment, assuming it consists of null terminated strings
+: showbufdata ( a -- )
+ dup >AHSlen be-l@ h# 00ff.ffff and ( a dslen )
+ dup 0= if 2drop exit then
+
+ d# 1024 min \ safety
+
+ swap >Data swap bounds ?do
+ i c@ dup if emit else drop cr then
+ loop
+;
+
+\ dump the buffers
+: dump-got ( actual -- )
+ verbose? 0= if drop exit then ( actual )
+
+ dup /bhs < if
+ ." received " .d ." bytes partial header " cr inbuf /bhs dump cr
+ exit
+ then
+
+ ." received header " cr inbuf /bhs dump cr ( actual )
+ ." plus " dup /bhs - .d ." bytes of data" cr ( actual )
+ inbuf swap /bhs /string dump cr cr
+;
+: dump-sent ( a n -- )
+ verbose? 0= if 2drop exit then
+
+ ." sent header " cr outbuf /bhs dump cr ( a n )
+ dup if
+ ." plus " 4 round-up dup .d ." bytes of data" cr ( a n )
+ 2dup d# 512 min dump cr
+ then
+ cr
+ 2drop
+;
+
+\ display a packet
+: show-in-pdu ( -- )
+ debug? 0= if exit then
+
+ inbuf >opcode c@ h# 3f and
+ case
+ h# 20 of .nopin endof
+ h# 21 of .scsiresp endof
+ h# 22 of .tmfr endof
+ h# 23 of .login-response endof
+ h# 24 of .textr endof
+ h# 25 of .scsidin endof
+ h# 26 of .logoutr endof
+ h# 31 of .r2t endof
+ h# 32 of .async endof
+ h# 3f of .reject endof
+ ( default )
+ .resp
+ true abort" invalid target packet"
+ endcase
+ cr
+;
+: separator ( $tag -- )
+ debug? 0= if 2drop exit then
+
+ type ." -----------------------------------------" cr
+;
+: get-show-pdu ( -- actual )
+\ " get" separator
+ (get-pdu) ( actual )
+ dup dump-got show-in-pdu
+\ " got" separator
+;
+' get-show-pdu to get-pdu
+
+: show-out-pdu ( -- )
+ debug? 0= if exit then
+
+ outbuf >opcode c@ h# 3f and
+ case
+ h# 00 of .nopout endof
+ h# 01 of .scsicmd endof
+ h# 02 of .tmfrq endof
+ h# 03 of .loginrq outbuf showbufdata endof
+ h# 04 of .textrq outbuf showbufdata endof
+ h# 05 of .scsidout endof
+ h# 06 of .logoutrq endof
+ h# 10 of .snackrq endof
+ ( default )
+ .cmd cr
+ true abort" invalid initiator packet"
+ endcase
+ cr
+;
+: send-show-pdu ( -- )
+\ " send" separator
+ (send-pdu)
+ outbuf >data dslen dump-sent
+ show-out-pdu
+\ " sent" separator
+;
+' send-show-pdu to send-pdu
+
+: send-show-pdu+data ( a n -- )
+\ " send" separator
+ 2dup (send-pdu+data)
+ dump-sent
+ show-out-pdu
+\ " sent" separator
+;
+' send-show-pdu+data to send-pdu+data
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/debug.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/ipackets.fth
===================================================================
--- ofw/inet/iscsi/ipackets.fth (rev 0)
+++ ofw/inet/iscsi/ipackets.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,103 @@
+purpose: incoming iSCSI packets
+\ See license at end of file
+
+hex
+
+\ particular responses
+
+defer nop-out
+: nop-in ( -- )
+ @ttt ttt -1 <> if \ this is not a replay
+ nop-out \ so we need to respond
+ then
+;
+
+0 value status
+0 value status-valid?
+: scsi-response ( -- )
+ inbuf >response c@ 0= to status-valid?
+ inbuf >status c@ to status
+;
+
+defer get-response
+0 instance value read-address
+0 instance value read-length
+: scsi-data-in ( -- )
+ read-address 0= abort" read-address is not set"
+ inbuf >data read-address read-length
+ inbuf >bufferoffset be-l@ /string ( src dst len )
+ @dslen min cmove
+
+ flags@ h# 81 and h# 81 = \ F and S set?
+ dup to status-valid? if
+ inbuf >status c@ to status
+ else
+ get-response \ not final, get more
+ then
+;
+
+: scsi-task-response ( -- )
+;
+: login-response ( -- )
+ inbuf >loginstat c@ abort" login failed"
+
+ inbuf >data @dslen parse-keys
+;
+: text-response ( -- )
+ inbuf >data @dslen parse-keys
+;
+
+: logout-response ( -- )
+;
+: ready2transfer ( -- )
+;
+: async-message ( -- )
+;
+: reject ( -- )
+;
+: (get-response) ( -- )
+ get-pdu ( actual )
+ drop
+
+ false to status-valid?
+ inbuf >opcode c@ h# 3f and
+ case
+ h# 20 of nop-in endof
+ h# 21 of scsi-response endof
+ h# 22 of scsi-task-response endof
+ h# 23 of login-response endof
+ h# 24 of text-response endof
+ h# 25 of scsi-data-in endof
+ h# 26 of logout-response endof
+ h# 31 of ready2transfer endof
+ h# 32 of async-message endof
+ h# 3f of reject endof
+ ( default )
+ true abort" invalid command packet"
+ endcase
+;
+' (get-response) to get-response
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/ipackets.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/keys.fth
===================================================================
--- ofw/inet/iscsi/keys.fth (rev 0)
+++ ofw/inet/iscsi/keys.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,294 @@
+purpose: iSCSI parameters
+\ See license at end of file
+
+decimal
+
+\ these are negotiated between initiator and target as key=value strings
+\ each chategory has different behavior: boolean, digest, numeric, text
+
+\ Note: we negotiate the values with the target, but do not implement
+\ the functionality in many cases. During negotiation we request that
+\ digests and markers not be used, and expect the target to comply.
+
+\ For numerical values we simply accept values provided by the target.
+\ Currently only MaxRecvDataSegmentLength is used.
+
+\ The keys are grouped by behavior.
+
+vocabulary bkeys
+vocabulary dkeys
+vocabulary nkeys
+vocabulary tkeys
+
+\ boolean
+also bkeys definitions
+
+variable DataPDUInOrder
+variable DataSequenceInOrder
+variable ImmediateData
+variable InitialR2T
+variable IFMarker
+variable OFMarker
+
+\ digest
+dkeys definitions
+
+variable DataDigest
+variable HeaderDigest
+
+\ numeric
+nkeys definitions
+
+variable DefaultTime2Wait
+variable DefaultTime2Retain
+variable ErrorRecoveryLevel
+variable FirstBurstLength
+variable MaxBurstLength
+variable MaxConnections
+variable MaxOutstandingR2T
+variable MaxRecvDataSegmentLength
+variable TargetPortalGroupTag
+variable CHAP_A
+variable CHAP_I
+
+\ text
+tkeys definitions
+
+256 buffer: TargetAddress
+256 buffer: TargetAlias
+256 buffer: TargetName
+256 buffer: InitiatorName
+256 buffer: InitiatorAlias
+256 buffer: AuthMethod
+256 buffer: CHAP_C
+256 buffer: CHAP_N
+256 buffer: CHAP_R
+256 buffer: CHAP_S
+
+previous definitions
+
+: find-key ( $ -- false | a type )
+ ['] nkeys $vfind if ( xt )
+ execute ['] nkeys exit ( a t )
+ then ( $ )
+
+ ['] tkeys $vfind if ( xt )
+ execute ['] tkeys exit ( a t )
+ then ( $ )
+
+ ['] bkeys $vfind if ( xt )
+ execute ['] tkeys exit ( a t )
+ then ( $ )
+
+ ['] dkeys $vfind if ( xt )
+ execute ['] tkeys exit ( a t )
+ then ( $ )
+
+ 2drop false
+;
+
+: default-keys ( -- )
+ [ also bkeys ]
+ 1 DataPDUInOrder !
+ 1 DataSequenceInOrder !
+ 1 ImmediateData !
+ 0 InitialR2T !
+ 0 IFMarker !
+ 0 OFMarker !
+
+ [ dkeys ]
+
+ 0 DataDigest !
+ 0 HeaderDigest !
+
+ [ nkeys ]
+
+ 0 DefaultTime2Wait !
+ 0 DefaultTime2Retain !
+ 0 ErrorRecoveryLevel !
+ 65536 FirstBurstLength !
+ 262144 MaxBurstLength !
+ 1 MaxConnections !
+ 1 MaxOutstandingR2T !
+ 65536 MaxRecvDataSegmentLength !
+ \ 0 TargetPortalGroupTag !
+ 5 CHAP_A !
+
+ [ tkeys ]
+
+ 0 TargetAddress c!
+ 0 TargetAlias c!
+ 0 TargetName c!
+ 0 CHAP_C c!
+
+ [ previous ]
+;
+
+: get-addr ( $name --a ) find-key 0= abort" key not found" ;
+
+: get-num ( $name -- value )
+ find-key ['] nkeys <> abort" numeric key not found" ( a )
+ @
+;
+: get-text ( $name -- $text )
+ find-key ['] tkeys <> abort" text key not found" ( a )
+ count
+;
+: get-key ( $key -- $value )
+ ['] nkeys $vfind if ( xt )
+ execute @ push-decimal (.) pop-base
+ exit
+ then ( $ )
+
+ ['] tkeys $vfind if ( xt )
+ execute count exit
+ then ( $ )
+
+ ['] bkeys $vfind if ( xt )
+ execute @ if " Yes" else " No" then
+ exit
+ then ( $ )
+
+ ['] dkeys $vfind if ( xt )
+ execute @ if " CRC32C" else " None" then
+ exit ( a t )
+ then ( $ )
+
+ 2drop " Unknown key"
+;
+: set-key ( $value $key -- )
+ ['] nkeys $vfind if ( $v xt )
+ execute -rot $dnumber if drop bad-number throw then
+ swap ! exit
+ then ( $v $k )
+
+ ['] tkeys $vfind if ( $v xt )
+ execute place exit
+ then ( $v $k )
+
+ ['] bkeys $vfind if ( $v xt )
+ execute -rot ( a $v )
+ " Yes" $= swap ! exit
+ then ( $v $k )
+
+ ['] dkeys $vfind if ( $v xt )
+ execute -rot ( a $v )
+ " CRC32C" $= swap ! exit
+ then ( $v $k )
+
+ 4drop true abort" Invalid key"
+;
+
+: set-text ( $text $name -- )
+ find-key ['] tkeys <> if
+ 2drop true abort" text key not found"
+ then ( $text a )
+ place
+;
+: set-iname ( -- )
+ " iqn.1986-03.com.sun:boot." (mac-address) $cat2
+ " InitiatorName" set-text
+ " openboot" " InitiatorAlias" set-text
+;
+
+
+create $( char " c, char ( c,
+create $) char ) c,
+\ for CHAP
+: 2hd ( a n -- a' )
+ swap >r
+ dup 4 >> >digit r@ c!
+ h# 0f and >digit r@ 1+ c!
+ r> 2+
+;
+: put-hex ( $number $name -- )
+ find-key ['] tkeys <> if ( $number )
+ 2drop true abort" text key not found"
+ then ( $number a )
+
+ dup >r
+
+ 1+ [char] 0 over c! 1+ [char] x over c! 1+
+ -rot bounds ?do ( a' )
+ i c@ 2hd
+ loop ( a' )
+ r@ - r> c!
+;
+
+256 buffer: hexbuf
+: get-hex ( $name -- $hex )
+ get-addr dup 1+ 2 " 0x" $= 0= if ( a )
+ drop true abort" invalid hex format"
+ then ( a )
+
+ count dup 1 and if
+ 2drop true abort" invalid hex format" \ odd number of digits
+ then ( a n )
+
+ 2 /string hexbuf -rot bounds ?do ( buf )
+ i c@ d# 16 digit 0= abort" bad number" ( buf h )
+ 4 << i 1+ c@ d# 16 digit 0= abort" bad number" ( buf h l )
+ + over c! 1+ ( buf' )
+ 2 +loop
+ hexbuf tuck -
+;
+
+
+: append-key ( $name -- )
+ 2dup get-key ( $name $value )
+ " =" 2swap $cat3 append0
+;
+
+
+\ handle incoming k=v pairs
+256 buffer: keybuf
+256 buffer: valbuf
+0 value parsely
+
+: update-kev ( -- )
+ debug? if
+ ." set " keybuf count type ." =" valbuf count type cr
+ then
+ valbuf count keybuf count set-key
+;
+: parse-keys ( a n -- )
+ over to parsely
+ bounds ?do
+ i c@ [char] = = if
+ parsely i over - keybuf place
+ i 1+ to parsely
+ else
+ i c@ 0= if
+ parsely i over - valbuf place
+ i 1+ to parsely
+ update-kev
+ parsely c@ 0= if unloop exit then \ teminate on double null
+ then
+ then
+ loop
+ debug? if cr then
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/keys.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/loadiscsi.fth
===================================================================
--- ofw/inet/iscsi/loadiscsi.fth (rev 0)
+++ ofw/inet/iscsi/loadiscsi.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,56 @@
+purpose: load iSCSI package
+\ See license at end of file
+
+devalias iscsi tcp//iscsi
+
+" " d# 32 config-string iscsi-user
+" " d# 32 config-string iscsi-password
+
+\ true instance value debug?
+\ false instance value verbose?
+false value debug?
+false value verbose?
+
+fload ${BP}/ofw/inet/iscsi/low.fth
+fload ${BP}/ofw/inet/iscsi/buffers.fth
+
+\ debug.fth may be commented out to save space
+fload ${BP}/ofw/inet/iscsi/debug.fth
+
+fload ${BP}/ofw/inet/iscsi/keys.fth
+fload ${BP}/ofw/inet/random.fth
+fload ${BP}/ofw/ppp/md5.fth
+fload ${BP}/ofw/inet/iscsi/ipackets.fth
+fload ${BP}/ofw/inet/iscsi/opackets.fth
+fload ${BP}/ofw/inet/iscsi/methods.fth
+fload ${BP}/ofw/inet/iscsi/scsi.fth
+
+fload ${BP}/dev/scsi/hacom.fth
+
+support-package: disk
+fload ${BP}/dev/scsi/scsidisk.fth
+end-support-package
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/loadiscsi.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/low.fth
===================================================================
--- ofw/inet/iscsi/low.fth (rev 0)
+++ ofw/inet/iscsi/low.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,120 @@
+purpose: iSCSI low level routines
+\ See license at end of file
+
+hex
+
+d# 3260 value is_port
+0 value use_port \ remember which port we used, for re-connect
+
+\ parent routines
+: connect ( port -- connected? )
+ debug? if ." connecting to port " dup .d cr then
+ " connect" $call-parent
+ debug? if dup 0= if ." not " then ." connected" cr then
+;
+: disconnect ( -- )
+ " disconnect" $call-parent
+;
+: tcp-read ( adr len -- actual ) " read" $call-parent ;
+: tcp-write ( adr len -- ) " write" $call-parent drop ;
+: set-server ( server$ -- )
+ dup if " $set-host" $call-parent else 2drop then
+;
+
+
+\ we do not have a parent physical device, so get memory directly
+: dma-alloc ( size -- adr ) alloc-mem ;
+: dma-free ( adr size -- ) free-mem ;
+: dma-map-in ( vaddr n cache? -- devaddr ) 2drop ;
+: dma-map-out ( vaddr devaddr n -- ) 3drop ;
+
+0 [if]
+\ tcp input
+
+variable rah \ read ahead buffer
+: rah0 ( -- ) 0 rah ! ;
+: rahlen@ ( -- n ) rah 1+ c@ ;
+: rahlen! ( n -- ) rah 1+ c! ;
+
+: rah? ( -- any? )
+ rahlen@ dup 0> if exit then drop
+ rah 1 tcp-read dup rahlen! 0>
+;
+: rah@ ( -- c ) rah c@ rah0 ;
+
+: tcp-rd ( adr len -- actual )
+ rah? if
+ over rah@ swap c! 1 /string ( adr' len' )
+ 1 -rot
+ then
+ tcp-read dup 0> if ( rahl actual' )
+ +
+ else
+ drop
+ then
+;
+[then]
+
+\ timeout
+1 [if]
+\ XXX for debugging
+instance variable endtime
+: set-interval ( interval -- )
+ dup if get-msecs + then endtime !
+;
+: timeout? ( -- flag )
+ endtime @ if get-msecs endtime @ >= else true then
+;
+[then]
+
+\ read up to len characters into buffer at adr
+\ returns -1 if the connection is closed
+: wait-read ( adr len -- actual )
+ d# 60000 set-interval \ try for up to 60 seconds
+ begin
+ 2dup tcp-read dup -2 = ( adr len actual flag )
+ while ( adr len actual )
+ drop ( adr len )
+ timeout? if
+ debug? if ." wait-read timed out " cr then
+ 2drop 0 exit
+ then
+ repeat ( adr len actual )
+ nip nip ( actual )
+;
+
+: (.12) ( d -- a n )
+ <# d# 12 0 do # loop #>
+;
+
+\ return the mac address as a string
+: (mac-address) ( -- a n )
+ mac-address drop dup 2+ be-l@ swap be-w@ (.12)
+;
+
+\ convert a decimal string to an integer
+: $dnumber ( adr len -- true | n false ) push-decimal $number pop-base ;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/low.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/methods.fth
===================================================================
--- ofw/inet/iscsi/methods.fth (rev 0)
+++ ofw/inet/iscsi/methods.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,101 @@
+purpose: iSCSI high level routines
+\ See license at end of file
+
+hex
+
+\ proposed syntax is select iscsi:server:port//disk@0:\filename
+\ ofw will open this node with arguments "server:port"
+\ and will open the subsidiary disk node with arguments "\filename"
+
+: decode-server ( server$ -- port# server$' )
+ [char] : left-parse-string ( port$ server$ )
+ 2swap dup if ( server$ port$ )
+ push-decimal $number pop-base ( server$ port# error? )
+ abort" Bad port number" ( server$ port# )
+ else ( server$ port$ )
+ 2drop is_port ( server$ port# )
+ then ( server$ port# )
+ -rot ( port# server$ )
+;
+: mount ( target$ -- error? )
+ decode-server ( port# server$ )
+ set-server ( port# )
+ dup to use_port
+ connect 0= if true exit then
+
+ ['] login-discovery catch ( failed? )
+ debug? if
+ ." login-discovery "
+ dup if ." failed" else ." succeeded" then cr
+ then
+ if true exit then
+
+
+ ['] login-normal catch ( failed? )
+ debug? if
+ ." login-normal "
+ dup if ." failed" else ." succeeded" then cr
+ then
+;
+
+\ Called when an instance, but not the last instance, of the driver
+\ is being closed
+: reclose-hardware ( -- ) ;
+
+\ Called when the last instance of driver is being closed
+: close-hardware ( -- )
+ logout
+ disconnect
+;
+
+: seed-rng ( -- )
+ " get-time" clock-node @ $call-method ( s m h d m y )
+ 3drop d# 60 * + d# 60 * + rn !
+ 3 0 do random drop loop \ stir the bits
+;
+: reopen-hardware ( -- okay? )
+ seed-rng
+ true
+;
+: open-hardware ( -- status )
+ reopen-hardware 0= if false exit then
+
+ my-args dup if
+ bootnet-debug if
+ 2dup ." iSCSI: target is: " type cr
+ then
+ mount 0=
+ bootnet-debug if
+ ." iSCSI: "
+ dup if ." Succeeded" else ." Failed!" then cr
+ then
+ else
+ 2drop true
+ then
+\ true to debug?
+\ true to verbose?
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/methods.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/opackets.fth
===================================================================
--- ofw/inet/iscsi/opackets.fth (rev 0)
+++ ofw/inet/iscsi/opackets.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,261 @@
+purpose: iSCSI packets
+\ See license at end of file
+
+hex
+
+: send-cmd ( -- )
+ send-pdu
+ get-response
+;
+
+: init-login ( -- )
+ h# 43 init-pdu
+ !isid
+ stage flags!
+;
+: init-text ( -- )
+ h# 04 init-pdu
+ h# 80 flags!
+ -1 to ttt !ttt
+;
+
+: login-d ( -- )
+ set-iname
+ 1 to cmdsn
+ 0 to expstatsn
+ 0 to itt
+ random to isid
+ !isid
+ init-login
+ " InitiatorName" append-key
+ " InitiatorAlias" append-key
+ " SessionType=Discovery" append0
+ " AuthMethod=CHAP,None" append0
+ send-cmd
+;
+: login-n ( -- )
+ 0 to cmdsn
+ 0 to expstatsn
+ ++isid
+ init-login
+ h# 000a0000 to itt !itt
+ " InitiatorName" append-key
+ " InitiatorAlias" append-key
+ " TargetName" append-key
+ " SessionType=Normal" append0
+ " AuthMethod=CHAP,None" append0
+ send-cmd
+;
+: login-dp ( -- )
+ h# 87 to stage
+ init-login
+ " HeaderDigest=None" append0
+ " DataDigest=None" append0
+\ " DefaultTime2Wait" append-key
+\ " DefaultTime2Retain" append-key
+ " IFMarker" append-key
+ " OFMarker" append-key
+ " ErrorRecoveryLevel" append-key
+ " MaxRecvDataSegmentLength=32768" append0
+ send-cmd
+;
+: login-np ( -- )
+ h# 87 to stage
+ init-login
+ !itt
+ " HeaderDigest=None" append0
+ " DataDigest=None" append0
+\ " DefaultTime2Wait" append-key
+\ " DefaultTime2Retain" append-key
+ " IFMarker" append-key
+ " OFMarker" append-key
+ " ErrorRecoveryLevel" append-key
+ " InitialR2T" append-key
+ " ImmediateData" append-key
+ " MaxBurstLength" append-key
+ " FirstBurstLength" append-key
+ " MaxOutstandingR2T" append-key
+ " MaxConnections" append-key
+ " DataPDUInOrder" append-key
+ " DataSequenceInOrder" append-key
+ " MaxRecvDataSegmentLength" append-key
+ send-cmd
+;
+: login-st ( -- )
+ init-text
+ ++itt
+ " SendTargets=All" append0
+ send-cmd
+;
+: login-none ( -- )
+ flags@ h# 81 = if exit then
+
+ h# 81 to stage
+ init-login
+ !itt
+ send-cmd
+;
+: login-chapa ( -- )
+ 0 to stage
+ init-login
+ !itt
+ " CHAP_A=5" append0
+ send-cmd
+;
+
+\ use this version for production systems
+: get-user ( -- )
+ " iscsi-user" $getenv if 0 0 then
+ " CHAP_N" set-text
+ " iscsi-password" $getenv if 0 0 then
+ " CHAP_S" set-text
+;
+
+: calculate-chap-response ( -- )
+ " CHAP_I" get-addr 1 ( $I )
+ " CHAP_S" get-text ( $I $N )
+ " CHAP_C" get-hex ( $I $N $C )
+ $cat3
+ $md5digest1 ( $R )
+ " CHAP_R" put-hex
+;
+
+: login-chapn ( -- )
+ h# 81 to stage
+ init-login
+ get-user
+ calculate-chap-response
+ " CHAP_N" append-key
+ " CHAP_R" append-key
+ send-cmd
+;
+: logout ( -- )
+ h# 46 init-pdu
+ h# 80 flags!
+ !itt
+ send-cmd
+;
+
+: (nop-out) ( -- )
+ h# 40 init-pdu
+ !ttt
+ -1 outbuf >ITT be-l!
+ send-cmd
+;
+' (nop-out) is nop-out
+
+: auth-login ( -- )
+ " AuthMethod" get-text " CHAP" $= if
+ login-chapa
+ login-chapn
+ else
+ login-none
+ then
+;
+
+d# 1000 value outtime
+: delay ( -- )
+ debug? if ." delaying " outtime d# 1000 / .d ." seconds " cr then
+ outtime ms
+;
+: verify-target ( -- )
+ " TargetName" get-text nip 0= abort" No target devices found"
+;
+: login-discovery ( -- )
+ default-keys
+ h# 81 to stage
+ login-d
+ auth-login
+ login-dp
+ login-st
+ logout
+ disconnect
+ verify-target
+ delay
+;
+: login-normal ( -- )
+ use_port connect 0= abort" reconnect failed"
+ h# 81 to stage
+ login-n
+ auth-login
+ login-np
+;
+
+: login ( -- )
+ login-discovery
+ login-normal
+;
+
+\
+\ SCSI commands
+\
+
+\ statbyte values come asynchronously in the response packet
+: result ( -- hwresult | statbyte 0 )
+ status-valid? if
+ status
+ debug? if dup if ." statbyte is " dup .h cr then then
+ false
+ else
+ debug? if ." no status" cr then
+ true
+ then
+;
+: nodata-cmd ( -- hwresult | statbyte 0 )
+ h# 80 flags!
+ send-cmd
+ result
+;
+: write-cmd ( data-adr,len -- hwresult | statbyte 0 )
+ h# a0 flags!
+ dup outbuf >ExpDataLen be-l!
+ send-pdu+data
+ get-response
+ result
+;
+: read-cmd ( data-adr,len -- hwresult | statbyte 0 )
+ to read-length
+ to read-address
+ h# c0 flags!
+ read-length outbuf >ExpDataLen be-l!
+ send-cmd
+ result
+;
+: execute-command ( data-adr,len dir cmd-adr,len -- hwresult | statbyte 0 )
+ dup d# 16 > if ." CDB is too large" -1 exit then
+
+ h# 01 init-pdu \ make it non-immediate
+ ++itt \ and change itt
+ outbuf >CDB swap move ( data-adr,len dir )
+ !lun \ set LUN
+ over outbuf >ExpDataLen be-l!
+ over if ( data-adr,len dir ) \ moving data
+ if read-cmd else write-cmd then
+ else
+ 3drop nodata-cmd
+ then
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/opackets.fth
___________________________________________________________________
Added: svn:executable
+ *
Added: ofw/inet/iscsi/scsi.fth
===================================================================
--- ofw/inet/iscsi/scsi.fth (rev 0)
+++ ofw/inet/iscsi/scsi.fth 2009-01-03 01:52:19 UTC (rev 1057)
@@ -0,0 +1,63 @@
+purpose: SCSI routines for iSCSI
+\ See license at end of file
+
+hex
+
+\ XXX is this what we need?
+: max-transfer ( -- n )
+ " MaxRecvDataSegmentLength" get-num ( n )
+ /max-transfer min
+ dup 0= if drop /max-transfer then
+;
+
+
+\ stubs
+
+\ error code
+fd constant bus-reset
+
+0 value his-id
+0 value his-lun
+: set-address ( unit target -- )
+ to his-id to his-lun
+;
+
+: set-timeout ( msecs -- ) drop ;
+
+
+0 [if]
+\ debug
+: showkey ( $name -- )
+ 2dup type space get-key type cr
+;
+: showkeys ( -- )
+ " MaxRecvDataSegmentLength" showkey
+ " FirstBurstLength" showkey
+ " MaxBurstLength" showkey
+ ." max-transfer " max-transfer .d
+;
+[then]
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 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.
+\
+\ LICENSE_END
Property changes on: ofw/inet/iscsi/scsi.fth
___________________________________________________________________
Added: svn:executable
+ *