usbatm.h 5.7 KB

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