[hatari-devel] nf_scsidrv: Support for two buses

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


Hi,

With more than one USB card reader connected one can easily have more than
8 generic Linux SCSI devices. In order to get access (both with SCSI Driver
and XHDI) to all of them (and not just the first 8) within Hatari I updated
nf_scsidrv accordingly, see the attached patch.
Note that this is a breaking change wrt the NF_SCSI natfeats interface
between Hatari and the TOS counterpart of the SCSI Driver. An updated TOS
driver is needed, which is available on GitHub:
https://github.com/uweseimet/atari_public/tree/feature_two_buses

I recommend to commit this change to the Hatari 2.4.x development branch
(is there any?), and not to the current release branch.

@Thorsten Are you reading this? Sooner or later I would also like to update
the ARAnyM driver. There are only minor changes.

Best regards

Uwe
diff --git a/src/nf_scsidrv.c b/src/nf_scsidrv.c
index a1329db8..cfcd8f75 100644
--- a/src/nf_scsidrv.c
+++ b/src/nf_scsidrv.c
@@ -1,7 +1,7 @@
 /*
  * Hatari - nf_scsidrv.c
  *
- * Copyright (C) 2015-2016, 2018 by Uwe Seimet
+ * Copyright (C) 2015-2020 by Uwe Seimet
  *
  * This file is distributed under the GNU General Public License, version 2
  * or at your option any later version. Read the file gpl.txt for details.
@@ -31,10 +31,10 @@ const char NfScsiDrv_fileid[] = "Hatari nf_scsidrv.c";
 #include "m68000.h"
 #include "nf_scsidrv.h"
 
-// The driver interface version, 1.02
-#define INTERFACE_VERSION 0x0102
+// The driver interface version, 1.20
+#define INTERFACE_VERSION 0x0120
 // Maximum is 20 characters
-#define BUS_NAME "Linux Generic SCSI"
+#define BUS_NAME "Linux SCSI"
 // The SG driver supports cAllCmds
 #define BUS_FEATURES 0x02
 // The transfer length may depend on the device, 65536 should always be safe
@@ -174,34 +174,36 @@ static int scsidrv_interface_version(Uint32 stack)
 
 static int scsidrv_interface_features(Uint32 stack)
 {
+	Uint32 busIndex = read_stack_long(&stack);
 	Uint32 st_bus_name = STMemory_ReadLong(stack);
 	char *busName = read_stack_pointer(&stack);
 	Uint32 features = read_stack_long(&stack);
 	Uint32 transferLen = read_stack_long(&stack);
 
-	LOG_TRACE(TRACE_SCSIDRV, "scsidrv_interface_features: busName=%s, features=$%04x, transferLen=%d", BUS_NAME, BUS_FEATURES, BUS_TRANSFER_LEN);
-
 	if ( !STMemory_CheckAreaType ( st_bus_name, 20, ABFLAG_RAM ) )
 	{
 		Log_Printf(LOG_WARN, "scsidrv_interface_features: Invalid RAM range 0x%x+%i\n", st_bus_name, 20);
 		return -1;
 	}
 
-	strncpy(busName, BUS_NAME, 20);
+        sprintf(busName, "%s (Bus %d)", BUS_NAME, busIndex);
 	M68000_Flush_Data_Cache(st_bus_name, 20);
 	write_word(features, BUS_FEATURES);
 	write_long(transferLen, BUS_TRANSFER_LEN);
 
+	LOG_TRACE(TRACE_SCSIDRV, "scsidrv_interface_features: busIndex=%d, busName=%s, features=$%04x, transferLen=%d", busIndex, busName, BUS_FEATURES, BUS_TRANSFER_LEN);
+
 	return 0;
 }
 
 // SCSI Driver: InquireBus()
 static int scsidrv_inquire_bus(Uint32 stack)
 {
-	Uint32 id = read_stack_long(&stack);
+	Uint32 busIndex = read_stack_long(&stack);
+	Uint32 id = busIndex * 8 + read_stack_long(&stack);
 	char device_file[16];
 
-	LOG_TRACE(TRACE_SCSIDRV, "scsidrv_inquire_bus: id=%d", id);
+	LOG_TRACE(TRACE_SCSIDRV, "scsidrv_inquire_bus: busIndex=%d, id=%d", busIndex, id);
 
 	sprintf(device_file, "/dev/sg%d", id);
 
@@ -209,7 +211,7 @@ static int scsidrv_inquire_bus(Uint32 stack)
 	{
 		if (!check_device_file(id))
 		{
-			return id;
+			return id - busIndex * 8;
 		}
 
 		sprintf(device_file, "/dev/sg%d", ++id);
@@ -223,6 +225,7 @@ static int scsidrv_open(Uint32 stack)
 {
 	char device_file[16];
 	Uint32 handle;
+	Uint32 busIndex;
 	Uint32 id;
 	int fd;
 
@@ -246,17 +249,18 @@ static int scsidrv_open(Uint32 stack)
 #endif
 
 	handle = read_stack_long(&stack);
+	busIndex = read_stack_long(&stack);
 	id = read_stack_long(&stack);
 
-	LOG_TRACE(TRACE_SCSIDRV, "scsidrv_open: handle=%d, id=%d", handle, id);
+	LOG_TRACE(TRACE_SCSIDRV, "scsidrv_open: handle=%d, busIndex=%d, id=%d", handle, busIndex, id);
 
 	if (handle >= SCSI_MAX_HANDLES || handle_meta_data[handle].fd ||
-	    check_device_file(id))
+	    check_device_file(id + busIndex * 8))
 	{
 		return GEMDOS_ENHNDL;
 	}
 
-	sprintf(device_file, "/dev/sg%d", id);
+	sprintf(device_file, "/dev/sg%d", id + busIndex * 8);
 
 	fd = open(device_file, O_RDWR | O_NONBLOCK);
 	if (fd < 0)
@@ -479,7 +483,8 @@ static int scsidrv_error(Uint32 stack)
 // SCSI Driver: CheckDev()
 static int scsidrv_check_dev(Uint32 stack)
 {
-	Uint32 id = read_stack_long(&stack);
+	Uint32 busIndex = read_stack_long(&stack);
+	Uint32 id = busIndex * 8 + read_stack_long(&stack);
 
 	LOG_TRACE(TRACE_SCSIDRV, "scsidrv_check_dev: id=%d", id);
 


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