14 #include <linux/kernel.h>
15 #include <linux/device.h>
18 #include <linux/slab.h>
44 .bLength =
sizeof eem_intf,
130 .
bLength =
sizeof eem_ss_bulk_comp_desc,
150 static struct usb_string eem_string_defs[] = {
151 [0].s =
"CDC Ethernet Emulation Model (EEM)",
157 .strings = eem_string_defs,
175 DBG(cdev,
"invalid control req%02x.%02x v%04x i%04x l%d\n",
177 w_value, w_index, w_length);
186 struct f_eem *eem = func_to_eem(f);
196 if (eem->
port.in_ep->driver_data) {
197 DBG(cdev,
"reset eem\n");
201 if (!eem->
port.in_ep->desc || !eem->
port.out_ep->desc) {
202 DBG(cdev,
"init eem\n");
216 eem->
port.is_zlp_ok = 1;
218 DBG(cdev,
"activate eem\n");
232 struct f_eem *eem = func_to_eem(f);
235 DBG(cdev,
"eem deactivated\n");
237 if (eem->
port.in_ep->driver_data)
249 struct f_eem *eem = func_to_eem(f);
258 eem_intf.bInterfaceNumber =
status;
266 eem->
port.in_ep = ep;
272 eem->
port.out_ep = ep;
286 if (gadget_is_dualspeed(c->
cdev->gadget)) {
287 eem_hs_in_desc.bEndpointAddress =
288 eem_fs_in_desc.bEndpointAddress;
289 eem_hs_out_desc.bEndpointAddress =
290 eem_fs_out_desc.bEndpointAddress;
298 if (gadget_is_superspeed(c->
cdev->gadget)) {
299 eem_ss_in_desc.bEndpointAddress =
300 eem_fs_in_desc.bEndpointAddress;
301 eem_ss_out_desc.bEndpointAddress =
302 eem_fs_out_desc.bEndpointAddress;
310 DBG(cdev,
"CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n",
311 gadget_is_superspeed(c->
cdev->gadget) ?
"super" :
312 gadget_is_dualspeed(c->
cdev->gadget) ?
"dual" :
"full",
313 eem->
port.in_ep->name, eem->
port.out_ep->name);
323 if (eem->
port.out_ep->desc)
324 eem->
port.out_ep->driver_data =
NULL;
325 if (eem->
port.in_ep->desc)
326 eem->
port.in_ep->driver_data =
NULL;
328 ERROR(cdev,
"%s: can't bind, err %d\n", f->
name, status);
336 struct f_eem *eem = func_to_eem(f);
340 if (gadget_is_superspeed(c->
cdev->gadget))
342 if (gadget_is_dualspeed(c->
cdev->gadget))
367 if (!skb_cloned(skb)) {
368 int headroom = skb_headroom(skb);
369 int tailroom = skb_tailroom(skb);
398 put_unaligned_le16(len & 0x3FFF,
skb_push(skb, 2));
402 put_unaligned_le16(0,
skb_put(skb, 2));
411 static int eem_unwrap(
struct gether *port,
425 DBG(cdev,
"invalid EEM header\n");
430 header = get_unaligned_le16(skb->
data);
437 if (header &
BIT(15)) {
447 if (header &
BIT(14))
450 bmEEMCmd = (header >> 11) & 0x7;
453 len = header & 0x7FF;
454 if (skb->
len < len) {
461 DBG(cdev,
"EEM echo response error\n");
465 put_unaligned_le16(
BIT(15) |
BIT(11) | len,
473 DBG(cdev,
"echo response queue fail\n");
497 len = header & 0x3FFF;
505 if (header &
BIT(14)) {
516 DBG(cdev,
"invalid EEM CRC\n");
522 DBG(cdev,
"unable to unframe EEM packet\n");
532 DBG(cdev,
"unable to realign EEM packet\n");
564 if (eem_string_defs[0].
id == 0) {
571 eem_intf.iInterface =
status;
581 eem->
port.func.name =
"cdc_eem";
582 eem->
port.func.strings = eem_strings;
584 eem->
port.func.bind = eem_bind;
585 eem->
port.func.unbind = eem_unbind;
586 eem->
port.func.set_alt = eem_set_alt;
587 eem->
port.func.setup = eem_setup;
588 eem->
port.func.disable = eem_disable;
589 eem->
port.wrap = eem_wrap;
590 eem->
port.unwrap = eem_unwrap;