u_ether.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifndef __U_ETHER_H
  23. #define __U_ETHER_H
  24. #include <linux/err.h>
  25. #include <linux/if_ether.h>
  26. #include <linux/usb/composite.h>
  27. #include <linux/usb/cdc.h>
  28. #include "gadget_chips.h"
  29. /*
  30. * This represents the USB side of an "ethernet" link, managed by a USB
  31. * function which provides control and (maybe) framing. Two functions
  32. * in different configurations could share the same ethernet link/netdev.
  33. *
  34. * There is currently a limitation that one instance of this function
  35. * may be present in any given configuration.
  36. */
  37. struct gether {
  38. struct usb_function func;
  39. /* updated by gether_{connect,disconnect} */
  40. struct eth_dev *ioport;
  41. /* endpoints handle full and/or high speeds */
  42. struct usb_ep *in_ep;
  43. struct usb_ep *out_ep;
  44. /* descriptors match device speed at gether_connect() time */
  45. struct usb_endpoint_descriptor *in;
  46. struct usb_endpoint_descriptor *out;
  47. bool is_zlp_ok;
  48. u16 cdc_filter;
  49. /* hooks for added framing, as needed for RNDIS and EEM.
  50. * we currently don't support multiple frames per SKB.
  51. */
  52. u32 header_len;
  53. struct sk_buff *(*wrap)(struct sk_buff *skb);
  54. int (*unwrap)(struct sk_buff *skb);
  55. /* called on network open/close */
  56. void (*open)(struct gether *);
  57. void (*close)(struct gether *);
  58. };
  59. #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
  60. |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
  61. |USB_CDC_PACKET_TYPE_PROMISCUOUS \
  62. |USB_CDC_PACKET_TYPE_DIRECTED)
  63. /* netdev setup/teardown as directed by the gadget driver */
  64. int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]);
  65. void gether_cleanup(void);
  66. /* connect/disconnect is handled by individual functions */
  67. struct net_device *gether_connect(struct gether *);
  68. void gether_disconnect(struct gether *);
  69. /* Some controllers can't support CDC Ethernet (ECM) ... */
  70. static inline bool can_support_ecm(struct usb_gadget *gadget)
  71. {
  72. if (!gadget_supports_altsettings(gadget))
  73. return false;
  74. /* SA1100 can do ECM, *without* status endpoint ... but we'll
  75. * only use it in non-ECM mode for backwards compatibility
  76. * (and since we currently require a status endpoint)
  77. */
  78. if (gadget_is_sa1100(gadget))
  79. return false;
  80. /* Everything else is *presumably* fine ... but this is a bit
  81. * chancy, so be **CERTAIN** there are no hardware issues with
  82. * your controller. Add it above if it can't handle CDC.
  83. */
  84. return true;
  85. }
  86. /* each configuration may bind one instance of an ethernet link */
  87. int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
  88. int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
  89. #endif /* __U_ETHER_H */