Re: [PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
Hi guys!! :) First of all - I would like to thank both of you for your interest and time in my patches. I agree with Joe's point of view, completely. The Coding style document tries to leverage on the developer's good sense, even when defining some rules. Apart from that - checkpatch.po informed me about those very long lines, but I decided to leave them as they are due to the fact that they would look even more horrible than they look now. My braille display is 80-chars long (at least, the one I use normally), so I understand very well the problem of not passing that limit. Even so, the coding style says you might do so if you think the code is more readable this way, and that's why. My git usage is very bad as you may have observed (and I'm working on improving myself of course), but this was something I took into consideration. I remember when this cameto discussion: http://lkml.org/lkml/2009/12/17/229 still I know perfectly that one of the line you're blaming is indeed 139 characters. I understand and appreciate the fact that we _shouldn't_ take as reference worst cases (but only bbetter cases) to improve our practice & life, but in various drivers you can find examples like those. Is this still a problem? I will re-work the code and send the patch again as soon as I can. thank you again! -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
On Mon, 2013-08-26 at 17:09 -0400, David Miller wrote: > From: Joe Perches [] > Don't try to over-simplify things and act as if they are black > and white when they aren't. It wasn't me simplifying. I commented on your request to: "order local function variable declarations by line length, longest to shortest." as it seemed a bit rigid. And perhaps you didn't read the rest of my email. >> As a general rule, it's I suppose OK, but as >> a hardened rule, it's like most all hard rules. >> It's made to be broken. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
From: Joe Perches Date: Mon, 26 Aug 2013 14:05:55 -0700 > On Mon, 2013-08-26 at 16:58 -0400, David Miller wrote: >> From: Joe Perches >> Date: Mon, 26 Aug 2013 13:45:13 -0700 >> >> > I think the premise of local variable >> > declaration by line length is flawed. >> >> I disagree. >> >> > It can't work when local variables are >> > dependent on initialization order as >> > above. >> >> Move the initialization below the declarations. > > So all initializations should be on separate > lines from declarations? No, you can often make it work out when the initialization occurs on the same time. Like everything else in life, you evaluate it on a case by case basis. Don't try to over-simplify things and act as if they are black and white when they aren't. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
On Mon, 2013-08-26 at 16:58 -0400, David Miller wrote: > From: Joe Perches > Date: Mon, 26 Aug 2013 13:45:13 -0700 > > > I think the premise of local variable > > declaration by line length is flawed. > > I disagree. > > > It can't work when local variables are > > dependent on initialization order as > > above. > > Move the initialization below the declarations. So all initializations should be on separate lines from declarations? ick. It's possible, but it doubles the associated line count and I still think it's a very dubious premise/practice/style. As a general rule, it's I suppose OK, but as a hardened rule, it's like most all hard rules. It's made to be broken. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
From: Joe Perches Date: Mon, 26 Aug 2013 13:45:13 -0700 > I think the premise of local variable > declaration by line length is flawed. I disagree. > It can't work when local variables are > dependent on initialization order as > above. Move the initialization below the declarations. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
On Mon, 2013-08-26 at 16:31 -0400, David Miller wrote: > From: Enrico Mioso [] > > + int ret = 0; > > + struct usbnet *usbnet_dev = usb_get_intfdata(intf); > > + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; > > + struct cdc_ncm_ctx *ctx = drvstate->ctx; > > + bool callsub = (intf == ctx->control && drvstate->subdriver && > > drvstate->subdriver->resume); /* should we call subdriver's resume? ? */ > > Likewise, and order local function variable declarations by line > length, longest to shortest. I think the premise of local variable declaration by line length is flawed. It can't work when local variables are dependent on initialization order as above. int ret; could be moved down below callsub if really desired though. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
From: Enrico Mioso Date: Fri, 23 Aug 2013 09:56:29 +0200 > + if ((on && atomic_add_return(1, &drvstate->pmcount) == 1) || (!on && > atomic_dec_and_test(&drvstate->pmcount))) { These line significantly exceeds 80 columns. > + subdriver = usb_cdc_wdm_register(ctx->control, > + &usbnet_dev->status->desc, > + 256, /* CDC-WMC r1.1 requires > wMaxCommand to be "at least 256 decimal (0x100)" */ > + > huawei_cdc_ncm_wdm_manage_power); Likewise. > + if (intf == ctx->control && drvstate->subdriver && > drvstate->subdriver->suspend) Likewise. > + int ret = 0; > + struct usbnet *usbnet_dev = usb_get_intfdata(intf); > + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; > + struct cdc_ncm_ctx *ctx = drvstate->ctx; > + bool callsub = (intf == ctx->control && drvstate->subdriver && > drvstate->subdriver->resume); /* should we call subdriver's resume? ? */ Likewise, and order local function variable declarations by line length, longest to shortest. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH RESEND V3 net-next 2/3] net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver
This driver supports devices using the NCM protocol as an encapsulation layer for other protocols, like the E3131 Huawei 3G modem. This drivers approach was heavily inspired by the qmi_wwan approach & code model. Suggested-by: Bjorn Mork Signed-off-by: Enrico Mioso --- drivers/net/usb/Kconfig | 11 ++ drivers/net/usb/Makefile |1 + drivers/net/usb/huawei_cdc_ncm.c | 210 ++ 3 files changed, 222 insertions(+) create mode 100644 drivers/net/usb/huawei_cdc_ncm.c diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig index d84bfd4..6e56751 100644 --- a/drivers/net/usb/Kconfig +++ b/drivers/net/usb/Kconfig @@ -242,6 +242,17 @@ config USB_NET_CDC_NCM * ST-Ericsson M343 HSPA Mobile Broadband Modem (reference design) * Ericsson F5521gw Mobile Broadband Module +config USB_NET_HUAWEI_CDC_NCM + tristate "Huawei-style CDC NCM support" + depends on USB_USBNET + select USB_WDM + select USB_NET_CDC_NCM + help + This driver aims to support huawei-style NCM devices, that use ncm as a + transport for other protocols. + To compile this driver as a module, choose M here: the module will be + called huawei_cdc_ncm. + config USB_NET_CDC_MBIM tristate "CDC MBIM support" depends on USB_USBNET diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile index e817178..fd0e6a7 100644 --- a/drivers/net/usb/Makefile +++ b/drivers/net/usb/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_USB_IPHETH) += ipheth.o obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o obj-$(CONFIG_USB_NET_CX82310_ETH) += cx82310_eth.o obj-$(CONFIG_USB_NET_CDC_NCM) += cdc_ncm.o +obj-$(CONFIG_USB_NET_HUAWEI_CDC_NCM) += huawei_cdc_ncm.o obj-$(CONFIG_USB_VL600)+= lg-vl600.o obj-$(CONFIG_USB_NET_QMI_WWAN) += qmi_wwan.o obj-$(CONFIG_USB_NET_CDC_MBIM) += cdc_mbim.o diff --git a/drivers/net/usb/huawei_cdc_ncm.c b/drivers/net/usb/huawei_cdc_ncm.c new file mode 100644 index 000..d3426b9 --- /dev/null +++ b/drivers/net/usb/huawei_cdc_ncm.c @@ -0,0 +1,210 @@ +/* + * huawei_cdc_ncm.c - handles huawei-style NCM devices. + * Copyright (C) 2013 Enrico Mioso + * This driver handles devices resembling the CDC NCM standard, but + * encapsulating another protocol inside it. An example are some Huawei 3G + * devices, exposing an embedded AT channel where you can set up the NCM + * connection. + * This code has been heavily inspired by the cdc_mbim.c driver, which is + * Copyright (c) 2012 Smith Micro Software, Inc. + * Copyright (c) 2012 Bjørn Mork + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Driver data */ +struct huawei_cdc_ncm_state { + struct cdc_ncm_ctx *ctx; + atomic_t pmcount; + struct usb_driver *subdriver; + struct usb_interface *control; + struct usb_interface *data; +}; + +static int huawei_cdc_ncm_manage_power(struct usbnet *usbnet_dev, int on) +{ + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; + int rv = 0; + + if ((on && atomic_add_return(1, &drvstate->pmcount) == 1) || (!on && atomic_dec_and_test(&drvstate->pmcount))) { + rv = usb_autopm_get_interface(usbnet_dev->intf); + if (rv < 0) + goto err; + usbnet_dev->intf->needs_remote_wakeup = on; + usb_autopm_put_interface(usbnet_dev->intf); + } +err: + return rv; +} + +static int huawei_cdc_ncm_wdm_manage_power(struct usb_interface *intf, int status) +{ + struct usbnet *usbnet_dev = usb_get_intfdata(intf); + + /* can be called while disconnecting */ + if (!usbnet_dev) + return 0; + + return huawei_cdc_ncm_manage_power(usbnet_dev, status); +} + + +static int huawei_cdc_ncm_bind(struct usbnet *usbnet_dev, struct usb_interface *intf) +{ + struct cdc_ncm_ctx *ctx; + struct usb_driver *subdriver = ERR_PTR(-ENODEV); + int ret = -ENODEV; + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; + + ret = cdc_ncm_bind_common(usbnet_dev, intf, 1); /* altsetting should be 1 for NCM devices */ + if (ret) + goto err; + + ctx = drvstate->ctx; + + if (usbnet_dev->status) + subdriver = usb_cdc_wdm_register(ctx->control, +&usbnet_dev->status->desc, +256, /* CDC-WMC r1.1 requires wMaxCommand to be "at least 256 decimal (0x100)" */ + huawei_cdc_ncm_wdm_manage_power); + if (IS_ERR(subdriver))