u_ether.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * u_ether.h -- interface to USB gadget "ethernet link" utilities
  3. *
  4. * Copyright (C) 2003-2005,2008 David Brownell
  5. * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
  6. * Copyright (C) 2008 Nokia Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #ifndef __U_ETHER_H
  14. #define __U_ETHER_H
  15. #include <linux/err.h>
  16. #include <linux/if_ether.h>
  17. #include <linux/usb/composite.h>
  18. #include <linux/usb/cdc.h>
  19. #include "gadget_chips.h"
  20. /*
  21. * This represents the USB side of an "ethernet" link, managed by a USB
  22. * function which provides control and (maybe) framing. Two functions
  23. * in different configurations could share the same ethernet link/netdev,
  24. * using different host interaction models.
  25. *
  26. * There is a current limitation that only one instance of this link may
  27. * be present in any given configuration. When that's a problem, network
  28. * layer facilities can be used to package multiple logical links on this
  29. * single "physical" one.
  30. */
  31. struct gether {
  32. struct usb_function func;
  33. /* updated by gether_{connect,disconnect} */
  34. struct eth_dev *ioport;
  35. /* endpoints handle full and/or high speeds */
  36. struct usb_ep *in_ep;
  37. struct usb_ep *out_ep;
  38. bool is_zlp_ok;
  39. u16 cdc_filter;
  40. /* hooks for added framing, as needed for RNDIS and EEM. */
  41. u32 header_len;
  42. /* NCM requires fixed size bundles */
  43. bool is_fixed;
  44. u32 fixed_out_len;
  45. u32 fixed_in_len;
  46. struct sk_buff *(*wrap)(struct gether *port,
  47. struct sk_buff *skb);
  48. int (*unwrap)(struct gether *port,
  49. struct sk_buff *skb,
  50. struct sk_buff_head *list);
  51. /* called on network open/close */
  52. void (*open)(struct gether *);
  53. void (*close)(struct gether *);
  54. };
  55. #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
  56. |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
  57. |USB_CDC_PACKET_TYPE_PROMISCUOUS \
  58. |USB_CDC_PACKET_TYPE_DIRECTED)
  59. /* netdev setup/teardown as directed by the gadget driver */
  60. int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]);
  61. void gether_cleanup(void);
  62. /* connect/disconnect is handled by individual functions */
  63. struct net_device *gether_connect(struct gether *);
  64. void gether_disconnect(struct gether *);
  65. /* Some controllers can't support CDC Ethernet (ECM) ... */
  66. static inline bool can_support_ecm(struct usb_gadget *gadget)
  67. {
  68. if (!gadget_supports_altsettings(gadget))
  69. return false;
  70. /* Everything else is *presumably* fine ... but this is a bit
  71. * chancy, so be **CERTAIN** there are no hardware issues with
  72. * your controller. Add it above if it can't handle CDC.
  73. */
  74. return true;
  75. }
  76. /* each configuration may bind one instance of an ethernet link */
  77. int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
  78. int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
  79. int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
  80. int eem_bind_config(struct usb_configuration *c);
  81. #ifdef USB_ETH_RNDIS
  82. int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
  83. #else
  84. static inline int
  85. rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
  86. {
  87. return 0;
  88. }
  89. #endif
  90. #endif /* __U_ETHER_H */