linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: Implement proper subclass protocol translation
@ 2025-10-10 11:30 Shi Hao
  2025-10-10 12:29 ` Greg KH
  2025-10-10 15:07 ` Alan Stern
  0 siblings, 2 replies; 4+ messages in thread
From: Shi Hao @ 2025-10-10 11:30 UTC (permalink / raw)
  To: gregkh; +Cc: i.shihao.999, linux-usb, stern, skhan

Proper protocol translation for old legacy  usb devices.

Earlier protocol translation was insufficient for old usb devices
which was padding all subclasses  such as USB_SC_RBC, USB_SC_SCSI
and USB_SC_CYP_ATACB cmd_len to 6 byte value and because It wasn't
complete It had a FIXME comment stating to fix the protocol transl
-ation for those legacy usb devices.

As a result implement proper protocol translation as per their op
code.In addition to   the old default value 6  those old legacy
usb-device subclasses needed cmd_len value  to 10, 12 , and 16
byte also .

Signed-off-by: Shi Hao <i.shihao.999@gmail.com>
---
 drivers/usb/storage/transport.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 1aa1bd26c81f..4820b45d2a32 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -718,12 +718,25 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)

 		scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sense_size);

-		/* FIXME: we must do the protocol translation here */
+		/* Protocol translation per scsi opcode group */
 		if (us->subclass == USB_SC_RBC || us->subclass == USB_SC_SCSI ||
-				us->subclass == USB_SC_CYP_ATACB)
-			srb->cmd_len = 6;
-		else
+		    us->subclass == USB_SC_CYP_ATACB) {
+			/* Determine cmd_len based on scsi opcode group */
+			if (srb->cmnd[0] <= 0x1F)
+				srb->cmd_len = 6;
+			else if (srb->cmnd[0] <= 0x7F)
+				srb->cmd_len = 10;
+			else if (srb->cmnd[0] <= 0x9F)
+				srb->cmd_len = 16;
+			else if (srb->cmnd[0] <= 0xBF)
+				srb->cmd_len = 12;
+			else if (srb->cmnd[0] <= 0xDF)
+				srb->cmd_len = 16;
+			else
+				srb->cmd_len = 6;
+		} else {
 			srb->cmd_len = 12;
+		}

 		/* issue the auto-sense command */
 		scsi_set_resid(srb, 0);
--
2.51.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-11  9:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-10 11:30 [PATCH] usb: Implement proper subclass protocol translation Shi Hao
2025-10-10 12:29 ` Greg KH
2025-10-10 15:07 ` Alan Stern
2025-10-11  9:37   ` ShiHao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).