smscusbnet.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * USB Networking Link Interface
  3. *
  4. * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net>
  5. * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __SMSCUSBNET_H
  22. #define __SMSCUSBNET_H
  23. #ifndef DEBUG
  24. #define DEBUG
  25. #endif
  26. typedef unsigned char BOOLEAN;
  27. #define TRUE ((BOOLEAN)1)
  28. #define FALSE ((BOOLEAN)0)
  29. #define ID_REV_9500_CHIPID 0x9500
  30. #define ID_REV_9500A_CHIPID 0x9E00
  31. #define ID_REV_9512_CHIPID 0xEC00
  32. #define EXTRA_HEADER_LEN 8
  33. #define VLAN_DUMMY 0xFFFF
  34. enum{
  35. DEV_SMSC9500
  36. };
  37. #define RX_SKB_COPY
  38. enum{
  39. RX_FIXUP_VALID_SKB,
  40. RX_FIXUP_INVALID_SKB,
  41. RX_FIXUP_ERROR,
  42. };
  43. struct ExtraErrorCounter
  44. {
  45. u32 tx_epipe;
  46. u32 tx_eproto;
  47. u32 tx_etimeout;
  48. u32 tx_eilseq;
  49. u32 tx_eoverflow;
  50. u32 rx_epipe;
  51. u32 rx_eproto;
  52. u32 rx_etimeout;
  53. u32 rx_eilseq;
  54. u32 rx_eoverflow;
  55. };
  56. #define AUTOSUSPEND_DYNAMIC 0x01 //Suspend on s0, work for lan9500 and lan9500a
  57. #define AUTOSUSPEND_DYNAMIC_S3 0x02 //Suspend on s3, only for lan9500a
  58. #define AUTOSUSPEND_LINKDOWN 0x04 //Suspend when link is down
  59. #define AUTOSUSPEND_INTFDOWN 0x08 //Suspend when interface is down
  60. #define AUTOSUSPEND_DETACH 0x10 //Enable net detach
  61. enum{
  62. FEATURE_SUSPEND3,
  63. FEATURE_SMARTDETACH,
  64. FEATURE_NEWSTATIS_CNT,
  65. FEATURE_SEP_LEDS,
  66. FEATURE_WUFF_8,
  67. FEATURE_MDIX_MODE,
  68. FEATURE_EEE,
  69. FEATURE_MAX_NO
  70. };
  71. enum{
  72. EVENT_TX_HALT,
  73. EVENT_RX_HALT,
  74. EVENT_RX_MEMORY,
  75. EVENT_STS_SPLIT,
  76. EVENT_LINK_RESET,
  77. EVENT_SET_MULTICAST,
  78. EVENT_HAS_FRAME,
  79. EVENT_DEV_RECOVERY,
  80. EVENT_IDLE_CHECK,
  81. EVENT_IDLE_RESUME,
  82. EVENT_LINK_DOWN_DETACH,
  83. EVENT_LINK_UP,
  84. EVENT_LINK_DOWN,
  85. };
  86. /* interface from usbnet core to each USB networking link we handle */
  87. struct usbnet {
  88. /* housekeeping */
  89. struct usb_device *udev;
  90. struct usb_interface *uintf;
  91. struct driver_info *driver_info;
  92. wait_queue_head_t *wait;
  93. int StopSummitUrb;
  94. /* i/o info: pipes etc */
  95. unsigned in, out;
  96. struct usb_host_endpoint *status;
  97. unsigned maxpacket;
  98. struct timer_list delay;
  99. struct timer_list LinkPollingTimer;
  100. BOOLEAN StopLinkPolling;
  101. u16 idProduct; //Product id from device descriptor
  102. u16 idVendor; //Vendor id from device descriptor
  103. u32 linkDownSuspend; //1. auto-negotiation complete; 2. energy detection;
  104. u32 dynamicSuspend; //Enable dynamic suspend when there are no traffic
  105. u32 netDetach; //Enable net detach, only for LAN9500A
  106. /* protocol/interface state */
  107. struct net_device *net;
  108. struct net_device_stats stats;
  109. struct ExtraErrorCounter extra_error_cnts;
  110. int msg_enable;
  111. unsigned long data [5];
  112. u32 xid;
  113. u32 hard_mtu; /* count any extra framing */
  114. size_t rx_urb_size; /* size for rx urbs */
  115. struct mii_if_info mii;
  116. /* various kinds of pending driver work */
  117. struct sk_buff_head rxq;
  118. struct sk_buff_head txq;
  119. struct sk_buff_head tx_pending_q;
  120. struct sk_buff_head done;
  121. struct urb **rx_urb_pool; //idle urb pool
  122. unsigned int rx_urb_pool_head;
  123. unsigned int rx_urb_pool_tail;
  124. unsigned int rx_urb_pool_size;
  125. spinlock_t rx_urblist_lock;
  126. struct urb *tx_urb;
  127. struct urb *interrupt;
  128. void *interrupt_urb_buffer;
  129. struct tasklet_struct bh;
  130. struct work_struct kevent;
  131. struct work_struct myevent;
  132. struct workqueue_struct * MyWorkQueue;
  133. unsigned long flags;
  134. BOOLEAN intr_urb_delay_submit;
  135. int idleCount;
  136. int linkcheck;
  137. BOOLEAN pmLock;
  138. struct semaphore pm_mutex;
  139. int suspendFlag; //Flag indicates link down suspend and select suspend
  140. BOOLEAN netDetachDone;
  141. u32 chipID;
  142. u32 preRxFifoDroppedFrame; //Previous counter value
  143. int chipDependFeatures[FEATURE_MAX_NO]; //Flag for chip-depend feratures
  144. struct vlan_group *vlgrp; //vlan support
  145. int device_id; //DEV_SMSC9500
  146. int tx_hold_on_completion;
  147. };
  148. #define PM_IDLE_DELAY 3 //Time before auto-suspend
  149. enum{
  150. WAKEPHY_OFF,
  151. WAKEPHY_NEGO_COMPLETE,
  152. WAKEPHY_ENERGY
  153. };
  154. static inline struct usb_driver *driver_of(struct usb_interface *intf)
  155. {
  156. return to_usb_driver(intf->dev.driver);
  157. }
  158. /* interface from the device/framing level "minidriver" to core */
  159. struct driver_info {
  160. char *description;
  161. int flags;
  162. /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
  163. #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
  164. #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
  165. #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
  166. #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
  167. #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
  168. #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
  169. #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
  170. /* init device ... can sleep, or cause probe() failure */
  171. int (*bind)(struct usbnet *, struct usb_interface *);
  172. /* cleanup device ... can sleep, but can't fail */
  173. void (*unbind)(struct usbnet *, struct usb_interface *);
  174. /* reset device ... can sleep */
  175. int (*reset)(struct usbnet *);
  176. /* see if peer is connected ... can sleep */
  177. int (*check_connect)(struct usbnet *);
  178. /* for status polling */
  179. void (*status)(struct usbnet *, struct urb *);
  180. /* Set max frame size*/
  181. int (*set_max_frame_size)(struct usbnet *, int size);
  182. /* link reset handling, called from defer_kevent */
  183. int (*link_reset)(struct usbnet *);
  184. /* fixup rx packet (strip framing) */
  185. int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
  186. /*set multicast list */
  187. int (*rx_setmulticastlist) (struct usbnet *dev);
  188. /* fixup tx packet (add framing) */
  189. struct sk_buff *(*tx_fixup)(struct usbnet *dev,
  190. struct sk_buff *skb, int flags);
  191. /* for new devices, use the descriptor-reading code instead */
  192. int in; /* rx endpoint */
  193. int out; /* tx endpoint */
  194. unsigned long data; /* Misc driver specific data */
  195. };
  196. /* Minidrivers are just drivers using the "usbnet" core as a powerful
  197. * network-specific subroutine library ... that happens to do pretty
  198. * much everything except custom framing and chip-specific stuff.
  199. */
  200. extern int smscusbnet_probe(struct usb_interface *, const struct usb_device_id *);
  201. extern void smscusbnet_disconnect(struct usb_interface *);
  202. extern void smscusbnet_linkpolling(unsigned long ptr);
  203. /* Drivers that reuse some of the standard USB CDC infrastructure
  204. * (notably, using multiple interfaces according to the the CDC
  205. * union descriptor) get some helper code.
  206. */
  207. struct cdc_state {
  208. struct usb_cdc_header_desc *header;
  209. struct usb_cdc_union_desc *u;
  210. struct usb_cdc_ether_desc *ether;
  211. struct usb_interface *control;
  212. struct usb_interface *data;
  213. };
  214. extern int usbnet_generic_cdc_bind (struct usbnet *, struct usb_interface *);
  215. extern void usbnet_cdc_unbind (struct usbnet *, struct usb_interface *);
  216. /* CDC and RNDIS support the same host-chosen packet filters for IN transfers */
  217. #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
  218. |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
  219. |USB_CDC_PACKET_TYPE_PROMISCUOUS \
  220. |USB_CDC_PACKET_TYPE_DIRECTED)
  221. /* we record the state for each of our queued skbs */
  222. enum skb_state {
  223. illegal = 0,
  224. tx_start, tx_done,
  225. rx_start, rx_done, rx_cleanup
  226. };
  227. struct skb_data { /* skb->cb is one of these */
  228. struct urb *urb;
  229. struct usbnet *dev;
  230. enum skb_state state;
  231. size_t length;
  232. size_t pkt_cnt;
  233. };
  234. extern int smscusbnet_IsOperationalMode(struct usbnet *);
  235. extern int smscusbnet_get_endpoints(struct usbnet *, struct usb_interface *);
  236. extern void smscusbnet_defer_kevent (struct usbnet *, int);
  237. extern void smscusbnet_defer_myevent (struct usbnet *, int);
  238. extern void smscusbnet_skb_return (struct usbnet *, struct sk_buff *);
  239. extern int summit_IntrUrb (struct usbnet *dev);
  240. extern u32 smscusbnet_get_msglevel (struct net_device *);
  241. extern void smscusbnet_set_msglevel (struct net_device *, u32);
  242. extern void smscusbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
  243. extern int smscusbnet_FreeQueue (struct usbnet *dev);
  244. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
  245. extern int smscusbnet_stop (struct net_device *net);
  246. extern struct net_device_stats *smscusbnet_get_stats (struct net_device *net);
  247. extern int smscusbnet_open (struct net_device *net);
  248. extern int smscusbnet_start_xmit (struct sk_buff *skb, struct net_device *net);
  249. extern int smscusbnet_change_mtu (struct net_device *net, int new_mtu);
  250. extern void smscusbnet_tx_timeout (struct net_device *net);
  251. #endif
  252. /* messaging support includes the interface name, so it must not be
  253. * used before it has one ... notably, in minidriver bind() calls.
  254. */
  255. #ifdef DEBUG
  256. #define devdbg(usbnet, fmt, arg...) \
  257. printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
  258. #else
  259. #define devdbg(usbnet, fmt, arg...) do {} while(0)
  260. #endif
  261. #define deverr(usbnet, fmt, arg...) \
  262. printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
  263. #define devwarn(usbnet, fmt, arg...) \
  264. printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
  265. #define devinfo(usbnet, fmt, arg...) \
  266. printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
  267. #endif /* __smscusbnet_H */