viatel_rawbulk.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Rawbulk Driver from VIA Telecom
  3. *
  4. * Copyright (C) 2011 VIA Telecom, Inc.
  5. * Author: Karfield Chen (kfchen@via-telecom.com)
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #ifndef __RAWBULK_H__
  18. #define __RAWBULK_H__
  19. #include <linux/usb.h>
  20. #include <linux/usb/ch9.h>
  21. #include <linux/usb/composite.h>
  22. #include <linux/usb/gadget.h>
  23. #include <linux/wakelock.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/device.h>
  26. #include <linux/tty.h>
  27. #include <linux/tty_driver.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/kthread.h>
  30. #include <linux/wait.h>
  31. #include <linux/sched.h>
  32. #define INTF_DESC 0
  33. #define BULKIN_DESC 1
  34. #define BULKOUT_DESC 2
  35. #define MAX_DESC_ARRAY 4
  36. #define NAME_BUFFSIZE 64
  37. #define MAX_ATTRIBUTES 10
  38. #define MAX_TTY_RX 8
  39. #define MAX_TTY_RX_PACKAGE 512
  40. #define MAX_TTY_TX 8
  41. #define MAX_TTY_TX_PACKAGE 512
  42. /* #define CONFIG_EVDO_DT_VIA_SUPPORT */
  43. #ifdef CONFIG_EVDO_DT_VIA_SUPPORT
  44. enum transfer_id {
  45. RAWBULK_TID_MODEM,
  46. RAWBULK_TID_ETS,
  47. RAWBULK_TID_AT,
  48. RAWBULK_TID_PCV,
  49. RAWBULK_TID_GPS,
  50. _MAX_TID
  51. };
  52. #else
  53. enum transfer_id {
  54. RAWBULK_TID_PCV,
  55. RAWBULK_TID_MODEM,
  56. RAWBULK_TID_ETS,
  57. RAWBULK_TID_AT,
  58. RAWBULK_TID_GPS,
  59. _MAX_TID
  60. };
  61. #endif
  62. struct rawbulk_function {
  63. int transfer_id;
  64. const char *longname;
  65. const char *shortname;
  66. struct device *dev;
  67. /* Controls */
  68. spinlock_t lock;
  69. int enable:1;
  70. int activated:1; /* set when usb enabled */
  71. int tty_opened:1;
  72. int initialized:1; /* init-flag for activator worker */
  73. struct work_struct activator; /* asynic transaction starter */
  74. struct wake_lock keep_awake;
  75. /* USB Gadget related */
  76. struct usb_function function;
  77. struct usb_composite_dev *cdev;
  78. struct usb_ep *bulk_out, *bulk_in;
  79. int rts_state; /* Handshaking pins (outputs) */
  80. int dtr_state;
  81. int cts_state; /* Handshaking pins (inputs) */
  82. int dsr_state;
  83. int dcd_state;
  84. int ri_state;
  85. /* TTY related */
  86. struct tty_struct *tty;
  87. int tty_minor;
  88. struct tty_port port;
  89. spinlock_t tx_lock;
  90. struct list_head tx_free;
  91. struct list_head tx_inproc;
  92. spinlock_t rx_lock;
  93. struct list_head rx_free;
  94. struct list_head rx_inproc;
  95. struct list_head rx_throttled;
  96. unsigned int last_pushed;
  97. struct workqueue_struct *tty_push_wq;
  98. struct work_struct tty_push_work;
  99. int tty_throttled;
  100. /* Transfer Controls */
  101. int nups;
  102. int ndowns;
  103. int upsz;
  104. int downsz;
  105. /* int splitsz; */
  106. int autoreconn;
  107. int pushable; /* Set to use push-way for upstream */
  108. int cbp_reset;
  109. /* Descriptors and Strings */
  110. struct usb_descriptor_header *fs_descs[MAX_DESC_ARRAY];
  111. struct usb_descriptor_header *hs_descs[MAX_DESC_ARRAY];
  112. struct usb_string string_defs[2];
  113. struct usb_gadget_strings string_table;
  114. struct usb_gadget_strings *strings[2];
  115. struct usb_interface_descriptor interface;
  116. struct usb_endpoint_descriptor fs_bulkin_endpoint;
  117. struct usb_endpoint_descriptor hs_bulkin_endpoint;
  118. struct usb_endpoint_descriptor fs_bulkout_endpoint;
  119. struct usb_endpoint_descriptor hs_bulkout_endpoint;
  120. /* Sysfs Accesses */
  121. int max_attrs;
  122. struct device_attribute attr[MAX_ATTRIBUTES];
  123. };
  124. typedef void (*rawbulk_autoreconn_callback_t) (int transfer_id);
  125. /* bind/unbind host interfaces */
  126. int rawbulk_bind_sdio_channel(int transfer_id);
  127. void rawbulk_unbind_sdio_channel(int transfer_id);
  128. struct rawbulk_function *rawbulk_lookup_function(int transfer_id);
  129. /* rawbulk tty io */
  130. int rawbulk_register_tty(struct rawbulk_function *fn);
  131. void rawbulk_unregister_tty(struct rawbulk_function *fn);
  132. int rawbulk_tty_stop_io(struct rawbulk_function *fn);
  133. int rawbulk_tty_start_io(struct rawbulk_function *fn);
  134. int rawbulk_tty_alloc_request(struct rawbulk_function *fn);
  135. void rawbulk_tty_free_request(struct rawbulk_function *fn);
  136. /* bind/unbind for gadget */
  137. int rawbulk_bind_function(int transfer_id, struct usb_function *function,
  138. struct usb_ep *bulk_out, struct usb_ep *bulk_in,
  139. rawbulk_autoreconn_callback_t autoreconn_callback);
  140. void rawbulk_unbind_function(int trasfer_id);
  141. int rawbulk_check_enable(struct rawbulk_function *fn);
  142. void rawbulk_disable_function(struct rawbulk_function *fn);
  143. /* operations for transactions */
  144. int rawbulk_start_transactions(int transfer_id, int nups, int ndowns, int upsz, int downsz);
  145. void rawbulk_stop_transactions(int transfer_id);
  146. int rawbulk_push_upstream_buffer(int transfer_id, const void *buffer, unsigned int length);
  147. int rawbulk_transfer_statistics(int transfer_id, char *buf);
  148. int rawbulk_transfer_state(int transfer_id);
  149. extern int modem_dtr_set(int on, int low_latency);
  150. extern int modem_dcd_state(void);
  151. extern int sdio_buffer_push(int port_num, const unsigned char *buf, int count);
  152. extern int sdio_rawbulk_intercept(int port_num, unsigned int inception);
  153. /* debug mechanism */
  154. extern unsigned int c2k_usb_dbg_level; /* refer to rawbulk_transfer.c */
  155. static inline int c2k_dbg_level(unsigned level)
  156. {
  157. return c2k_usb_dbg_level >= level;
  158. }
  159. #define C2K_LOG_EMERG 0
  160. #define C2K_LOG_ALERT 1
  161. #define C2K_LOG_CRIT 2
  162. #define C2K_LOG_ERR 3
  163. #define C2K_LOG_WARN 4
  164. #define C2K_LOG_NOTICE 5
  165. #define C2K_LOG_INFO 6
  166. #define C2K_LOG_DBG 7
  167. #define C2K_USB_DBG_ON
  168. #ifdef C2K_USB_DBG_ON
  169. #define C2K_ERR(format, args...) do {if (c2k_dbg_level(C2K_LOG_ERR)) \
  170. pr_warn("C2K_USB_ERR,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  171. while (0)
  172. #define C2K_WARN(format, args...) do {if (c2k_dbg_level(C2K_LOG_WARN)) \
  173. pr_warn("C2K_USB_WARN,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  174. while (0)
  175. #define C2K_NOTE(format, args...) do {if (c2k_dbg_level(C2K_LOG_NOTICE)) \
  176. pr_warn("C2K_USB_NOTE,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  177. while (0)
  178. #define C2K_INFO(format, args...) do {if (c2k_dbg_level(C2K_LOG_INFO)) \
  179. pr_warn("C2K_USB_INFO,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  180. while (0)
  181. #define C2K_DBG(format, args...) do {if (c2k_dbg_level(C2K_LOG_DBG)) \
  182. pr_warn("C2K_USB_DBG,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  183. while (0)
  184. #else
  185. #define C2K_ERR(format, args...) do {} while (0)
  186. #define C2K_WARN(format, args...) do {} while (0)
  187. #define C2K_NOTE(format, args...) do {} while (0)
  188. #define C2K_INFO(format, args...) do {} while (0)
  189. #define C2K_DBG(format, args...) do {} while (0)
  190. #endif
  191. extern unsigned int upstream_data[_MAX_TID];
  192. extern unsigned int upstream_cnt[_MAX_TID];
  193. extern unsigned int total_drop[_MAX_TID];
  194. extern unsigned int alloc_fail[_MAX_TID];
  195. extern unsigned int total_tran[_MAX_TID];
  196. extern unsigned long volatile jiffies;
  197. extern int modem_buffer_push(int port_num, void *buf, int count);
  198. #ifdef C2K_USB_UT
  199. extern int delay_set;
  200. extern int ut_err;
  201. #endif
  202. #endif /* __RAWBULK_HEADER_FILE__ */