usbnet.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * USB Networking Link Interface
  4. *
  5. * Copyright (C) 2000-2005 by David Brownell <[email protected]>
  6. * Copyright (C) 2003-2005 David Hollis <[email protected]>
  7. */
  8. #ifndef __LINUX_USB_USBNET_H
  9. #define __LINUX_USB_USBNET_H
  10. #include <linux/mii.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/skbuff.h>
  13. #include <linux/types.h>
  14. #include <linux/usb.h>
  15. #include <linux/android_kabi.h>
  16. /* interface from usbnet core to each USB networking link we handle */
  17. struct usbnet {
  18. /* housekeeping */
  19. struct usb_device *udev;
  20. struct usb_interface *intf;
  21. const struct driver_info *driver_info;
  22. const char *driver_name;
  23. void *driver_priv;
  24. wait_queue_head_t wait;
  25. struct mutex phy_mutex;
  26. unsigned char suspend_count;
  27. unsigned char pkt_cnt, pkt_err;
  28. unsigned short rx_qlen, tx_qlen;
  29. unsigned can_dma_sg:1;
  30. /* i/o info: pipes etc */
  31. unsigned in, out;
  32. struct usb_host_endpoint *status;
  33. unsigned maxpacket;
  34. struct timer_list delay;
  35. const char *padding_pkt;
  36. /* protocol/interface state */
  37. struct net_device *net;
  38. int msg_enable;
  39. unsigned long data[5];
  40. u32 xid;
  41. u32 hard_mtu; /* count any extra framing */
  42. size_t rx_urb_size; /* size for rx urbs */
  43. struct mii_if_info mii;
  44. long rx_speed; /* If MII not used */
  45. long tx_speed; /* If MII not used */
  46. # define SPEED_UNSET -1
  47. /* various kinds of pending driver work */
  48. struct sk_buff_head rxq;
  49. struct sk_buff_head txq;
  50. struct sk_buff_head done;
  51. struct sk_buff_head rxq_pause;
  52. struct urb *interrupt;
  53. unsigned interrupt_count;
  54. struct mutex interrupt_mutex;
  55. struct usb_anchor deferred;
  56. struct tasklet_struct bh;
  57. struct work_struct kevent;
  58. unsigned long flags;
  59. # define EVENT_TX_HALT 0
  60. # define EVENT_RX_HALT 1
  61. # define EVENT_RX_MEMORY 2
  62. # define EVENT_STS_SPLIT 3
  63. # define EVENT_LINK_RESET 4
  64. # define EVENT_RX_PAUSED 5
  65. # define EVENT_DEV_ASLEEP 6
  66. # define EVENT_DEV_OPEN 7
  67. # define EVENT_DEVICE_REPORT_IDLE 8
  68. # define EVENT_NO_RUNTIME_PM 9
  69. # define EVENT_RX_KILL 10
  70. # define EVENT_LINK_CHANGE 11
  71. # define EVENT_SET_RX_MODE 12
  72. # define EVENT_NO_IP_ALIGN 13
  73. ANDROID_KABI_RESERVE(1);
  74. ANDROID_KABI_RESERVE(2);
  75. ANDROID_KABI_RESERVE(3);
  76. ANDROID_KABI_RESERVE(4);
  77. };
  78. static inline struct usb_driver *driver_of(struct usb_interface *intf)
  79. {
  80. return to_usb_driver(intf->dev.driver);
  81. }
  82. /* interface from the device/framing level "minidriver" to core */
  83. struct driver_info {
  84. char *description;
  85. int flags;
  86. /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
  87. #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
  88. #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
  89. #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
  90. #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
  91. #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
  92. #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
  93. #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
  94. #define FLAG_WLAN 0x0080 /* use "wlan%d" names */
  95. #define FLAG_AVOID_UNLINK_URBS 0x0100 /* don't unlink urbs at usbnet_stop() */
  96. #define FLAG_SEND_ZLP 0x0200 /* hw requires ZLPs are sent */
  97. #define FLAG_WWAN 0x0400 /* use "wwan%d" names */
  98. #define FLAG_LINK_INTR 0x0800 /* updates link (carrier) status */
  99. #define FLAG_POINTTOPOINT 0x1000 /* possibly use "usb%d" names */
  100. /*
  101. * Indicates to usbnet, that USB driver accumulates multiple IP packets.
  102. * Affects statistic (counters) and short packet handling.
  103. */
  104. #define FLAG_MULTI_PACKET 0x2000
  105. #define FLAG_RX_ASSEMBLE 0x4000 /* rx packets may span >1 frames */
  106. #define FLAG_NOARP 0x8000 /* device can't do ARP */
  107. /* init device ... can sleep, or cause probe() failure */
  108. int (*bind)(struct usbnet *, struct usb_interface *);
  109. /* cleanup device ... can sleep, but can't fail */
  110. void (*unbind)(struct usbnet *, struct usb_interface *);
  111. /* reset device ... can sleep */
  112. int (*reset)(struct usbnet *);
  113. /* stop device ... can sleep */
  114. int (*stop)(struct usbnet *);
  115. /* see if peer is connected ... can sleep */
  116. int (*check_connect)(struct usbnet *);
  117. /* (dis)activate runtime power management */
  118. int (*manage_power)(struct usbnet *, int);
  119. /* for status polling */
  120. void (*status)(struct usbnet *, struct urb *);
  121. /* link reset handling, called from defer_kevent */
  122. int (*link_reset)(struct usbnet *);
  123. /* fixup rx packet (strip framing) */
  124. int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
  125. /* fixup tx packet (add framing) */
  126. struct sk_buff *(*tx_fixup)(struct usbnet *dev,
  127. struct sk_buff *skb, gfp_t flags);
  128. /* recover from timeout */
  129. void (*recover)(struct usbnet *dev);
  130. /* early initialization code, can sleep. This is for minidrivers
  131. * having 'subminidrivers' that need to do extra initialization
  132. * right after minidriver have initialized hardware. */
  133. int (*early_init)(struct usbnet *dev);
  134. /* called by minidriver when receiving indication */
  135. void (*indication)(struct usbnet *dev, void *ind, int indlen);
  136. /* rx mode change (device changes address list filtering) */
  137. void (*set_rx_mode)(struct usbnet *dev);
  138. /* for new devices, use the descriptor-reading code instead */
  139. int in; /* rx endpoint */
  140. int out; /* tx endpoint */
  141. unsigned long data; /* Misc driver specific data */
  142. ANDROID_KABI_RESERVE(1);
  143. ANDROID_KABI_RESERVE(2);
  144. };
  145. /* Minidrivers are just drivers using the "usbnet" core as a powerful
  146. * network-specific subroutine library ... that happens to do pretty
  147. * much everything except custom framing and chip-specific stuff.
  148. */
  149. extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *);
  150. extern int usbnet_suspend(struct usb_interface *, pm_message_t);
  151. extern int usbnet_resume(struct usb_interface *);
  152. extern void usbnet_disconnect(struct usb_interface *);
  153. extern void usbnet_device_suggests_idle(struct usbnet *dev);
  154. extern int usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
  155. u16 value, u16 index, void *data, u16 size);
  156. extern int usbnet_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
  157. u16 value, u16 index, const void *data, u16 size);
  158. extern int usbnet_read_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype,
  159. u16 value, u16 index, void *data, u16 size);
  160. extern int usbnet_write_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype,
  161. u16 value, u16 index, const void *data, u16 size);
  162. extern int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype,
  163. u16 value, u16 index, const void *data, u16 size);
  164. /* Drivers that reuse some of the standard USB CDC infrastructure
  165. * (notably, using multiple interfaces according to the CDC
  166. * union descriptor) get some helper code.
  167. */
  168. struct cdc_state {
  169. struct usb_cdc_header_desc *header;
  170. struct usb_cdc_union_desc *u;
  171. struct usb_cdc_ether_desc *ether;
  172. struct usb_interface *control;
  173. struct usb_interface *data;
  174. };
  175. extern void usbnet_cdc_update_filter(struct usbnet *dev);
  176. extern int usbnet_generic_cdc_bind(struct usbnet *, struct usb_interface *);
  177. extern int usbnet_ether_cdc_bind(struct usbnet *dev, struct usb_interface *intf);
  178. extern int usbnet_cdc_bind(struct usbnet *, struct usb_interface *);
  179. extern void usbnet_cdc_unbind(struct usbnet *, struct usb_interface *);
  180. extern void usbnet_cdc_status(struct usbnet *, struct urb *);
  181. extern int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb);
  182. /* CDC and RNDIS support the same host-chosen packet filters for IN transfers */
  183. #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
  184. |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
  185. |USB_CDC_PACKET_TYPE_PROMISCUOUS \
  186. |USB_CDC_PACKET_TYPE_DIRECTED)
  187. /* we record the state for each of our queued skbs */
  188. enum skb_state {
  189. illegal = 0,
  190. tx_start, tx_done,
  191. rx_start, rx_done, rx_cleanup,
  192. unlink_start
  193. };
  194. struct skb_data { /* skb->cb is one of these */
  195. struct urb *urb;
  196. struct usbnet *dev;
  197. enum skb_state state;
  198. long length;
  199. unsigned long packets;
  200. };
  201. /* Drivers that set FLAG_MULTI_PACKET must call this in their
  202. * tx_fixup method before returning an skb.
  203. */
  204. static inline void
  205. usbnet_set_skb_tx_stats(struct sk_buff *skb,
  206. unsigned long packets, long bytes_delta)
  207. {
  208. struct skb_data *entry = (struct skb_data *) skb->cb;
  209. entry->packets = packets;
  210. entry->length = bytes_delta;
  211. }
  212. extern int usbnet_open(struct net_device *net);
  213. extern int usbnet_stop(struct net_device *net);
  214. extern netdev_tx_t usbnet_start_xmit(struct sk_buff *skb,
  215. struct net_device *net);
  216. extern void usbnet_tx_timeout(struct net_device *net, unsigned int txqueue);
  217. extern int usbnet_change_mtu(struct net_device *net, int new_mtu);
  218. extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *);
  219. extern int usbnet_get_ethernet_addr(struct usbnet *, int);
  220. extern void usbnet_defer_kevent(struct usbnet *, int);
  221. extern void usbnet_skb_return(struct usbnet *, struct sk_buff *);
  222. extern void usbnet_unlink_rx_urbs(struct usbnet *);
  223. extern void usbnet_pause_rx(struct usbnet *);
  224. extern void usbnet_resume_rx(struct usbnet *);
  225. extern void usbnet_purge_paused_rxq(struct usbnet *);
  226. extern int usbnet_get_link_ksettings_mii(struct net_device *net,
  227. struct ethtool_link_ksettings *cmd);
  228. extern int usbnet_set_link_ksettings_mii(struct net_device *net,
  229. const struct ethtool_link_ksettings *cmd);
  230. extern int usbnet_get_link_ksettings_internal(struct net_device *net,
  231. struct ethtool_link_ksettings *cmd);
  232. extern u32 usbnet_get_link(struct net_device *net);
  233. extern u32 usbnet_get_msglevel(struct net_device *);
  234. extern void usbnet_set_msglevel(struct net_device *, u32);
  235. extern void usbnet_set_rx_mode(struct net_device *net);
  236. extern void usbnet_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
  237. extern int usbnet_nway_reset(struct net_device *net);
  238. extern int usbnet_manage_power(struct usbnet *, int);
  239. extern void usbnet_link_change(struct usbnet *, bool, bool);
  240. extern int usbnet_status_start(struct usbnet *dev, gfp_t mem_flags);
  241. extern void usbnet_status_stop(struct usbnet *dev);
  242. extern void usbnet_update_max_qlen(struct usbnet *dev);
  243. #endif /* __LINUX_USB_USBNET_H */