usbatm.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 <asm/semaphore.h>
  26. #include <linux/atm.h>
  27. #include <linux/atmdev.h>
  28. #include <linux/completion.h>
  29. #include <linux/device.h>
  30. #include <linux/kernel.h>
  31. #include <linux/kref.h>
  32. #include <linux/list.h>
  33. #include <linux/stringify.h>
  34. #include <linux/usb.h>
  35. #include <linux/mutex.h>
  36. /*
  37. #define VERBOSE_DEBUG
  38. */
  39. #ifdef DEBUG
  40. #define UDSL_ASSERT(x) BUG_ON(!(x))
  41. #else
  42. #define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0)
  43. #endif
  44. #define usb_err(instance, format, arg...) \
  45. dev_err(&(instance)->usb_intf->dev , format , ## arg)
  46. #define usb_info(instance, format, arg...) \
  47. dev_info(&(instance)->usb_intf->dev , format , ## arg)
  48. #define usb_warn(instance, format, arg...) \
  49. dev_warn(&(instance)->usb_intf->dev , format , ## arg)
  50. #ifdef DEBUG
  51. #define usb_dbg(instance, format, arg...) \
  52. dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
  53. #else
  54. #define usb_dbg(instance, format, arg...) \
  55. do {} while (0)
  56. #endif
  57. /* FIXME: move to dev_* once ATM is driver model aware */
  58. #define atm_printk(level, instance, format, arg...) \
  59. printk(level "ATM dev %d: " format , \
  60. (instance)->atm_dev->number , ## arg)
  61. #define atm_err(instance, format, arg...) \
  62. atm_printk(KERN_ERR, instance , format , ## arg)
  63. #define atm_info(instance, format, arg...) \
  64. atm_printk(KERN_INFO, instance , format , ## arg)
  65. #define atm_warn(instance, format, arg...) \
  66. atm_printk(KERN_WARNING, instance , format , ## arg)
  67. #ifdef DEBUG
  68. #define atm_dbg(instance, format, arg...) \
  69. atm_printk(KERN_DEBUG, instance , format , ## arg)
  70. #define atm_rldbg(instance, format, arg...) \
  71. if (printk_ratelimit()) \
  72. atm_printk(KERN_DEBUG, instance , format , ## arg)
  73. #else
  74. #define atm_dbg(instance, format, arg...) \
  75. do {} while (0)
  76. #define atm_rldbg(instance, format, arg...) \
  77. do {} while (0)
  78. #endif
  79. /* flags, set by mini-driver in bind() */
  80. #define UDSL_SKIP_HEAVY_INIT (1<<0)
  81. #define UDSL_USE_ISOC (1<<1)
  82. #define UDSL_IGNORE_EILSEQ (1<<2)
  83. /* mini driver */
  84. struct usbatm_data;
  85. /*
  86. * Assuming all methods exist and succeed, they are called in this order:
  87. *
  88. * bind, heavy_init, atm_start, ..., atm_stop, unbind
  89. */
  90. struct usbatm_driver {
  91. const char *driver_name;
  92. /* init device ... can sleep, or cause probe() failure */
  93. int (*bind) (struct usbatm_data *, struct usb_interface *,
  94. const struct usb_device_id *id);
  95. /* additional device initialization that is too slow to be done in probe() */
  96. int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
  97. /* cleanup device ... can sleep, but can't fail */
  98. void (*unbind) (struct usbatm_data *, struct usb_interface *);
  99. /* init ATM device ... can sleep, or cause ATM initialization failure */
  100. int (*atm_start) (struct usbatm_data *, struct atm_dev *);
  101. /* cleanup ATM device ... can sleep, but can't fail */
  102. void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
  103. int bulk_in; /* bulk rx endpoint */
  104. int isoc_in; /* isochronous rx endpoint */
  105. int bulk_out; /* bulk tx endpoint */
  106. unsigned rx_padding;
  107. unsigned tx_padding;
  108. };
  109. extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
  110. struct usbatm_driver *driver);
  111. extern void usbatm_usb_disconnect(struct usb_interface *intf);
  112. struct usbatm_channel {
  113. int endpoint; /* usb pipe */
  114. unsigned int stride; /* ATM cell size + padding */
  115. unsigned int buf_size; /* urb buffer size */
  116. unsigned int packet_size; /* endpoint maxpacket */
  117. spinlock_t lock;
  118. struct list_head list;
  119. struct tasklet_struct tasklet;
  120. struct timer_list delay;
  121. struct usbatm_data *usbatm;
  122. };
  123. /* main driver data */
  124. struct usbatm_data {
  125. /******************
  126. * public fields *
  127. ******************/
  128. /* mini driver */
  129. struct usbatm_driver *driver;
  130. void *driver_data;
  131. char driver_name[16];
  132. unsigned int flags; /* set by mini-driver in bind() */
  133. /* USB device */
  134. struct usb_device *usb_dev;
  135. struct usb_interface *usb_intf;
  136. char description[64];
  137. /* ATM device */
  138. struct atm_dev *atm_dev;
  139. /********************************
  140. * private fields - do not use *
  141. ********************************/
  142. struct kref refcount;
  143. struct mutex serialize;
  144. int disconnected;
  145. /* heavy init */
  146. int thread_pid;
  147. struct completion thread_started;
  148. struct completion thread_exited;
  149. /* ATM device */
  150. struct list_head vcc_list;
  151. struct usbatm_channel rx_channel;
  152. struct usbatm_channel tx_channel;
  153. struct sk_buff_head sndqueue;
  154. struct sk_buff *current_skb; /* being emptied */
  155. struct usbatm_vcc_data *cached_vcc;
  156. int cached_vci;
  157. short cached_vpi;
  158. unsigned char *cell_buf; /* holds partial rx cell */
  159. unsigned int buf_usage;
  160. struct urb *urbs[0];
  161. };
  162. #endif /* _USBATM_H_ */