Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Oliver Neukum
On Friday 14 December 2012 10:28:31 Fangxiaozhi wrote:

Hi,

> > For such devices we should put the switching code into generic code, not a
> > device driver so that we have a chance to do reset_resume() on those
> > devices.
> --Because in many embedded linux system, they don't include such 
> switch tools themselves. 
>   So I think it is better to put the switching code in 
> device driver.

Well, that argues for doing it in the kernel. Where you do it in the kernel 
shouldn't
matter.

> --By the way, because our device will response the switching 
> command for once, 
>   so I think you can do reset_resume() as you want.

What happens if S3 cuts power to the device?

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Fangxiaozhi (Franko)
Dear Oliver:

> -Original Message-
> From: Oliver Neukum [mailto:oneu...@suse.de]
> Sent: Friday, December 14, 2012 5:34 PM
> To: Alan Cox
> Cc: Fangxiaozhi (Franko); linux-...@vger.kernel.org;
> linux-kernel@vger.kernel.org; Xueguiying (Zihan); Linlei (Lei Lin);
> g...@kroah.com; Yili (Neil); Wangyuhua (Roger, Credit); Huqiao
> Subject: Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB
> storage devices and support new switch command
> 
> On Friday 14 December 2012 09:31:41 Alan Cox wrote:
> > On Fri, 14 Dec 2012 03:01:24 +
> > "Fangxiaozhi (Franko)"  wrote:
> >
> > > Dear Alan:
> > >
> > >   This prevents people getting access to the storage device if they want.
> > >   In our device, after its switching, it will keep the cdrom port
> together with other ports (such as modem port). So you can access the
> storage device too, after our switch.
> >
> > Ok so the behaviour is
> >
> > plug in device
> > "I am a CD-ROM"
> > command sent
> > "I am a CD-ROM, I am a modem, I am other things"
> >
> > with the newer devices ?
> 
> For such devices we should put the switching code into generic code, not a
> device driver so that we have a chance to do reset_resume() on those
> devices.
--Because in many embedded linux system, they don't include such 
switch tools themselves. 
So I think it is better to put the switching code in 
device driver.
--By the way, because our device will response the switching 
command for once, 
so I think you can do reset_resume() as you want.

>   Regards
>   Oliver

Best Regards,
Franko Fang



答复: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Fangxiaozhi (Franko)


> -邮件原件-
> 发件人: Alan Cox [mailto:a...@lxorguk.ukuu.org.uk]
> 发送时间: 2012年12月14日 17:32
> 收件人: Fangxiaozhi (Franko)
> 抄送: linux-...@vger.kernel.org; linux-kernel@vger.kernel.org; Xueguiying
> (Zihan); Linlei (Lei Lin); g...@kroah.com; Yili (Neil); Wangyuhua (Roger,
> Credit); Huqiao
> 主题: Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage
> devices and support new switch command
> 
> On Fri, 14 Dec 2012 03:01:24 +
> "Fangxiaozhi (Franko)"  wrote:
> 
> > Dear Alan:
> >
> > This prevents people getting access to the storage device if they want.
> > In our device, after its switching, it will keep the cdrom port
> together with other ports (such as modem port). So you can access the
> storage device too, after our switch.
> 
> Ok so the behaviour is
> 
>   plug in device
>   "I am a CD-ROM"
>   command sent
>   "I am a CD-ROM, I am a modem, I am other things"
> 
> with the newer devices ?
> 
> Alan
Yes, you are right.


Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Oliver Neukum
On Friday 14 December 2012 09:31:41 Alan Cox wrote:
> On Fri, 14 Dec 2012 03:01:24 +
> "Fangxiaozhi (Franko)"  wrote:
> 
> > Dear Alan:
> > 
> > This prevents people getting access to the storage device if they want.
> > In our device, after its switching, it will keep the cdrom port 
> > together with other ports (such as modem port). So you can access the 
> > storage device too, after our switch.
> 
> Ok so the behaviour is
> 
>   plug in device
>   "I am a CD-ROM"
>   command sent
>   "I am a CD-ROM, I am a modem, I am other things"
> 
> with the newer devices ?

