-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bjørn Mork says: ==================== The huawei_cdc_ncm driver. Enrico has been kind enough to let me repost his driver with the changes requested by Oliver Neukum during the last review of this series. The changes I have made from Enricos original v5 series to this version are: v6: - fix to avoid corrupting drvstate->pmcount - fix error return value from huawei_cdc_ncm_suspend() - drop redundant testing for subdriver->suspend during resume - broke a few lines to keep within the 80 columns recommendation - rebased on top of current net-next Enrico's orginal introduction to the v5 series follows below. It explains the background much better than I can. Bjørn [quote Enrico Mioso] So this is a new, revised, edition of the huawei_cdc_ncm.c driver, which supports devices resembling the NCM standard, but using it also as a mean to encapsulate other protocols, as is the case for the Huawei E3131 and E3251 modem devices. Some precisations are needed however - and I encourage discussion on this: and that's why I'm sending this message with a broader CC. Merging those patches might change: - the way Modem Manager interacts with those devices - some regressions might be possible if there are some unknown firmware variants around (Franko?) First of all: I observed the behaviours of two devices. Huawei E3131: this device doesn't accept NDIS setup requests unless they're sent via the embedded AT channel exposed by this driver. So actually we gain funcionality in this case! The second case, is the Huawei E3251: which works with standard NCM driver, still exposing an AT embedded channel. Whith this patch set applied, you gain some funcionality, loosing the ability to catch standard NCM events for now. The device will work in both ways with no problems, but this has to be acknowledged and discussed. Might be we can develop this driver further to change this, when more devices are tested. We where thinking Huawei changed their interfaces on new devices - but probably this driver only works around a nice firmware bug present in E3131, which prevented the modem from being used in NDIS mode. I think committing this is definitely wortth-while, since it will allow for more Huawei devices to be used without serial connection. Some devices like the E3251 also, reports some status information only via the embedded AT channel, at least in my case. Note: I'm not subscribed to any list except the Modem Manager's one, so please CC me, thanks!! [/quote] Enrico Mioso (3): net: cdc_ncm: Export cdc_ncm_{tx,rx}_fixup functions for re-use net: huawei_cdc_ncm: Introduce the huawei_cdc_ncm driver net: cdc_ncm: remove non-standard NCM device IDs ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
5 changed files
with
253 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
/* huawei_cdc_ncm.c - handles Huawei devices using the CDC NCM protocol as | ||
* transport layer. | ||
* Copyright (C) 2013 Enrico Mioso <mrkiko.rs@gmail.com> | ||
* | ||
* | ||
* ABSTRACT: | ||
* 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 <bjorn@mork.no> | ||
* | ||
* 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 <linux/module.h> | ||
#include <linux/netdevice.h> | ||
#include <linux/ethtool.h> | ||
#include <linux/if_vlan.h> | ||
#include <linux/ip.h> | ||
#include <linux/mii.h> | ||
#include <linux/usb.h> | ||
#include <linux/usb/cdc.h> | ||
#include <linux/usb/usbnet.h> | ||
#include <linux/usb/cdc-wdm.h> | ||
#include <linux/usb/cdc_ncm.h> | ||
|
||
/* 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; | ||
|
||
if ((on && atomic_add_return(1, &drvstate->pmcount) == 1) || | ||
(!on && atomic_dec_and_test(&drvstate->pmcount))) { | ||
rv = usb_autopm_get_interface(usbnet_dev->intf); | ||
usbnet_dev->intf->needs_remote_wakeup = on; | ||
if (!rv) | ||
usb_autopm_put_interface(usbnet_dev->intf); | ||
} | ||
return 0; | ||
} | ||
|
||
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; | ||
|
||
/* altsetting should always be 1 for NCM devices - so we hard-coded | ||
* it here | ||
*/ | ||
ret = cdc_ncm_bind_common(usbnet_dev, intf, 1); | ||
if (ret) | ||
goto err; | ||
|
||
ctx = drvstate->ctx; | ||
|
||
if (usbnet_dev->status) | ||
/* CDC-WMC r1.1 requires wMaxCommand to be "at least 256 | ||
* decimal (0x100)" | ||
*/ | ||
subdriver = usb_cdc_wdm_register(ctx->control, | ||
&usbnet_dev->status->desc, | ||
256, /* wMaxCommand */ | ||
huawei_cdc_ncm_wdm_manage_power); | ||
if (IS_ERR(subdriver)) { | ||
ret = PTR_ERR(subdriver); | ||
cdc_ncm_unbind(usbnet_dev, intf); | ||
goto err; | ||
} | ||
|
||
/* Prevent usbnet from using the status descriptor */ | ||
usbnet_dev->status = NULL; | ||
|
||
drvstate->subdriver = subdriver; | ||
|
||
err: | ||
return ret; | ||
} | ||
|
||
static void huawei_cdc_ncm_unbind(struct usbnet *usbnet_dev, | ||
struct usb_interface *intf) | ||
{ | ||
struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; | ||
struct cdc_ncm_ctx *ctx = drvstate->ctx; | ||
|
||
if (drvstate->subdriver && drvstate->subdriver->disconnect) | ||
drvstate->subdriver->disconnect(ctx->control); | ||
drvstate->subdriver = NULL; | ||
|
||
cdc_ncm_unbind(usbnet_dev, intf); | ||
} | ||
|
||
static int huawei_cdc_ncm_suspend(struct usb_interface *intf, | ||
pm_message_t message) | ||
{ | ||
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; | ||
|
||
if (ctx == NULL) { | ||
ret = -ENODEV; | ||
goto error; | ||
} | ||
|
||
ret = usbnet_suspend(intf, message); | ||
if (ret < 0) | ||
goto error; | ||
|
||
if (intf == ctx->control && | ||
drvstate->subdriver && | ||
drvstate->subdriver->suspend) | ||
ret = drvstate->subdriver->suspend(intf, message); | ||
if (ret < 0) | ||
usbnet_resume(intf); | ||
|
||
error: | ||
return ret; | ||
} | ||
|
||
static int huawei_cdc_ncm_resume(struct usb_interface *intf) | ||
{ | ||
int ret = 0; | ||
struct usbnet *usbnet_dev = usb_get_intfdata(intf); | ||
struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; | ||
bool callsub; | ||
struct cdc_ncm_ctx *ctx = drvstate->ctx; | ||
|
||
/* should we call subdriver's resume function? */ | ||
callsub = | ||
(intf == ctx->control && | ||
drvstate->subdriver && | ||
drvstate->subdriver->resume); | ||
|
||
if (callsub) | ||
ret = drvstate->subdriver->resume(intf); | ||
if (ret < 0) | ||
goto err; | ||
ret = usbnet_resume(intf); | ||
if (ret < 0 && callsub) | ||
drvstate->subdriver->suspend(intf, PMSG_SUSPEND); | ||
err: | ||
return ret; | ||
} | ||
|
||
static int huawei_cdc_ncm_check_connect(struct usbnet *usbnet_dev) | ||
{ | ||
struct cdc_ncm_ctx *ctx; | ||
|
||
ctx = (struct cdc_ncm_ctx *)usbnet_dev->data[0]; | ||
|
||
if (ctx == NULL) | ||
return 1; /* disconnected */ | ||
|
||
return !ctx->connected; | ||
} | ||
|
||
static const struct driver_info huawei_cdc_ncm_info = { | ||
.description = "Huawei CDC NCM device", | ||
.flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN, | ||
.bind = huawei_cdc_ncm_bind, | ||
.unbind = huawei_cdc_ncm_unbind, | ||
.check_connect = huawei_cdc_ncm_check_connect, | ||
.manage_power = huawei_cdc_ncm_manage_power, | ||
.rx_fixup = cdc_ncm_rx_fixup, | ||
.tx_fixup = cdc_ncm_tx_fixup, | ||
}; | ||
|
||
static const struct usb_device_id huawei_cdc_ncm_devs[] = { | ||
/* Huawei NCM devices disguised as vendor specific */ | ||
{ USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x16), | ||
.driver_info = (unsigned long)&huawei_cdc_ncm_info, | ||
}, | ||
{ USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x46), | ||
.driver_info = (unsigned long)&huawei_cdc_ncm_info, | ||
}, | ||
{ USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x76), | ||
.driver_info = (unsigned long)&huawei_cdc_ncm_info, | ||
}, | ||
|
||
/* Terminating entry */ | ||
{ | ||
}, | ||
}; | ||
MODULE_DEVICE_TABLE(usb, huawei_cdc_ncm_devs); | ||
|
||
static struct usb_driver huawei_cdc_ncm_driver = { | ||
.name = "huawei_cdc_ncm", | ||
.id_table = huawei_cdc_ncm_devs, | ||
.probe = usbnet_probe, | ||
.disconnect = usbnet_disconnect, | ||
.suspend = huawei_cdc_ncm_suspend, | ||
.resume = huawei_cdc_ncm_resume, | ||
.reset_resume = huawei_cdc_ncm_resume, | ||
.supports_autosuspend = 1, | ||
.disable_hub_initiated_lpm = 1, | ||
}; | ||
module_usb_driver(huawei_cdc_ncm_driver); | ||
MODULE_AUTHOR("Enrico Mioso <mrkiko.rs@gmail.com>"); | ||
MODULE_DESCRIPTION("USB CDC NCM host driver with encapsulated protocol support"); | ||
MODULE_LICENSE("GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters