vio-vscsi: added a proper lun parser
SCSI specification allows LUN to be specified in different formats,
the first 2 bits in 8 bytes LUN define the exact format. At the moment
QEMU uses only 2 formats: 00b for LUN<255 and 01b for bigger LUNs, both
are 2 bytes long and big endian.
However the existing SLOF code treats LUN as a 8 bytes big endian value
what is incorrect. The patch fixes this by adding a function which
parses LUN and returns an error if the format is not supported.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
diff --git a/board-qemu/slof/vio-vscsi.fs b/board-qemu/slof/vio-vscsi.fs
index 8a150ea..dc3c11e 100644
--- a/board-qemu/slof/vio-vscsi.fs
+++ b/board-qemu/slof/vio-vscsi.fs
@@ -593,6 +593,14 @@
8 CONSTANT #dev
+: vscsi-read-lun ( addr -- lun true | false )
+ dup c@ C0 AND CASE
+ 40 OF w@-be 3FFF AND TRUE ENDOF
+ 0 OF w@-be TRUE ENDOF
+ dup dup OF ." Unsupported LUN format = " . cr FALSE ENDOF
+ ENDCASE
+;
+
: vscsi-report-luns ( -- array ndev )
\ array of pointers, up to 8 devices
#dev 3 << alloc-mem dup
@@ -606,7 +614,11 @@
dup rot 0 fill ( devarray devcur ndev lunarray size mem )
dup >r swap move r> ( devarray devcur ndev mem )
dup sector l@ 3 >> 0 DO ( devarray devcur ndev mem memcur )
- dup dup x@ j 8 << 8000 or or 30 << swap x! 8 +
+ dup dup vscsi-read-lun IF
+ j 8 << 8000 or or 30 << swap x! 8 +
+ ELSE
+ 2drop
+ THEN
LOOP drop
rot ( devarray ndev mem devcur )
dup >r x! r> 8 + ( devarray ndev devcur )