usb_atm.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /******************************************************************************
  2. * usb_atm.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. #include <linux/config.h>
  24. #include <linux/list.h>
  25. #include <linux/kref.h>
  26. #include <linux/atm.h>
  27. #include <linux/atmdev.h>
  28. #include <asm/semaphore.h>
  29. /*
  30. #define DEBUG
  31. #define VERBOSE_DEBUG
  32. */
  33. #if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
  34. # define DEBUG
  35. #endif
  36. #include <linux/usb.h>
  37. #ifdef DEBUG
  38. #define UDSL_ASSERT(x) BUG_ON(!(x))
  39. #else
  40. #define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '" #x "' at line %d", __LINE__); } while(0)
  41. #endif
  42. #define UDSL_MAX_RCV_URBS 4
  43. #define UDSL_MAX_SND_URBS 4
  44. #define UDSL_MAX_RCV_BUFS 8
  45. #define UDSL_MAX_SND_BUFS 8
  46. #define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */
  47. #define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
  48. #define UDSL_DEFAULT_RCV_URBS 2
  49. #define UDSL_DEFAULT_SND_URBS 2
  50. #define UDSL_DEFAULT_RCV_BUFS 4
  51. #define UDSL_DEFAULT_SND_BUFS 4
  52. #define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */
  53. #define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */
  54. #define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
  55. #define UDSL_NUM_CELLS(x) (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 1) / ATM_CELL_PAYLOAD)
  56. /* receive */
  57. struct udsl_receive_buffer {
  58. struct list_head list;
  59. unsigned char *base;
  60. unsigned int filled_cells;
  61. };
  62. struct udsl_receiver {
  63. struct list_head list;
  64. struct udsl_receive_buffer *buffer;
  65. struct urb *urb;
  66. struct udsl_instance_data *instance;
  67. };
  68. struct udsl_vcc_data {
  69. /* vpi/vci lookup */
  70. struct list_head list;
  71. short vpi;
  72. int vci;
  73. struct atm_vcc *vcc;
  74. /* raw cell reassembly */
  75. struct sk_buff *sarb;
  76. };
  77. /* send */
  78. struct udsl_send_buffer {
  79. struct list_head list;
  80. unsigned char *base;
  81. unsigned char *free_start;
  82. unsigned int free_cells;
  83. };
  84. struct udsl_sender {
  85. struct list_head list;
  86. struct udsl_send_buffer *buffer;
  87. struct urb *urb;
  88. struct udsl_instance_data *instance;
  89. };
  90. struct udsl_control {
  91. struct atm_skb_data atm_data;
  92. unsigned int num_cells;
  93. unsigned int num_entire;
  94. unsigned int pdu_padding;
  95. unsigned char aal5_trailer[ATM_AAL5_TRAILER];
  96. };
  97. #define UDSL_SKB(x) ((struct udsl_control *)(x)->cb)
  98. /* main driver data */
  99. enum udsl_status {
  100. UDSL_NO_FIRMWARE,
  101. UDSL_LOADING_FIRMWARE,
  102. UDSL_LOADED_FIRMWARE
  103. };
  104. struct udsl_instance_data {
  105. struct kref refcount;
  106. struct semaphore serialize;
  107. /* USB device part */
  108. struct usb_device *usb_dev;
  109. char description[64];
  110. int data_endpoint;
  111. int snd_padding;
  112. int rcv_padding;
  113. const char *driver_name;
  114. /* ATM device part */
  115. struct atm_dev *atm_dev;
  116. struct list_head vcc_list;
  117. /* firmware */
  118. int (*firmware_wait) (struct udsl_instance_data *);
  119. enum udsl_status status;
  120. wait_queue_head_t firmware_waiters;
  121. /* receive */
  122. struct udsl_receiver receivers[UDSL_MAX_RCV_URBS];
  123. struct udsl_receive_buffer receive_buffers[UDSL_MAX_RCV_BUFS];
  124. spinlock_t receive_lock;
  125. struct list_head spare_receivers;
  126. struct list_head filled_receive_buffers;
  127. struct tasklet_struct receive_tasklet;
  128. struct list_head spare_receive_buffers;
  129. /* send */
  130. struct udsl_sender senders[UDSL_MAX_SND_URBS];
  131. struct udsl_send_buffer send_buffers[UDSL_MAX_SND_BUFS];
  132. struct sk_buff_head sndqueue;
  133. spinlock_t send_lock;
  134. struct list_head spare_senders;
  135. struct list_head spare_send_buffers;
  136. struct tasklet_struct send_tasklet;
  137. struct sk_buff *current_skb; /* being emptied */
  138. struct udsl_send_buffer *current_buffer; /* being filled */
  139. struct list_head filled_send_buffers;
  140. };
  141. extern int udsl_instance_setup(struct usb_device *dev,
  142. struct udsl_instance_data *instance);
  143. extern void udsl_instance_disconnect(struct udsl_instance_data *instance);
  144. extern void udsl_get_instance(struct udsl_instance_data *instance);
  145. extern void udsl_put_instance(struct udsl_instance_data *instance);