[hatari-devel] MODE SENSE update patch

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

This patch updates mode page 0x3f to return all available pages in the order
requested by the SCSI specification (i.e. page 0 last).

IMO the implementation of mode page 0x04 is wrong. It is definitely incomplete
because it ignores some CDB data. In particular it does not check the DBD bit:

A disable block descriptors (DBD) bit of zero indicates that the target
may return zero or more block descriptors in the returned MODE SENSE data
(see 8.3.3), at the target's discretion.  A DBD bit of one specifies that
the target shall not return any block descriptors in the returned MODE
SENSE data.

It also does not check the PC field:

The page control (PC) field defines the type of mode parameter values to
be returned in the mode pages.  The page control field is defined in
table 55.

                        Table 55 - Page control field
+=======-=====================-============+
| Code  |  Type of parameter  | Subclause  |
|-------+---------------------+------------|
|  00b  |  Current values     |  8.2.10.1  |
|  01b  |  Changeable values  |  8.2.10.2  |
|  10b  |  Default values     |  8.2.10.3  |
|  11b  |  Saved values       |  8.2.10.4  |
+==========================================+

The header of mode page 0x04 also appears to be wrong, because it is missing
data:

                     Table 91 - Mode parameter header(6)
+=====-========-========-========-========-========-========-========-========+
|  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
|Byte |        |        |        |        |        |        |        |        |
|=====+=======================================================================|
| 0   |                           Mode data length                            |
|-----+-----------------------------------------------------------------------|
| 1   |                           Medium type                                 |
|-----+-----------------------------------------------------------------------|
| 2   |                           Device-specific parameter                   |
|-----+-----------------------------------------------------------------------|
| 3   |                           Block descriptor length                     |
+=============================================================================+

If there are no objections I might fix some of these issues with a
subsequent patch. For now the attached patch fixes page code 0x3f, which is
a fix I needed right now while running some tests.

Best regards

Uwe
diff --git a/src/hdc.c b/src/hdc.c
index 6a235679..815489fd 100644
--- a/src/hdc.c
+++ b/src/hdc.c
@@ -300,10 +300,8 @@ static void HDC_Cmd_RequestSense(SCSI_CTRLR *ctr)
  * Mode sense - Vendor specific page 00h.
  * (Just enough to make the HDX tool from AHDI 5.0 happy)
  */
-static void HDC_CmdModeSense0x00(SCSI_DEV *dev, SCSI_CTRLR *ctr)
+static void HDC_CmdModeSense0x00(SCSI_DEV *dev, SCSI_CTRLR *ctr, Uint8 *buf)
 {
-	Uint8 *buf = HDC_PrepRespBuf(ctr, 16);
-
 	buf[0] = 0;
 	buf[1] = 14;
 	buf[2] = 0;
@@ -330,10 +328,8 @@ static void HDC_CmdModeSense0x00(SCSI_DEV *dev, SCSI_CTRLR *ctr)
 /**
  * Mode sense - Rigid disk geometry page (requested by ASV).
  */
-static void HDC_CmdModeSense0x04(SCSI_DEV *dev, SCSI_CTRLR *ctr)
+static void HDC_CmdModeSense0x04(SCSI_DEV *dev, SCSI_CTRLR *ctr, Uint8 *buf)
 {
-	Uint8 *buf = HDC_PrepRespBuf(ctr, 24);
-
 	buf[0] = 4;
 	buf[1] = 22;
 
@@ -385,16 +381,27 @@ static void HDC_Cmd_ModeSense(SCSI_CTRLR *ctr)
 
 	switch(ctr->command[2])
 	{
-	 case 0x00:
-		HDC_CmdModeSense0x00(dev, ctr);
+        case 0x00: {
+		Uint8 *buf = HDC_PrepRespBuf(ctr, 16);
+		HDC_CmdModeSense0x00(dev, ctr, buf);
+		break;
+	}
+
+        case 0x04: {
+		Uint8 *buf = HDC_PrepRespBuf(ctr, 24);
+		HDC_CmdModeSense0x04(dev, ctr, buf);
 		break;
+	}
 
-	 case 0x04:
-	 case 0x3f:
-		HDC_CmdModeSense0x04(dev, ctr);
+        case 0x3f: {
+		Uint8 *buf = HDC_PrepRespBuf(ctr, 44);
+		buf[0] = 44;
+		HDC_CmdModeSense0x04(dev, ctr, buf + 4);
+		HDC_CmdModeSense0x00(dev, ctr, buf + 28);
 		break;
+	}
 
-	 default:
+        default:
 		Log_Printf(LOG_TODO, "HDC: Unsupported MODE SENSE command\n");
 		ctr->status = HD_STATUS_ERROR;
 		dev->nLastError = HD_REQSENS_INVARG;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/