1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
14 \ Citrine storage controller.
17 device-name s" ide" device-type
20 3 encode-int s" #address-cells" property
21 0 encode-int s" #size-cells" property
23 : decode-unit 3 hex-decode-unit ;
24 : encode-unit 3 hex-encode-unit ;
27 : >ioa [ 10 config-l@ -10 and ] LITERAL + ;
32 \ Clear request completion doorbell.
36 CREATE ioasa 200 allot ioasa 200 erase \ can reduce to 8 later
38 \ request/response queue
39 CREATE rrq 100 allot rrq 100 erase \ can be smaller
45 CREATE ioarcb 80 allot ioarcb 80 erase
47 60708090 ioarcb c + l! \ user handle
48 ioadl ioarcb 2c + l! \ read ioadl
49 ioasa ioarcb 34 + l! 200 ioarcb 38 + w!
51 \ ioa config data (max. 16 devices)
52 CREATE ioacfg 404 allot ioacfg 404 erase
53 CREATE setsupbuff 2c allot
60 80000000 BEGIN dup 224 ioa@ cr .s dup 8000000 and IF
61 cr ." Unit check on SAS-Controller detected"
64 BEGIN cr 0 config-l@ dup . ffffffff <> UNTIL
65 \ ABORT" Unit check on SAS-Controller detected"
73 : wait-ioa ( int-mask -- ) BEGIN dup 224 ioa@ and UNTIL drop ;
74 : init-ioa ( -- ) 82800000 214 ioa! 80000000 wait-ioa ;
75 : do-request ( -- ) ioasa 20 erase ioarcb 404 ioa!
79 : setup-ioarcb ( rsrc type addr len -- )
80 tuck 49000000 or ioadl l! ioadl 4 + l! \ setup ioadl
81 ioarcb 20 + l! ioadl ioarcb 2c + l! 8 ioarcb 30 + l! \ set len, ioadl addr
82 ioarcb 3e + c! ioarcb 8 + l! \ set type and resource
83 ioarcb 40 + 40 erase ;
85 : setup-wrioarcb ( rsrc type addr len -- )
86 tuck 49000000 or ioadl l! ioadl 4 + l! \ setup ioadl
87 ioarcb 1C + l! ioadl ioarcb 24 + l! 8 ioarcb 28 + l! \ set len, ioadl addr
88 ioarcb 3e + c! ioarcb 8 + l! \ set type and resource
89 ioarcb 40 + 40 erase ;
91 : setup-idrrq ( rrq len -- )
92 c4 ioarcb 42 + c! 8 lshift ioarcb 48 + l! ioarcb 44 + l! ;
93 : do-idrrq ( -- ) -1 1 0 0 setup-ioarcb rrq 100 setup-idrrq do-request ;
95 : setup-query ( len -- ) c5 ioarcb 42 + c! 8 lshift ioarcb 48 + l! ;
96 : do-query ( -- ) -1 1 ioacfg 404 setup-ioarcb 404 setup-query do-request ;
98 : setup-startUnit ( -- ) 1b ioarcb 42 + c! 3 ioarcb 46 + c! ;
99 : do-startUnit ( hndl -- ) 0 0 0 setup-ioarcb setup-startUnit do-request ;
101 : setup-setsupported ( len -- ) 80 ioarcb 40 + c! fb ioarcb 42 + c! 8 lshift ioarcb 48 + l! ;
102 : do-setsupported ( -- ) -1 1 setsupbuff 2c setup-wrioarcb 2c setup-setsupported do-request ;
104 \ ********************************
106 \ ********************************
109 : setup-cap ( -- ) 25 ioarcb 42 + c! cap 8 erase ;
110 : do-cap ( rsrc addr -- )
111 >r 0 r> 8 setup-ioarcb setup-cap do-request ;
113 : .id ( id -- ) ." @" lwsplit 2 0.r ." ," wbsplit 2 0.r ." ," 2 0.r ;
116 cap do-cap cap l@ cap 4 + l@ * d# 50000000 + d# 100000000 /
117 base @ >r decimal d# 10 /mod 4 .r ." ." 0 .r ." GB" r> base ! ;
119 \ ********************************
121 \ ********************************
122 : setup-test-unit-ready ( -- )
123 00 ioarcb 42 + c! \ SCSI cmd: Test-Unit-Ready
126 : do-test-unit-ready ( rsrc -- )
127 0 0 0 setup-ioarcb ( rsrc type addr len -- )
128 setup-test-unit-ready
132 \ ********************************
134 \ ********************************
135 : check-device ( ioacfg-entry -- )
136 dup 2 + w@ 2001 and 0<> \ generic or raid disk
137 IF \ is an IOA resource ?
138 dup 8 + l@ ( ioacfg-entry rsrc ) \ get resource handle
140 DO ( ioacfg-entry rsrc )
141 dup do-test-unit-ready ( ioacfg-entry rsrc )
142 ioasa l@ 0= \ read returned status
147 drop ( ioacfg-entry )
152 : check-devices ( -- )
153 ioacfg 4 + ( ioacfg-entry ) \ config block for 16 devices
154 ioacfg c@ 0 \ amount of detected devices
157 check-device ( ioacfg-entry )
163 \ ********************************
165 \ ********************************
166 : show-device ( ioacfg-entry -- )
168 dup 8000 and IF ." Controller :" THEN
169 dup 2000 and IF ." Disk (RAID Member):" THEN
170 dup 0002 and IF ." Disk (Volume Set) :" THEN
171 0001 and IF ." Disk (Generic) :" THEN
172 space dup 4 + l@ ffffff and dup ffffff <> IF
174 ELSE drop 9 spaces THEN space
175 dup 1c + 8 type space dup 24 + 10 type
176 dup 2 + w@ 8000 and 0= IF
177 space dup 8 + l@ .cap
181 : show-devices ( -- )
182 ioacfg 4 + ioacfg c@ 0
183 ?DO dup show-device 40 + LOOP drop
186 : setup-read ( lba len -- ) \ len is in blocks
189 8 lshift ioarcb 48 + l!
192 : do-read ( hndl lba len addr -- ) \ len is in blocks
193 over >r rot >r swap 0 -rot 200 * ( 0 hndl addr len* )
194 setup-ioarcb r> r> ( lba len )
195 setup-read do-request
198 : make-subnode ( rsrc-type rsrc-handle id -- )
199 rot 2 and IF \ only device which are part of a RAID should be started
200 over do-startUnit \ at least on citrine there are problems starting
201 \ Generic SCSI devices
204 \ we need max-#blocks for citrine-disk.fs
206 over cap do-cap cap l@ ( rsrc id max-#blocks )
207 swap rot swap ( max-#block rsrc id ) \ this is what citrine-disk.fs expects...
208 s" citrine-disk.fs" included
214 : make-subnodes ( -- )
215 ioacfg 4 + ioacfg c@ 0 ?DO dup 2 + w@ dup ( ioacfg rsrc-type rsrc-type )
216 A000 \ 8000 = Resource Subtype is IOA Focal Point.
217 \ 2000 = Device is a member of a data redundancy group (eg. RAID).
218 \ (1000 = Device is designated for use as a hot spare.
219 \ Unfortunately obsidian reports disk which are not part of
220 \ of a RAID also as hot space even if they are not.)
221 \ all these devices should not appeat in DT
224 swap dup ( rsrc-type ioacfg ioacfg )
225 8 + l@ over 4 + l@ ( rsrc-type ioacfg rsrc-handle rsrc-addr )
226 ffffff and 2swap swap 2swap ( ioacfg rsrc-type rsrc-handle rsrc-addr )
227 make-subnode ELSE drop THEN 40 + LOOP drop ;
236 : setup-shutdown ( -- )
237 f7 ioarcb 42 + c! 0 ioarcb 48 + l! 0 ioarcb 44 + l! ;
238 : do-shutdown ( -- ) -1 1 0 0 setup-ioarcb setup-shutdown do-request ;
243 : start ['] do-it CATCH IF cr ." Citrine disabled" ELSE make-subnodes THEN ;