Skip to contentSkip to conversation

On patch "Let scsi_cmnd->cmnd use request->cmd buffer"

DISCUSSION Stefan Richter 2 participants 8 messages May 3, 2008 – May 4, 2008 SCSI

lore
Share & tools
lore
#0 lore raw

Commit 64a87b244b9297667ca80264aab849a36f494884 contains:
-------------------------- drivers/firewire/fw-sbp2.c -------------------------- index 2a99937..dda82f3 100644
@@ -1487,7 +1487,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0)
goto out;

- memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
+ memcpy(orb->request.command_block, cmd->cmnd, cmd->cmd_len);

orb->base.callback = complete_command_orb; orb->base.request_bus =

Should drivers/ieee1394/sbp2.c::sbp2_create_command_orb() be changed in the same way?

Signature · 3 lines
Stefan Richter
-=====-==--- -=-= --=--
http://arcgraph.de/sr/
#1 lore raw
Quoted 14 lines · Stefan Richter

Commit 64a87b244b9297667ca80264aab849a36f494884 contains:
-------------------------- drivers/firewire/fw-sbp2.c -------------------------- index 2a99937..dda82f3 100644

(quoted diff) +1 -1
@@ -1487,7 +1487,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
 	if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0)
 		goto out;
 
-	memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
+	memcpy(orb->request.command_block, cmd->cmnd, cmd->cmd_len);
 
 	orb->base.callback = complete_command_orb;
 	orb->base.request_bus =
Quoted 3 lines

Should drivers/ieee1394/sbp2.c::sbp2_create_command_orb() be changed in the same way?

Sorry to have missed it. Yes it is best if it is changed. cmd->cmd_len is now guarantied to be set properly at all cases. And some commands you want to support will not be set correctly by COMMAND_SIZE(). do you want me to do it?

Boaz

#2 lore raw

From: Stefan Richter <[email protected]>
Subject: ieee1394: sbp2: use correct size of command descriptor block

Quoted 3 lines · Boaz Harrosh

cmd->cmd_len is now guarantied to be set properly at all cases. And some commands you want to support will not be set correctly by COMMAND_SIZE().

---
 drivers/ieee1394/sbp2.c |   18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/ieee1394/sbp2.c +7 -11
Index: linux/drivers/ieee1394/sbp2.c
===================================================================
@@ -1539,15 +1539,13 @@ static void sbp2_prep_command_orb_sg(str
 
 static void sbp2_create_command_orb(struct sbp2_lu *lu,
 				    struct sbp2_command_info *cmd,
-				    unchar *scsi_cmd,
-				    unsigned int scsi_use_sg,
-				    unsigned int scsi_request_bufflen,
-				    struct scatterlist *sg,
-				    enum dma_data_direction dma_dir)
+				    struct scsi_cmnd *SCpnt)
 {
 	struct sbp2_fwhost_info *hi = lu->hi;
 	struct sbp2_command_orb *orb = &cmd->command_orb;
 	u32 orb_direction;
+	unsigned int scsi_request_bufflen = scsi_bufflen(SCpnt);
+	enum dma_data_direction dma_dir = SCpnt->sc_data_direction;
 
 	/*
 	 * Set-up our command ORB.
@@ -1580,13 +1578,14 @@ static void sbp2_create_command_orb(stru
 		orb->data_descriptor_lo = 0x0;
 		orb->misc |= ORB_SET_DIRECTION(1);
 	} else
-		sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_use_sg, sg,
+		sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_sg_count(SCpnt),
+					 scsi_sglist(SCpnt),
 					 orb_direction, dma_dir);
 
 	sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb));
 
 	memset(orb->cdb, 0, 12);
-	memcpy(orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
+	memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);
 }
 
 static void sbp2_link_orb_command(struct sbp2_lu *lu,
@@ -1669,16 +1668,13 @@ static void sbp2_link_orb_command(struct
 static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt,
 			     void (*done)(struct scsi_cmnd *))
 {
-	unchar *scsi_cmd = (unchar *)SCpnt->cmnd;
 	struct sbp2_command_info *cmd;
 
 	cmd = sbp2util_allocate_command_orb(lu, SCpnt, done);
 	if (!cmd)
 		return -EIO;
 
-	sbp2_create_command_orb(lu, cmd, scsi_cmd, scsi_sg_count(SCpnt),
-				scsi_bufflen(SCpnt), scsi_sglist(SCpnt),
-				SCpnt->sc_data_direction);
+	sbp2_create_command_orb(lu, cmd, SCpnt);
 	sbp2_link_orb_command(lu, cmd);
 
 	return 0;
Signature · 10 lines
Stefan Richter
-=====-==--- -=-= --=--
http://arcgraph.de/sr/


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
#3 lore raw
Quoted 4 lines · Stefan Richter
Quoted 3 lines · Boaz Harrosh

cmd->cmd_len is now guarantied to be set properly at all cases. And some commands you want to support will not be set correctly by COMMAND_SIZE().

...

Quoted 2 lines
drivers/ieee1394/sbp2.c +0 -0

...

drivers/ieee1394/sbp2.c static void sbp2_create_command_orb(stru · line 1588

Quoted 3 lines
drivers/ieee1394/sbp2.c +1 -1
 	memset(orb->cdb, 0, 12);
-	memcpy(orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
+	memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);

...

Wait a minute...

drivers/ieee1394/sbp2.[ch] and drivers/firewire/fw-sbp2.c hardwire the maximum size of the command descriptor block (command_block field in the command block ORB as per SBP-2 clause 5.1.2) to 12 bytes.

We need to use BLK_MAX_CDB there, don't we?

(Besides, we should keep an eye on unit_characteristics.ORB_size as per SBP-2 clause 7.4.8, but that's another story.)

Signature · 11 lines
Stefan Richter
-=====-==--- -=-= --=--
http://arcgraph.de/sr/



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
#4 lore raw
Quoted 10 lines · Stefan Richter
Quoted 4 lines · Stefan Richter
Quoted 3 lines · Boaz Harrosh

cmd->cmd_len is now guarantied to be set properly at all cases. And some commands you want to support will not be set correctly by COMMAND_SIZE().

...

Quoted 2 lines
drivers/ieee1394/sbp2.c +0 -0

...

Quoted 1 line

memset(orb->cdb, 0, 12);

if you are at it?
- memset(orb->cdb, 0, 12);
+ memset(orb->cdb, 0, sizeof(orb->cdb));

Quoted 6 lines

drivers/ieee1394/sbp2.c static void sbp2_create_command_orb(stru · line 1588

Quoted 2 lines
drivers/ieee1394/sbp2.c +1 -1
-	memcpy(orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
+	memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);

...

Wait a minute...

Quoted 8 lines

drivers/ieee1394/sbp2.[ch] and drivers/firewire/fw-sbp2.c hardwire the maximum size of the command descriptor block (command_block field in the command block ORB as per SBP-2 clause 5.1.2) to 12 bytes.

We need to use BLK_MAX_CDB there, don't we?

(Besides, we should keep an eye on unit_characteristics.ORB_size as per SBP-2 clause 7.4.8, but that's another story.)

I'm not sure what you mean. But orb->cdb is 12 bytes, and setting max_cmd_len in host template insures midlayer will never send a command bigger then that. So ->cmd_len will never be bigger then host->max_cmd_len. BLK_MAX_CDB should not be used here.

But I don't see .max_cmd_len set in this file, is it set elsewhere?

Boaz

#5 lore raw
Quoted 37 lines · Boaz Harrosh
Quoted 10 lines · Stefan Richter
Quoted 4 lines · Stefan Richter
Quoted 3 lines · Boaz Harrosh

cmd->cmd_len is now guarantied to be set properly at all cases. And some commands you want to support will not be set correctly by COMMAND_SIZE().

...

Quoted 2 lines
drivers/ieee1394/sbp2.c +0 -0

...

Quoted 1 line
     memset(orb->cdb, 0, 12);

if you are at it?

(quoted diff) +1 -1
-     memset(orb->cdb, 0, 12);
+     memset(orb->cdb, 0, sizeof(orb->cdb));
Quoted 7 lines

drivers/ieee1394/sbp2.c static void sbp2_create_command_orb(stru · line 1588

Quoted 3 lines
drivers/ieee1394/sbp2.c +1 -1
-    memcpy(orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
+    memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);

...

Wait a minute...

Quoted 8 lines

drivers/ieee1394/sbp2.[ch] and drivers/firewire/fw-sbp2.c hardwire the maximum size of the command descriptor block (command_block field in the command block ORB as per SBP-2 clause 5.1.2) to 12 bytes.

We need to use BLK_MAX_CDB there, don't we?

(Besides, we should keep an eye on unit_characteristics.ORB_size as per SBP-2 clause 7.4.8, but that's another story.)

I'm not sure what you mean. But orb->cdb is 12 bytes, and setting max_cmd_len in host template insures midlayer will never send a command bigger then that. So ->cmd_len will never be bigger then host->max_cmd_len. BLK_MAX_CDB should not
be used here.

Quoted 3 lines

But I don't see .max_cmd_len set in this file, is it set elsewhere?

Boaz

Oops sorry its fine not to set .max_cmd_len. If not set the midlayer will assume 12. So the code you sent is fine as is.

Boaz

#6 lore raw
Quoted 2 lines · Boaz Harrosh

its fine not to set .max_cmd_len. If not set the midlayer will assume 12. So the code you sent is fine as is.

Ah right, it's explained in scsi_host.h. Thanks.

Signature · 9 lines
Stefan Richter
-=====-==--- -=-= --=--
http://arcgraph.de/sr/

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
#7 lore raw
In reply to Boaz Harrosh

Review

Quoted 9 lines · Boaz Harrosh
Quoted 4 lines · Stefan Richter
Quoted 2 lines
drivers/ieee1394/sbp2.c +0 -0

...

Quoted 1 line
     memset(orb->cdb, 0, 12);

if you are at it?

(quoted diff) +1 -1
-     memset(orb->cdb, 0, 12);
+     memset(orb->cdb, 0, sizeof(orb->cdb));

Right, I'll do that.

Signature · 9 lines
Stefan Richter
-=====-==--- -=-= --=--
http://arcgraph.de/sr/

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone