Skip to content

Commit 38396e4

Browse files
Greg Suarezdavem330
authored andcommitted
net: cdc_ncm: refactor bind preparing for MBIM support
NCM and MBIM can share most of the bind function. Split out the shareable part and add MBIM functional descriptor parsing. Signed-off-by: Greg Suarez <[email protected]> Signed-off-by: Bjørn Mork <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2d1c431 commit 38396e4

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

drivers/net/usb/cdc_ncm.c

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static const struct ethtool_ops cdc_ncm_ethtool_ops = {
451451
.nway_reset = usbnet_nway_reset,
452452
};
453453

454-
static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
454+
static int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_altsetting)
455455
{
456456
struct cdc_ncm_ctx *ctx;
457457
struct usb_driver *driver;
@@ -525,6 +525,13 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
525525
ctx->func_desc = (const struct usb_cdc_ncm_desc *)buf;
526526
break;
527527

528+
case USB_CDC_MBIM_TYPE:
529+
if (buf[0] < sizeof(*(ctx->mbim_desc)))
530+
break;
531+
532+
ctx->mbim_desc = (const struct usb_cdc_mbim_desc *)buf;
533+
break;
534+
528535
default:
529536
break;
530537
}
@@ -537,7 +544,7 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
537544

538545
/* check if we got everything */
539546
if ((ctx->control == NULL) || (ctx->data == NULL) ||
540-
(ctx->ether_desc == NULL) || (ctx->control != intf))
547+
((!ctx->mbim_desc) && ((ctx->ether_desc == NULL) || (ctx->control != intf))))
541548
goto error;
542549

543550
/* claim interfaces, if any */
@@ -557,7 +564,7 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
557564
goto error2;
558565

559566
/* configure data interface */
560-
temp = usb_set_interface(dev->udev, iface_no, 1);
567+
temp = usb_set_interface(dev->udev, iface_no, data_altsetting);
561568
if (temp)
562569
goto error2;
563570

@@ -574,11 +581,13 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
574581
usb_set_intfdata(ctx->control, dev);
575582
usb_set_intfdata(ctx->intf, dev);
576583

577-
temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress);
578-
if (temp)
579-
goto error2;
584+
if (ctx->ether_desc) {
585+
temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress);
586+
if (temp)
587+
goto error2;
588+
dev_info(&dev->udev->dev, "MAC-Address: %pM\n", dev->net->dev_addr);
589+
}
580590

581-
dev_info(&dev->udev->dev, "MAC-Address: %pM\n", dev->net->dev_addr);
582591

583592
dev->in = usb_rcvbulkpipe(dev->udev,
584593
ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
@@ -587,13 +596,6 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
587596
dev->status = ctx->status_ep;
588597
dev->rx_urb_size = ctx->rx_max;
589598

590-
/*
591-
* We should get an event when network connection is "connected" or
592-
* "disconnected". Set network connection in "disconnected" state
593-
* (carrier is OFF) during attach, so the IP network stack does not
594-
* start IPv6 negotiation and more.
595-
*/
596-
netif_carrier_off(dev->net);
597599
ctx->tx_speed = ctx->rx_speed = 0;
598600
return 0;
599601

@@ -639,6 +641,23 @@ static void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf)
639641
cdc_ncm_free(ctx);
640642
}
641643

644+
static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
645+
{
646+
int ret;
647+
648+
/* NCM data altsetting is always 1 */
649+
ret = cdc_ncm_bind_common(dev, intf, 1);
650+
651+
/*
652+
* We should get an event when network connection is "connected" or
653+
* "disconnected". Set network connection in "disconnected" state
654+
* (carrier is OFF) during attach, so the IP network stack does not
655+
* start IPv6 negotiation and more.
656+
*/
657+
netif_carrier_off(dev->net);
658+
return ret;
659+
}
660+
642661
static void cdc_ncm_zero_fill(u8 *ptr, u32 first, u32 end, u32 max)
643662
{
644663
if (first >= max)

0 commit comments

Comments
 (0)