drivers/net/usb/huawei_cdc_ncm.c
Source file repositories/reference/linux-study-clean/drivers/net/usb/huawei_cdc_ncm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/usb/huawei_cdc_ncm.c- Extension
.c- Size
- 6394 bytes
- Lines
- 228
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/netdevice.hlinux/ethtool.hlinux/if_vlan.hlinux/ip.hlinux/mii.hlinux/usb.hlinux/usb/cdc.hlinux/usb/usbnet.hlinux/usb/cdc-wdm.hlinux/usb/cdc_ncm.h
Detected Declarations
struct huawei_cdc_ncm_statefunction huawei_cdc_ncm_manage_powerfunction huawei_cdc_ncm_wdm_manage_powerfunction huawei_cdc_ncm_bindfunction huawei_cdc_ncm_unbindfunction huawei_cdc_ncm_suspendfunction huawei_cdc_ncm_resume
Annotated Snippet
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;
struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
int drvflags = 0;
/* altsetting should always be 1 for NCM devices - so we hard-coded
* it here. Some huawei devices will need the NDP part of the NCM package to
* be at the end of the frame.
*/
drvflags |= CDC_NCM_FLAG_NDP_TO_END;
/* For many Huawei devices the NTB32 mode is the default and the best mode
* they work with. Huawei E5785 and E5885 devices refuse to work in NTB16 mode at all.
*/
drvflags |= CDC_NCM_FLAG_PREFER_NTB32;
ret = cdc_ncm_bind_common(usbnet_dev, intf, 1, drvflags);
if (ret)
goto err;
ctx = drvstate->ctx;
if (usbnet_dev->status)
/* The wMaxCommand buffer must be big enough to hold
* any message from the modem. Experience has shown
* that some replies are more than 256 bytes long
*/
subdriver = usb_cdc_wdm_register(ctx->control,
&usbnet_dev->status->desc,
1024, /* wMaxCommand */
WWAN_PORT_AT,
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)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/netdevice.h`, `linux/ethtool.h`, `linux/if_vlan.h`, `linux/ip.h`, `linux/mii.h`, `linux/usb.h`, `linux/usb/cdc.h`.
- Detected declarations: `struct huawei_cdc_ncm_state`, `function huawei_cdc_ncm_manage_power`, `function huawei_cdc_ncm_wdm_manage_power`, `function huawei_cdc_ncm_bind`, `function huawei_cdc_ncm_unbind`, `function huawei_cdc_ncm_suspend`, `function huawei_cdc_ncm_resume`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.