For such devices we should put the switching code into generic code,
not a device driver so that we have a chance to do reset_resume()
on those devices.

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Alan Cox
On Fri, 14 Dec 2012 03:01:24 +
"Fangxiaozhi (Franko)"  wrote:

> Dear Alan:
> 
>   This prevents people getting access to the storage device if they want.
>   In our device, after its switching, it will keep the cdrom port 
> together with other ports (such as modem port). So you can access the storage 
> device too, after our switch.

Ok so the behaviour is

plug in device
"I am a CD-ROM"
command sent
"I am a CD-ROM, I am a modem, I am other things"

with the newer devices ?

Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Alan Cox
On Fri, 14 Dec 2012 03:01:24 +
Fangxiaozhi (Franko) fangxiao...@huawei.com wrote:

 Dear Alan:
 
   This prevents people getting access to the storage device if they want.
   In our device, after its switching, it will keep the cdrom port 
 together with other ports (such as modem port). So you can access the storage 
 device too, after our switch.

Ok so the behaviour is

plug in device
I am a CD-ROM
command sent
I am a CD-ROM, I am a modem, I am other things

with the newer devices ?

Alan
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Oliver Neukum
On Friday 14 December 2012 09:31:41 Alan Cox wrote:
 On Fri, 14 Dec 2012 03:01:24 +
 Fangxiaozhi (Franko) fangxiao...@huawei.com wrote:
 
  Dear Alan:
  
  This prevents people getting access to the storage device if they want.
  In our device, after its switching, it will keep the cdrom port 
  together with other ports (such as modem port). So you can access the 
  storage device too, after our switch.
 
 Ok so the behaviour is
 
   plug in device
   I am a CD-ROM
   command sent
   I am a CD-ROM, I am a modem, I am other things
 
 with the newer devices ?

For such devices we should put the switching code into generic code,
not a device driver so that we have a chance to do reset_resume()
on those devices.

Regards
Oliver

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


答复: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Fangxiaozhi (Franko)


 -邮件原件-
 发件人: Alan Cox [mailto:a...@lxorguk.ukuu.org.uk]
 发送时间: 2012年12月14日 17:32
 收件人: Fangxiaozhi (Franko)
 抄送: linux-...@vger.kernel.org; linux-kernel@vger.kernel.org; Xueguiying
 (Zihan); Linlei (Lei Lin); g...@kroah.com; Yili (Neil); Wangyuhua (Roger,
 Credit); Huqiao
 主题: Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage
 devices and support new switch command
 
 On Fri, 14 Dec 2012 03:01:24 +
 Fangxiaozhi (Franko) fangxiao...@huawei.com wrote:
 
  Dear Alan:
 
  This prevents people getting access to the storage device if they want.
  In our device, after its switching, it will keep the cdrom port
 together with other ports (such as modem port). So you can access the
 storage device too, after our switch.
 
 Ok so the behaviour is
 
   plug in device
   I am a CD-ROM
   command sent
   I am a CD-ROM, I am a modem, I am other things
 
 with the newer devices ?
 
 Alan
Yes, you are right.


RE: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Fangxiaozhi (Franko)
Dear Oliver:

 -Original Message-
 From: Oliver Neukum [mailto:oneu...@suse.de]
 Sent: Friday, December 14, 2012 5:34 PM
 To: Alan Cox
 Cc: Fangxiaozhi (Franko); linux-...@vger.kernel.org;
 linux-kernel@vger.kernel.org; Xueguiying (Zihan); Linlei (Lei Lin);
 g...@kroah.com; Yili (Neil); Wangyuhua (Roger, Credit); Huqiao
 Subject: Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB
 storage devices and support new switch command
 
 On Friday 14 December 2012 09:31:41 Alan Cox wrote:
  On Fri, 14 Dec 2012 03:01:24 +
  Fangxiaozhi (Franko) fangxiao...@huawei.com wrote:
 
   Dear Alan:
  
 This prevents people getting access to the storage device if they want.
 In our device, after its switching, it will keep the cdrom port
 together with other ports (such as modem port). So you can access the
 storage device too, after our switch.
 
  Ok so the behaviour is
 
  plug in device
  I am a CD-ROM
  command sent
  I am a CD-ROM, I am a modem, I am other things
 
  with the newer devices ?
 
 For such devices we should put the switching code into generic code, not a
 device driver so that we have a chance to do reset_resume() on those
 devices.
