Re: [PATCH] gadget: mass_storage: make mass_storage support multi-luns with different logic block size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 17 Oct 2011 02:01:48 -0700, Yuping Luo <lypingsh@xxxxxxxxx> wrote:
here you are , :)

diff --git a/drivers/usb/gadget/f_mass_storage.c
b/drivers/usb/gadget/f_mass_storage.c
index 524381a..6a5c42d 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -379,6 +379,7 @@ struct fsg_common {
 	enum data_direction	data_dir;
 	u32			data_size;
 	u32			data_size_from_cmnd;
+	u32			data_size_is_in_blocks;

Personally, I'd make it an argument to check_command() or create a simple
wrapper for check_command() that calculates the size.

 	u32			tag;
 	u32			residue;
 	u32			usb_amount_left;
@@ -1851,6 +1852,18 @@ static int check_command(struct fsg_common
*common, int cmnd_size,
 	char			hdlen[20];
 	struct fsg_lun		*curlun;

+	curlun = common->curlun;
+	/* Convert the data size's unit from CDB */
+	if (common->data_size_is_in_blocks == 1) {
+		common->data_size_is_in_blocks = 0;
+		if (!curlun) {
+			DBG(common, "curlun NULL\n");
+			return -EINVAL;
+		}
+		common->data_size_from_cmnd =
+			common->data_size_from_cmnd << curlun->blkbits;
+	}
+

Same thing as in what Alan pointed.

 	hdlen[0] = 0;
 	if (common->data_dir != DATA_DIR_UNKNOWN)
 		sprintf(hdlen, ", H%c=%u", dirletter[(int) common->data_dir],
@@ -1859,6 +1872,7 @@ static int check_command(struct fsg_common
*common, int cmnd_size,
 	     name, cmnd_size, dirletter[(int) data_dir],
 	     common->data_size_from_cmnd, common->cmnd_size, hdlen);

+

Unnecessary empty line.

 	/*
 	 * We can't reply at all until we know the correct data direction
 	 * and size.
@@ -1916,17 +1930,13 @@ static int check_command(struct fsg_common
*common, int cmnd_size,
 		    common->lun, lun);

 	/* Check the LUN */
-	if (common->lun >= 0 && common->lun < common->nluns) {
-		curlun = &common->luns[common->lun];
-		common->curlun = curlun;
+	if (curlun) {
 		if (common->cmnd[0] != REQUEST_SENSE) {
 			curlun->sense_data = SS_NO_SENSE;
 			curlun->sense_data_info = 0;
 			curlun->info_valid = 0;
 		}
 	} else {
-		common->curlun = NULL;
-		curlun = NULL;
 		common->bad_lun_okay = 0;

 		/*
@@ -2054,8 +2064,8 @@ static int do_scsi_command(struct fsg_common *common)

 	case READ_6:
 		i = common->cmnd[4];
-		common->data_size_from_cmnd = (i == 0 ? 256 : i) <<
-				common->curlun->blkbits;
+		common->data_size_from_cmnd = (i == 0 ? 256 : i);
+		common->data_size_is_in_blocks = 1;
 		reply = check_command(common, 6, DATA_DIR_TO_HOST,
 				      (7<<1) | (1<<4), 1,
 				      "READ(6)");
@@ -2065,8 +2075,8 @@ static int do_scsi_command(struct fsg_common *common)

 	case READ_10:
 		common->data_size_from_cmnd =
-				get_unaligned_be16(&common->cmnd[7]) <<
-						common->curlun->blkbits;
+				get_unaligned_be16(&common->cmnd[7]);
+		common->data_size_is_in_blocks = 1;
 		reply = check_command(common, 10, DATA_DIR_TO_HOST,
 				      (1<<1) | (0xf<<2) | (3<<7), 1,
 				      "READ(10)");
@@ -2076,8 +2086,8 @@ static int do_scsi_command(struct fsg_common *common)

 	case READ_12:
 		common->data_size_from_cmnd =
-				get_unaligned_be32(&common->cmnd[6]) <<
-						common->curlun->blkbits;
+				get_unaligned_be32(&common->cmnd[6]);
+		common->data_size_is_in_blocks = 1;
 		reply = check_command(common, 12, DATA_DIR_TO_HOST,
 				      (1<<1) | (0xf<<2) | (0xf<<6), 1,
 				      "READ(12)");
@@ -2177,8 +2187,8 @@ static int do_scsi_command(struct fsg_common *common)

 	case WRITE_6:
 		i = common->cmnd[4];
-		common->data_size_from_cmnd = (i == 0 ? 256 : i) <<
-					common->curlun->blkbits;
+		common->data_size_from_cmnd = (i == 0 ? 256 : i);
+		common->data_size_is_in_blocks = 1;
 		reply = check_command(common, 6, DATA_DIR_FROM_HOST,
 				      (7<<1) | (1<<4), 1,
 				      "WRITE(6)");
@@ -2188,8 +2198,8 @@ static int do_scsi_command(struct fsg_common *common)

 	case WRITE_10:
 		common->data_size_from_cmnd =
-				get_unaligned_be16(&common->cmnd[7]) <<
-						common->curlun->blkbits;
+				get_unaligned_be16(&common->cmnd[7]);
+		common->data_size_is_in_blocks = 1;
 		reply = check_command(common, 10, DATA_DIR_FROM_HOST,
 				      (1<<1) | (0xf<<2) | (3<<7), 1,
 				      "WRITE(10)");
@@ -2199,8 +2209,8 @@ static int do_scsi_command(struct fsg_common *common)

 	case WRITE_12:
 		common->data_size_from_cmnd =
-				get_unaligned_be32(&common->cmnd[6]) <<
-						common->curlun->blkbits;
+				get_unaligned_be32(&common->cmnd[6]);
+		common->data_size_is_in_blocks = 1;
 		reply = check_command(common, 12, DATA_DIR_FROM_HOST,
 				      (1<<1) | (0xf<<2) | (0xf<<6), 1,
 				      "WRITE(12)");
@@ -2316,7 +2326,10 @@ static int received_cbw(struct fsg_dev *fsg,
struct fsg_buffhd *bh)
 	if (common->data_size == 0)
 		common->data_dir = DATA_DIR_NONE;
 	common->lun = cbw->Lun;
-	common->curlun = &common->luns[cbw->Lun];

Where did this line came from?  I cannot see it in my Felipe's gadget tree.

+	if (common->lun >= 0 && common->lun < common->nluns)
+		common->curlun = &common->luns[common->lun];
+	else
+		common->curlun = NULL;
 	common->tag = cbw->Tag;
 	return 0;
 }

--
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@xxxxxxxxxx>--------------ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux