usbatm.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /******************************************************************************
  2. * usbatm.h - Generic USB xDSL driver core
  3. *
  4. * Copyright (C) 2001, Alcatel
  5. * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
  6. * Copyright (C) 2004, David Woodhouse
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc., 59
  20. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. ******************************************************************************/
  23. #ifndef _USBATM_H_
  24. #define _USBATM_H_
  25. #include <linux/atm.h>
  26. #include <linux/atmdev.h>
  27. #include <linux/completion.h>
  28. #include <linux/device.h>
  29. #include <linux/kernel.h>
  30. #include <linux/kref.h>
  31. #include <linux/list.h>
  32. #include <linux/stringify.h>
  33. #include <linux/usb.h>
  34. #include <linux/mutex.h>
  35. /*
  36. #define VERBOSE_DEBUG
  37. */
  38. #ifdef DEBUG
  39. #define UDSL_ASSERT(instance, x) BUG_ON(!(x))
  40. #else
  41. #define UDSL_ASSERT(instance, x) \
  42. do { \
  43. if (!(x)) \
  44. dev_warn(&(instance)->usb_intf->dev, \
  45. "failed assertion '%s' at line %d", \
  46. __stringify(x), __LINE__); \
  47. } while (0)
  48. #endif
  49. #define usb_err(instance, format, arg...) \
  50. dev_err(&(instance)->usb_intf->dev , format , ## arg)
  51. #define usb_info(instance, format, arg...) \
  52. dev_info(&(instance)->usb_intf->dev , format , ## arg)
  53. #define usb_warn(instance, format, arg...) \
  54. dev_warn(&(instance)->usb_intf->dev , format , ## arg)
  55. #ifdef DEBUG
  56. #define usb_dbg(instance, format, arg...) \
  57. dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
  58. #else
  59. #define usb_dbg(instance, format, arg...) \
  60. do {} while (0)
  61. #endif
  62. /* FIXME: move to dev_* once ATM is driver model aware */
  63. #define atm_printk(level, instance, format, arg...) \
  64. printk(level "ATM dev %d: " format , \
  65. (instance)->atm_dev->number , ## arg)
  66. #define atm_err(instance, format, arg...) \
  67. atm_printk(KERN_ERR, instance , format , ## arg)
  68. #define atm_info(instance, format, arg...) \
  69. atm_printk(KERN_INFO, instance , format , ## arg)
  70. #define atm_warn(instance, format, arg...) \
  71. atm_printk(KERN_WARNING, instance , format , ## arg)
  72. #ifdef DEBUG
  73. #define atm_dbg(instance, format, arg...) \
  74. atm_printk(KERN_DEBUG, instance , format , ## arg)
  75. #define atm_rldbg(instance, format, arg...) \
  76. if (printk_ratelimit()) \
  77. atm_printk(KERN_DEBUG, instance , format , ## arg)
  78. #else
  79. #define atm_dbg(instance, format, arg...) \
  80. do {} while (0)
  81. #define atm_rldbg(instance, format, arg...) \
  82. do {} while (0)
  83. #endif
  84. /* flags, set by mini-driver in bind() */
  85. #define UDSL_SKIP_HEAVY_INIT (1<<0)
  86. #define UDSL_USE_ISOC (1<<1)
  87. #define UDSL_IGNORE_EILSEQ (1<<2)
  88. /* mini driver */
  89. struct usbatm_data;
  90. /*
  91. * Assuming all methods exist and succeed, they are called in this order:
  92. *
  93. * bind, heavy_init, atm_start, ..., atm_stop, unbind
  94. */
  95. struct usbatm_driver {
  96. const char *driver_name;
  97. /* init device ... can sleep, or cause probe() failure */
  98. int (*bind) (struct usbatm_data *, struct usb_interface *,
  99. const struct usb_device_id *id);
  100. /* additional device initialization that is too slow to be done in probe() */
  101. int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
  102. /* cleanup device ... can sleep, but can't fail */
  103. void (*unbind) (struct usbatm_data *, struct usb_interface *);
  104. /* init ATM device ... can sleep, or cause ATM initialization failure */
  105. int (*atm_start) (struct usbatm_data *, struct atm_dev *);
  106. /* cleanup ATM device ... can sleep, but can't fail */
  107. void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
  108. int bulk_in; /* bulk rx endpoint */
  109. int isoc_in; /* isochronous rx endpoint */
  110. int bulk_out; /* bulk tx endpoint */
  111. unsigned rx_padding;
  112. unsigned tx_padding;
  113. };
  114. extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
  115. struct usbatm_driver *driver);
  116. extern void usbatm_usb_disconnect(struct usb_interface *intf);
  117. struct usbatm_channel {
  118. int endpoint; /* usb pipe */
  119. unsigned int stride; /* ATM cell size + padding */
  120. unsigned int buf_size; /* urb buffer size */
  121. unsigned int packet_size; /* endpoint maxpacket */
  122. spinlock_t lock;
  123. struct list_head list;
  124. struct tasklet_struct tasklet;
  125. struct timer_list delay;
  126. struct usbatm_data *usbatm;
  127. };
  128. /* main driver data */
  129. struct usbatm_data {
  130. /******************
  131. * public fields *
  132. ******************/
  133. /* mini driver */
  134. struct usbatm_driver *driver;
  135. void *driver_data;
  136. char driver_name[16];
  137. unsigned int flags; /* set by mini-driver in bind() */
  138. /* USB device */
  139. struct usb_device *usb_dev;
  140. struct usb_interface *usb_intf;
  141. char description[64];
  142. /* ATM device */
  143. struct atm_dev *atm_dev;
  144. /********************************
  145. * private fields - do not use *
  146. ********************************/
  147. struct kref refcount;
  148. struct mutex serialize;
  149. int disconnected;
  150. /* heavy init */
  151. struct task_struct *thread;
  152. struct completion thread_started;
  153. struct completion thread_exited;
  154. /* ATM device */
  155. struct list_head vcc_list;
  156. struct usbatm_channel rx_channel;
  157. struct usbatm_channel tx_channel;
  158. struct sk_buff_head sndqueue;
  159. struct sk_buff *current_skb; /* being emptied */
  160. struct usbatm_vcc_data *cached_vcc;
  161. int cached_vci;
  162. short cached_vpi;
  163. unsigned char *cell_buf; /* holds partial rx cell */
  164. unsigned int buf_usage;
  165. struct urb *urbs[0];
  166. };
  167. static inline void *to_usbatm_driver_data(struct usb_interface *intf)
  168. {
  169. struct usbatm_data *usbatm_instance;
  170. if (intf == NULL)
  171. return NULL;
  172. usbatm_instance = usb_get_intfdata(intf);
  173. if (usbatm_instance == NULL) /* set NULL before unbind() */
  174. return NULL;
  175. return usbatm_instance->driver_data; /* set NULL after unbind() */
  176. }
  177. #endif /* _USBATM_H_ */