--Because in many embedded linux system, they don't include such 
switch tools themselves. 
So I think it is better to put the switching code in 
device driver.
--By the way, because our device will response the switching 
command for once, 
so I think you can do reset_resume() as you want.

   Regards
   Oliver

Best Regards,
Franko Fang



Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-14 Thread Oliver Neukum
On Friday 14 December 2012 10:28:31 Fangxiaozhi wrote:

Hi,

  For such devices we should put the switching code into generic code, not a
  device driver so that we have a chance to do reset_resume() on those
  devices.
 --Because in many embedded linux system, they don't include such 
 switch tools themselves. 
   So I think it is better to put the switching code in 
 device driver.

Well, that argues for doing it in the kernel. Where you do it in the kernel 
shouldn't
matter.

 --By the way, because our device will response the switching 
 command for once, 
   so I think you can do reset_resume() as you want.

What happens if S3 cuts power to the device?

Regards
Oliver

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-12 Thread Alan Cox
On Wed, 12 Dec 2012 18:20:33 +0800
fangxiaozhi 00110321  wrote:

> From: fangxiaozhi 
> 
> 1. To optimize the match rules for the Huawei USB storage devices. Avoid to 
> load USB storage driver for modem interface with Huawei devices.
> 2. Add to support new switch command for new Huawei USB dongles.

This prevents people getting access to the storage device if they want.
It also means you need to change kernel not simply a user space file to
add support for different new identifiers.

So it seems a large step backwards to me.

Why not just teach udev the new switch command then it'll work as a udev
update on all sorts of existing kernels as well as being the kind of
small safe change you can get into the entprise distributions ?

Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-12 Thread Felipe Balbi
Hi,

ok, let's start.

On Wed, Dec 12, 2012 at 06:20:33PM +0800, fangxiaozhi 00110321 wrote:
> From: fangxiaozhi 
> 
> 1. To optimize the match rules for the Huawei USB storage devices. Avoid to 
> load USB storage driver for modem interface with Huawei devices.
> 2. Add to support new switch command for new Huawei USB dongles.

first of all you're doing a whole lot more than these two things and
your commit log is a lot over 72 characters.

> Signed-off-by: fangxiaozhi 
> -
> diff -uprN linux-3.7_bak/drivers/usb/storage/initializers.c 
> linux-3.7/drivers/usb/storage/initializers.c
> --- linux-3.7_bak/drivers/usb/storage/initializers.c  2012-12-11 
> 09:56:11.0 +0800
> +++ linux-3.7/drivers/usb/storage/initializers.c  2012-12-12 
> 16:26:53.0 +0800
> @@ -92,8 +92,8 @@ int usb_stor_ucr61s2b_init(struct us_dat
>   return 0;
>  }
>  
> -/* This places the HUAWEI E220 devices in multi-port mode */
> -int usb_stor_huawei_e220_init(struct us_data *us)
> +/* This places the HUAWEI usb dongles in multi-port mode */
> +static int usb_stor_huawei_feature_init(struct us_data *us)

renaming this function doesn't look like is part of $SUBJECT

>  {
>   int result;
>  
> @@ -104,3 +104,60 @@ int usb_stor_huawei_e220_init(struct us_
>   US_DEBUGP("Huawei mode set result is %d\n", result);
>   return 0;
>  }
> +
> +/*Find the supported Huawei USB dongles*/

comment style is wrong, you miss a space after /* and before */

> +static int usb_stor_huawei_dongles_pid(struct us_data *us)
> +{
> + int ret = 0;
> + struct usb_interface_descriptor *idesc = NULL;

could add a blank line here to aid readability

> + idesc = >pusb_intf->cur_altsetting->desc;
> + if (idesc != NULL && idesc->bInterfaceNumber == 0) {
> + if ((us->pusb_dev->descriptor.idProduct >= 0x1401 && 
> us->pusb_dev->descriptor.idProduct <= 0x1600)
> + || (us->pusb_dev->descriptor.idProduct 
> >= 0x1c02 && us->pusb_dev->descriptor.idProduct <= 0x2202)
> + || (us->pusb_dev->descriptor.idProduct 
> == 0x1001)
> + || (us->pusb_dev->descriptor.idProduct 
> == 0x1003)
> + || (us->pusb_dev->descriptor.idProduct 
> == 0x1004)) {

clearly you didn't even run checkpatch.pl here.

> + if (us->pusb_dev->descriptor.idProduct >= 
> 0x1501 

^

trailing

whitespace

> + && us->pusb_dev->descriptor.idProduct 
> <= 0x1504) {
> + ret = 0;

ret is already initialized to zero, why do it again ?

> + } else {
> + ret = 1;
> + }
> + }
> + }
> + return ret;
> +}
> +
> +static int usb_stor_huawei_scsi_init(struct us_data *us)
> +{
> + int result = 0;
> + int act_len = 0;
> + unsigned char rewind_cmd[] = {0x11, 0x06, 0x20, 0x00, 0x00, 0x01, 0x00, 
> 0x00, 

 ^

 trailing

 whitespace

> +   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
> 0x00};
> + struct bulk_cb_wrap bcbw = {0};
> + bcbw.Signature = cpu_to_le32(US_BULK_CB_SIGN);
> + bcbw.Tag = 0;
> + bcbw.DataTransferLength = cpu_to_le32(0);
> + bcbw.Flags = bcbw.Lun = 0;
> + bcbw.Length = sizeof(rewind_cmd);
> + memset(bcbw.CDB, 0, sizeof(bcbw.CDB));

the entire structure is already initialized to zero, no ?

> + memcpy(bcbw.CDB, rewind_cmd, sizeof(rewind_cmd));
> +
> + result = usb_stor_bulk_transfer_buf (us, us->send_bulk_pipe, , 31, 
> _len);
> + US_DEBUGP("usb_stor_bulk_transfer_buf performing result is %d, transfer 
> the actual length=%d\n", result, act_len);

waay over 80-characters. Run checkpatch.pl

> + return result;
> +}
> +
> +int usb_stor_huawei_init(struct us_data *us)
> +{
> + int result = 0;
> + if(usb_stor_huawei_dongles_pid(us)) {
> + if ((us->pusb_dev->descriptor.idProduct >= 0x1446)) {
> + result = usb_stor_huawei_scsi_init(us);
> + } else {
> + result = usb_stor_huawei_feature_init(us);
> + }

read Documentation/CodingStyle, you'll see this is wrong.

> + }
> + return result;
> +}
> diff -uprN 

[PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-12 Thread fangxiaozhi 00110321
From: fangxiaozhi 

1. To optimize the match rules for the Huawei USB storage devices. Avoid to 
load USB storage driver for modem interface with Huawei devices.
2. Add to support new switch command for new Huawei USB dongles.

Signed-off-by: fangxiaozhi 
-
diff -uprN linux-3.7_bak/drivers/usb/storage/initializers.c 
linux-3.7/drivers/usb/storage/initializers.c
--- linux-3.7_bak/drivers/usb/storage/initializers.c2012-12-11 
09:56:11.0 +0800
+++ linux-3.7/drivers/usb/storage/initializers.c2012-12-12 
16:26:53.0 +0800
@@ -92,8 +92,8 @@ int usb_stor_ucr61s2b_init(struct us_dat
return 0;
 }
 
-/* This places the HUAWEI E220 devices in multi-port mode */
-int usb_stor_huawei_e220_init(struct us_data *us)
+/* This places the HUAWEI usb dongles in multi-port mode */
+static int usb_stor_huawei_feature_init(struct us_data *us)
 {
int result;
 
@@ -104,3 +104,60 @@ int usb_stor_huawei_e220_init(struct us_
US_DEBUGP("Huawei mode set result is %d\n", result);
return 0;
 }
+
+/*Find the supported Huawei USB dongles*/
+static int usb_stor_huawei_dongles_pid(struct us_data *us)
+{
+   int ret = 0;
+   struct usb_interface_descriptor *idesc = NULL;
+   idesc = >pusb_intf->cur_altsetting->desc;
+   if (idesc != NULL && idesc->bInterfaceNumber == 0) {
+   if ((us->pusb_dev->descriptor.idProduct >= 0x1401 && 
us->pusb_dev->descriptor.idProduct <= 0x1600)
+   || (us->pusb_dev->descriptor.idProduct 
>= 0x1c02 && us->pusb_dev->descriptor.idProduct <= 0x2202)
+   || (us->pusb_dev->descriptor.idProduct 
== 0x1001)
+   || (us->pusb_dev->descriptor.idProduct 
== 0x1003)
+   || (us->pusb_dev->descriptor.idProduct 
== 0x1004)) {
+
+   if (us->pusb_dev->descriptor.idProduct >= 
0x1501 
+   && us->pusb_dev->descriptor.idProduct 
<= 0x1504) {
+   ret = 0;
+   } else {
+   ret = 1;
+   }
+   }
+   }
+   return ret;
+}
+
+static int usb_stor_huawei_scsi_init(struct us_data *us)
+{
+   int result = 0;
+   int act_len = 0;
+   unsigned char rewind_cmd[] = {0x11, 0x06, 0x20, 0x00, 0x00, 0x01, 0x00, 
0x00, 
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00};
+   struct bulk_cb_wrap bcbw = {0};
+   bcbw.Signature = cpu_to_le32(US_BULK_CB_SIGN);
+   bcbw.Tag = 0;
+   bcbw.DataTransferLength = cpu_to_le32(0);
+   bcbw.Flags = bcbw.Lun = 0;
+   bcbw.Length = sizeof(rewind_cmd);
+   memset(bcbw.CDB, 0, sizeof(bcbw.CDB));
+   memcpy(bcbw.CDB, rewind_cmd, sizeof(rewind_cmd));
+
+   result = usb_stor_bulk_transfer_buf (us, us->send_bulk_pipe, , 31, 
_len);
+   US_DEBUGP("usb_stor_bulk_transfer_buf performing result is %d, transfer 
the actual length=%d\n", result, act_len);
+   return result;
+}
+
+int usb_stor_huawei_init(struct us_data *us)
+{
+   int result = 0;
+   if(usb_stor_huawei_dongles_pid(us)) {
+   if ((us->pusb_dev->descriptor.idProduct >= 0x1446)) {
+   result = usb_stor_huawei_scsi_init(us);
+   } else {
+   result = usb_stor_huawei_feature_init(us);
+   }
+   }
+   return result;
+}
diff -uprN linux-3.7_bak/drivers/usb/storage/initializers.h 
linux-3.7/drivers/usb/storage/initializers.h
--- linux-3.7_bak/drivers/usb/storage/initializers.h2012-12-11 
09:56:11.0 +0800
+++ linux-3.7/drivers/usb/storage/initializers.h2012-12-12 
11:43:58.0 +0800
@@ -46,5 +46,5 @@ int usb_stor_euscsi_init(struct us_data 
  * flash reader */
 int usb_stor_ucr61s2b_init(struct us_data *us);
 
-/* This places the HUAWEI E220 devices in multi-port mode */
-int usb_stor_huawei_e220_init(struct us_data *us);
+/* This places the HUAWEI usb dongles in multi-port mode */
+int usb_stor_huawei_init(struct us_data *us);
diff -uprN linux-3.7_bak/drivers/usb/storage/unusual_devs.h 
linux-3.7/drivers/usb/storage/unusual_devs.h
--- linux-3.7_bak/drivers/usb/storage/unusual_devs.h2012-12-11 
09:56:11.0 +0800
+++ linux-3.7/drivers/usb/storage/unusual_devs.h2012-12-12 
11:47:34.0 +0800
@@ -1527,335 +1527,10 @@ UNUSUAL_DEV(  0x1210, 0x0003, 0x0100, 0x
 /* Reported by fangxiaozhi 
  * This brings the HUAWEI data card devices into multi-port mode
  */
-UNUSUAL_DEV(  0x12d1, 0x1001, 0x, 0x,
+UNUSUAL_VENDOR_INTF(  0x12d1, 0x08, 0x06, 0x50,
"HUAWEI MOBILE",
"Mass Storage",
-   USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
-  

[PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-12 Thread fangxiaozhi 00110321
From: fangxiaozhi huana...@huawei.com

1. To optimize the match rules for the Huawei USB storage devices. Avoid to 
load USB storage driver for modem interface with Huawei devices.
2. Add to support new switch command for new Huawei USB dongles.

Signed-off-by: fangxiaozhi huana...@huawei.com
-
diff -uprN linux-3.7_bak/drivers/usb/storage/initializers.c 
linux-3.7/drivers/usb/storage/initializers.c
--- linux-3.7_bak/drivers/usb/storage/initializers.c2012-12-11 
09:56:11.0 +0800
+++ linux-3.7/drivers/usb/storage/initializers.c2012-12-12 
16:26:53.0 +0800
@@ -92,8 +92,8 @@ int usb_stor_ucr61s2b_init(struct us_dat
return 0;
 }
 
-/* This places the HUAWEI E220 devices in multi-port mode */
-int usb_stor_huawei_e220_init(struct us_data *us)
+/* This places the HUAWEI usb dongles in multi-port mode */
+static int usb_stor_huawei_feature_init(struct us_data *us)
 {
int result;
 
@@ -104,3 +104,60 @@ int usb_stor_huawei_e220_init(struct us_
US_DEBUGP(Huawei mode set result is %d\n, result);
return 0;
 }
+
+/*Find the supported Huawei USB dongles*/
+static int usb_stor_huawei_dongles_pid(struct us_data *us)
+{
+   int ret = 0;
+   struct usb_interface_descriptor *idesc = NULL;
+   idesc = us-pusb_intf-cur_altsetting-desc;
+   if (idesc != NULL  idesc-bInterfaceNumber == 0) {
+   if ((us-pusb_dev-descriptor.idProduct = 0x1401  
us-pusb_dev-descriptor.idProduct = 0x1600)
+   || (us-pusb_dev-descriptor.idProduct 
= 0x1c02  us-pusb_dev-descriptor.idProduct = 0x2202)
+   || (us-pusb_dev-descriptor.idProduct 
== 0x1001)
+   || (us-pusb_dev-descriptor.idProduct 
== 0x1003)
+   || (us-pusb_dev-descriptor.idProduct 
== 0x1004)) {
+
+   if (us-pusb_dev-descriptor.idProduct = 
0x1501 
+us-pusb_dev-descriptor.idProduct 
= 0x1504) {
+   ret = 0;
+   } else {
+   ret = 1;
+   }
+   }
+   }
+   return ret;
+}
+
+static int usb_stor_huawei_scsi_init(struct us_data *us)
+{
+   int result = 0;
+   int act_len = 0;
+   unsigned char rewind_cmd[] = {0x11, 0x06, 0x20, 0x00, 0x00, 0x01, 0x00, 
0x00, 
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00};
+   struct bulk_cb_wrap bcbw = {0};
+   bcbw.Signature = cpu_to_le32(US_BULK_CB_SIGN);
+   bcbw.Tag = 0;
+   bcbw.DataTransferLength = cpu_to_le32(0);
+   bcbw.Flags = bcbw.Lun = 0;
+   bcbw.Length = sizeof(rewind_cmd);
+   memset(bcbw.CDB, 0, sizeof(bcbw.CDB));
+   memcpy(bcbw.CDB, rewind_cmd, sizeof(rewind_cmd));
+
+   result = usb_stor_bulk_transfer_buf (us, us-send_bulk_pipe, bcbw, 31, 
act_len);
+   US_DEBUGP(usb_stor_bulk_transfer_buf performing result is %d, transfer 
the actual length=%d\n, result, act_len);
+   return result;
+}
+
+int usb_stor_huawei_init(struct us_data *us)
+{
+   int result = 0;
+   if(usb_stor_huawei_dongles_pid(us)) {
+   if ((us-pusb_dev-descriptor.idProduct = 0x1446)) {
+   result = usb_stor_huawei_scsi_init(us);
+   } else {
+   result = usb_stor_huawei_feature_init(us);
+   }
+   }
+   return result;
+}
diff -uprN linux-3.7_bak/drivers/usb/storage/initializers.h 
linux-3.7/drivers/usb/storage/initializers.h
--- linux-3.7_bak/drivers/usb/storage/initializers.h2012-12-11 
09:56:11.0 +0800
+++ linux-3.7/drivers/usb/storage/initializers.h2012-12-12 
11:43:58.0 +0800
@@ -46,5 +46,5 @@ int usb_stor_euscsi_init(struct us_data 
  * flash reader */
 int usb_stor_ucr61s2b_init(struct us_data *us);
 
-/* This places the HUAWEI E220 devices in multi-port mode */
-int usb_stor_huawei_e220_init(struct us_data *us);
+/* This places the HUAWEI usb dongles in multi-port mode */
+int usb_stor_huawei_init(struct us_data *us);
diff -uprN linux-3.7_bak/drivers/usb/storage/unusual_devs.h 
linux-3.7/drivers/usb/storage/unusual_devs.h
--- linux-3.7_bak/drivers/usb/storage/unusual_devs.h2012-12-11 
09:56:11.0 +0800
+++ linux-3.7/drivers/usb/storage/unusual_devs.h2012-12-12 
11:47:34.0 +0800
@@ -1527,335 +1527,10 @@ UNUSUAL_DEV(  0x1210, 0x0003, 0x0100, 0x
 /* Reported by fangxiaozhi huana...@huawei.com
  * This brings the HUAWEI data card devices into multi-port mode
  */
-UNUSUAL_DEV(  0x12d1, 0x1001, 0x, 0x,
+UNUSUAL_VENDOR_INTF(  0x12d1, 0x08, 0x06, 0x50,
HUAWEI MOBILE,
Mass Storage,
-   USB_SC_DEVICE, USB_PR_DEVICE, 

Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-12 Thread Felipe Balbi
Hi,

ok, let's start.

On Wed, Dec 12, 2012 at 06:20:33PM +0800, fangxiaozhi 00110321 wrote:
 From: fangxiaozhi huana...@huawei.com
 
 1. To optimize the match rules for the Huawei USB storage devices. Avoid to 
 load USB storage driver for modem interface with Huawei devices.
 2. Add to support new switch command for new Huawei USB dongles.

first of all you're doing a whole lot more than these two things and
your commit log is a lot over 72 characters.

 Signed-off-by: fangxiaozhi huana...@huawei.com
 -
 diff -uprN linux-3.7_bak/drivers/usb/storage/initializers.c 
 linux-3.7/drivers/usb/storage/initializers.c
 --- linux-3.7_bak/drivers/usb/storage/initializers.c  2012-12-11 
 09:56:11.0 +0800
 +++ linux-3.7/drivers/usb/storage/initializers.c  2012-12-12 
 16:26:53.0 +0800
 @@ -92,8 +92,8 @@ int usb_stor_ucr61s2b_init(struct us_dat
   return 0;
  }
  
 -/* This places the HUAWEI E220 devices in multi-port mode */
 -int usb_stor_huawei_e220_init(struct us_data *us)
 +/* This places the HUAWEI usb dongles in multi-port mode */
 +static int usb_stor_huawei_feature_init(struct us_data *us)

renaming this function doesn't look like is part of $SUBJECT

  {
   int result;
  
 @@ -104,3 +104,60 @@ int usb_stor_huawei_e220_init(struct us_
   US_DEBUGP(Huawei mode set result is %d\n, result);
   return 0;
  }
 +
 +/*Find the supported Huawei USB dongles*/

comment style is wrong, you miss a space after /* and before */

 +static int usb_stor_huawei_dongles_pid(struct us_data *us)
 +{
 + int ret = 0;
 + struct usb_interface_descriptor *idesc = NULL;

could add a blank line here to aid readability

 + idesc = us-pusb_intf-cur_altsetting-desc;
 + if (idesc != NULL  idesc-bInterfaceNumber == 0) {
 + if ((us-pusb_dev-descriptor.idProduct = 0x1401  
 us-pusb_dev-descriptor.idProduct = 0x1600)
 + || (us-pusb_dev-descriptor.idProduct 
 = 0x1c02  us-pusb_dev-descriptor.idProduct = 0x2202)
 + || (us-pusb_dev-descriptor.idProduct 
 == 0x1001)
 + || (us-pusb_dev-descriptor.idProduct 
 == 0x1003)
 + || (us-pusb_dev-descriptor.idProduct 
 == 0x1004)) {

clearly you didn't even run checkpatch.pl here.

 + if (us-pusb_dev-descriptor.idProduct = 
 0x1501 

^

trailing

whitespace

 +  us-pusb_dev-descriptor.idProduct 
 = 0x1504) {
 + ret = 0;

ret is already initialized to zero, why do it again ?

 + } else {
 + ret = 1;
 + }
 + }
 + }
 + return ret;
 +}
 +
 +static int usb_stor_huawei_scsi_init(struct us_data *us)
 +{
 + int result = 0;
 + int act_len = 0;
 + unsigned char rewind_cmd[] = {0x11, 0x06, 0x20, 0x00, 0x00, 0x01, 0x00, 
 0x00, 

 ^

 trailing

 whitespace

 +   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x00};
 + struct bulk_cb_wrap bcbw = {0};
 + bcbw.Signature = cpu_to_le32(US_BULK_CB_SIGN);
 + bcbw.Tag = 0;
 + bcbw.DataTransferLength = cpu_to_le32(0);
 + bcbw.Flags = bcbw.Lun = 0;
 + bcbw.Length = sizeof(rewind_cmd);
 + memset(bcbw.CDB, 0, sizeof(bcbw.CDB));

the entire structure is already initialized to zero, no ?

 + memcpy(bcbw.CDB, rewind_cmd, sizeof(rewind_cmd));
 +
 + result = usb_stor_bulk_transfer_buf (us, us-send_bulk_pipe, bcbw, 31, 
 act_len);
 + US_DEBUGP(usb_stor_bulk_transfer_buf performing result is %d, transfer 
 the actual length=%d\n, result, act_len);

waay over 80-characters. Run checkpatch.pl

 + return result;
 +}
 +
 +int usb_stor_huawei_init(struct us_data *us)
 +{
 + int result = 0;
 + if(usb_stor_huawei_dongles_pid(us)) {
 + if ((us-pusb_dev-descriptor.idProduct = 0x1446)) {
 + result = usb_stor_huawei_scsi_init(us);
 + } else {
 + result = usb_stor_huawei_feature_init(us);
 + }

read Documentation/CodingStyle, you'll see this is wrong.

 + }
 + return result;
 +}
 diff -uprN linux-3.7_bak/drivers/usb/storage/initializers.h 
 linux-3.7/drivers/usb/storage/initializers.h
 --- 

Re: [PATCH 1/1]linux-usb: optimize to match the Huawei USB storage devices and support new switch command

2012-12-12 Thread Alan Cox
On Wed, 12 Dec 2012 18:20:33 +0800
fangxiaozhi 00110321 fangxiao...@huawei.com wrote:

 From: fangxiaozhi huana...@huawei.com
 
 1. To optimize the match rules for the Huawei USB storage devices. Avoid to 
 load USB storage driver for modem interface with Huawei devices.
 2. Add to support new switch command for new Huawei USB dongles.

This prevents people getting access to the storage device if they want.
It also means you need to change kernel not simply a user space file to
add support for different new identifiers.

So it seems a large step backwards to me.

Why not just teach udev the new switch command then it'll work as a udev
update on all sorts of existing kernels as well as being the kind of
small safe change you can get into the entprise distributions ?

Alan
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/