|
51 | 51 | #include <linux/atomic.h>
|
52 | 52 | #include <linux/usb/usbnet.h>
|
53 | 53 | #include <linux/usb/cdc.h>
|
| 54 | +#include <linux/usb/cdc_ncm.h> |
54 | 55 |
|
55 | 56 | #define DRIVER_VERSION "14-Mar-2012"
|
56 | 57 |
|
57 |
| -/* CDC NCM subclass 3.2.1 */ |
58 |
| -#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10 |
59 |
| - |
60 |
| -/* Maximum NTB length */ |
61 |
| -#define CDC_NCM_NTB_MAX_SIZE_TX 32768 /* bytes */ |
62 |
| -#define CDC_NCM_NTB_MAX_SIZE_RX 32768 /* bytes */ |
63 |
| - |
64 |
| -/* Minimum value for MaxDatagramSize, ch. 6.2.9 */ |
65 |
| -#define CDC_NCM_MIN_DATAGRAM_SIZE 1514 /* bytes */ |
66 |
| - |
67 |
| -/* Minimum value for MaxDatagramSize, ch. 8.1.3 */ |
68 |
| -#define CDC_MBIM_MIN_DATAGRAM_SIZE 2048 /* bytes */ |
69 |
| - |
70 |
| -#define CDC_NCM_MIN_TX_PKT 512 /* bytes */ |
71 |
| - |
72 |
| -/* Default value for MaxDatagramSize */ |
73 |
| -#define CDC_NCM_MAX_DATAGRAM_SIZE 8192 /* bytes */ |
74 |
| - |
75 |
| -/* |
76 |
| - * Maximum amount of datagrams in NCM Datagram Pointer Table, not counting |
77 |
| - * the last NULL entry. |
78 |
| - */ |
79 |
| -#define CDC_NCM_DPT_DATAGRAMS_MAX 40 |
80 |
| - |
81 |
| -/* Restart the timer, if amount of datagrams is less than given value */ |
82 |
| -#define CDC_NCM_RESTART_TIMER_DATAGRAM_CNT 3 |
83 |
| -#define CDC_NCM_TIMER_PENDING_CNT 2 |
84 |
| -#define CDC_NCM_TIMER_INTERVAL (400UL * NSEC_PER_USEC) |
85 |
| - |
86 |
| -/* The following macro defines the minimum header space */ |
87 |
| -#define CDC_NCM_MIN_HDR_SIZE \ |
88 |
| - (sizeof(struct usb_cdc_ncm_nth16) + sizeof(struct usb_cdc_ncm_ndp16) + \ |
89 |
| - (CDC_NCM_DPT_DATAGRAMS_MAX + 1) * sizeof(struct usb_cdc_ncm_dpe16)) |
90 |
| - |
91 |
| -#define CDC_NCM_NDP_SIZE \ |
92 |
| - (sizeof(struct usb_cdc_ncm_ndp16) + \ |
93 |
| - (CDC_NCM_DPT_DATAGRAMS_MAX + 1) * sizeof(struct usb_cdc_ncm_dpe16)) |
94 |
| - |
95 |
| -struct cdc_ncm_ctx { |
96 |
| - struct usb_cdc_ncm_ntb_parameters ncm_parm; |
97 |
| - struct hrtimer tx_timer; |
98 |
| - struct tasklet_struct bh; |
99 |
| - |
100 |
| - const struct usb_cdc_ncm_desc *func_desc; |
101 |
| - const struct usb_cdc_mbim_desc *mbim_desc; |
102 |
| - const struct usb_cdc_header_desc *header_desc; |
103 |
| - const struct usb_cdc_union_desc *union_desc; |
104 |
| - const struct usb_cdc_ether_desc *ether_desc; |
105 |
| - |
106 |
| - struct net_device *netdev; |
107 |
| - struct usb_device *udev; |
108 |
| - struct usb_host_endpoint *in_ep; |
109 |
| - struct usb_host_endpoint *out_ep; |
110 |
| - struct usb_host_endpoint *status_ep; |
111 |
| - struct usb_interface *intf; |
112 |
| - struct usb_interface *control; |
113 |
| - struct usb_interface *data; |
114 |
| - |
115 |
| - struct sk_buff *tx_curr_skb; |
116 |
| - struct sk_buff *tx_rem_skb; |
117 |
| - __le32 tx_rem_sign; |
118 |
| - |
119 |
| - spinlock_t mtx; |
120 |
| - atomic_t stop; |
121 |
| - |
122 |
| - u32 tx_timer_pending; |
123 |
| - u32 tx_curr_frame_num; |
124 |
| - u32 rx_speed; |
125 |
| - u32 tx_speed; |
126 |
| - u32 rx_max; |
127 |
| - u32 tx_max; |
128 |
| - u32 max_datagram_size; |
129 |
| - u16 tx_max_datagrams; |
130 |
| - u16 tx_remainder; |
131 |
| - u16 tx_modulus; |
132 |
| - u16 tx_ndp_modulus; |
133 |
| - u16 tx_seq; |
134 |
| - u16 rx_seq; |
135 |
| - u16 connected; |
136 |
| -}; |
137 |
| - |
138 | 58 | static void cdc_ncm_txpath_bh(unsigned long param);
|
139 | 59 | static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
|
140 | 60 | static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer);
|
@@ -447,7 +367,7 @@ static const struct ethtool_ops cdc_ncm_ethtool_ops = {
|
447 | 367 | .nway_reset = usbnet_nway_reset,
|
448 | 368 | };
|
449 | 369 |
|
450 |
| -static int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_altsetting) |
| 370 | +int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_altsetting) |
451 | 371 | {
|
452 | 372 | struct cdc_ncm_ctx *ctx;
|
453 | 373 | struct usb_driver *driver;
|
@@ -605,8 +525,9 @@ static int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u
|
605 | 525 | dev_info(&dev->udev->dev, "bind() failure\n");
|
606 | 526 | return -ENODEV;
|
607 | 527 | }
|
| 528 | +EXPORT_SYMBOL_GPL(cdc_ncm_bind_common); |
608 | 529 |
|
609 |
| -static void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf) |
| 530 | +void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf) |
610 | 531 | {
|
611 | 532 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
|
612 | 533 | struct usb_driver *driver = driver_of(intf);
|
@@ -636,6 +557,7 @@ static void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf)
|
636 | 557 | usb_set_intfdata(ctx->intf, NULL);
|
637 | 558 | cdc_ncm_free(ctx);
|
638 | 559 | }
|
| 560 | +EXPORT_SYMBOL_GPL(cdc_ncm_unbind); |
639 | 561 |
|
640 | 562 | static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
|
641 | 563 | {
|
@@ -701,7 +623,7 @@ static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp(struct cdc_ncm_ctx *ctx, struct sk_
|
701 | 623 | return ndp16;
|
702 | 624 | }
|
703 | 625 |
|
704 |
| -static struct sk_buff * |
| 626 | +struct sk_buff * |
705 | 627 | cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign)
|
706 | 628 | {
|
707 | 629 | struct usb_cdc_ncm_nth16 *nth16;
|
@@ -858,6 +780,7 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign)
|
858 | 780 | cdc_ncm_tx_timeout_start(ctx);
|
859 | 781 | return NULL;
|
860 | 782 | }
|
| 783 | +EXPORT_SYMBOL_GPL(cdc_ncm_fill_tx_frame); |
861 | 784 |
|
862 | 785 | static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx)
|
863 | 786 | {
|
@@ -924,7 +847,7 @@ cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
|
924 | 847 | }
|
925 | 848 |
|
926 | 849 | /* verify NTB header and return offset of first NDP, or negative error */
|
927 |
| -static int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in) |
| 850 | +int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in) |
928 | 851 | {
|
929 | 852 | struct usb_cdc_ncm_nth16 *nth16;
|
930 | 853 | int len;
|
@@ -966,9 +889,10 @@ static int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_
|
966 | 889 | error:
|
967 | 890 | return ret;
|
968 | 891 | }
|
| 892 | +EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_nth16); |
969 | 893 |
|
970 | 894 | /* verify NDP header and return number of datagrams, or negative error */
|
971 |
| -static int cdc_ncm_rx_verify_ndp16(struct sk_buff *skb_in, int ndpoffset) |
| 895 | +int cdc_ncm_rx_verify_ndp16(struct sk_buff *skb_in, int ndpoffset) |
972 | 896 | {
|
973 | 897 | struct usb_cdc_ncm_ndp16 *ndp16;
|
974 | 898 | int ret = -EINVAL;
|
@@ -999,6 +923,7 @@ static int cdc_ncm_rx_verify_ndp16(struct sk_buff *skb_in, int ndpoffset)
|
999 | 923 | error:
|
1000 | 924 | return ret;
|
1001 | 925 | }
|
| 926 | +EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp16); |
1002 | 927 |
|
1003 | 928 | static int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
|
1004 | 929 | {
|
|
0 commit comments