viatel_rawbulk.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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_DUMMY0,
  57. RAWBULK_TID_AT,
  58. RAWBULK_TID_GPS,
  59. RAWBULK_TID_DUMMY1,
  60. RAWBULK_TID_DUMMY2,
  61. RAWBULK_TID_ETS,
  62. _MAX_TID
  63. };
  64. #endif
  65. struct rawbulk_function {
  66. int transfer_id;
  67. const char *longname;
  68. const char *shortname;
  69. struct device *dev;
  70. /* Controls */
  71. spinlock_t lock;
  72. int enable:1;
  73. int activated:1; /* set when usb enabled */
  74. int tty_opened:1;
  75. int initialized:1; /* init-flag for activator worker */
  76. struct work_struct activator; /* asynic transaction starter */
  77. struct wake_lock keep_awake;
  78. /* USB Gadget related */
  79. struct usb_function function;
  80. struct usb_composite_dev *cdev;
  81. struct usb_ep *bulk_out, *bulk_in;
  82. int rts_state; /* Handshaking pins (outputs) */
  83. int dtr_state;
  84. int cts_state; /* Handshaking pins (inputs) */
  85. int dsr_state;
  86. int dcd_state;
  87. int ri_state;
  88. /* TTY related */
  89. struct tty_struct *tty;
  90. int tty_minor;
  91. struct tty_port port;
  92. spinlock_t tx_lock;
  93. struct list_head tx_free;
  94. struct list_head tx_inproc;
  95. spinlock_t rx_lock;
  96. struct list_head rx_free;
  97. struct list_head rx_inproc;
  98. struct list_head rx_throttled;
  99. unsigned int last_pushed;
  100. struct workqueue_struct *tty_push_wq;
  101. struct work_struct tty_push_work;
  102. int tty_throttled;
  103. /* Transfer Controls */
  104. int nups;
  105. int ndowns;
  106. int upsz;
  107. int downsz;
  108. /* int splitsz; */
  109. int autoreconn;
  110. int pushable; /* Set to use push-way for upstream */
  111. int cbp_reset;
  112. /* Descriptors and Strings */
  113. struct usb_descriptor_header *fs_descs[MAX_DESC_ARRAY];
  114. struct usb_descriptor_header *hs_descs[MAX_DESC_ARRAY];
  115. struct usb_string string_defs[2];
  116. struct usb_gadget_strings string_table;
  117. struct usb_gadget_strings *strings[2];
  118. struct usb_interface_descriptor interface;
  119. struct usb_endpoint_descriptor fs_bulkin_endpoint;
  120. struct usb_endpoint_descriptor hs_bulkin_endpoint;
  121. struct usb_endpoint_descriptor fs_bulkout_endpoint;
  122. struct usb_endpoint_descriptor hs_bulkout_endpoint;
  123. /* Sysfs Accesses */
  124. int max_attrs;
  125. struct device_attribute attr[MAX_ATTRIBUTES];
  126. };
  127. typedef void (*rawbulk_autoreconn_callback_t) (int transfer_id);
  128. /* bind/unbind host interfaces */
  129. int rawbulk_bind_sdio_channel(int transfer_id);
  130. void rawbulk_unbind_sdio_channel(int transfer_id);
  131. struct rawbulk_function *rawbulk_lookup_function(int transfer_id);
  132. /* rawbulk tty io */
  133. int rawbulk_register_tty(struct rawbulk_function *fn);
  134. void rawbulk_unregister_tty(struct rawbulk_function *fn);
  135. int rawbulk_tty_stop_io(struct rawbulk_function *fn);
  136. int rawbulk_tty_start_io(struct rawbulk_function *fn);
  137. int rawbulk_tty_alloc_request(struct rawbulk_function *fn);
  138. void rawbulk_tty_free_request(struct rawbulk_function *fn);
  139. /* bind/unbind for gadget */
  140. int rawbulk_bind_function(int transfer_id, struct usb_function *function,
  141. struct usb_ep *bulk_out, struct usb_ep *bulk_in,
  142. rawbulk_autoreconn_callback_t autoreconn_callback);
  143. void rawbulk_unbind_function(int trasfer_id);
  144. int rawbulk_check_enable(struct rawbulk_function *fn);
  145. void rawbulk_disable_function(struct rawbulk_function *fn);
  146. /* operations for transactions */
  147. int rawbulk_start_transactions(int transfer_id, int nups, int ndowns, int upsz, int downsz);
  148. void rawbulk_stop_transactions(int transfer_id);
  149. int rawbulk_push_upstream_buffer(int transfer_id, const void *buffer, unsigned int length);
  150. int rawbulk_transfer_statistics(int transfer_id, char *buf);
  151. int rawbulk_transfer_state(int transfer_id);
  152. extern int modem_dtr_set(int on, int low_latency);
  153. extern int modem_dcd_state(void);
  154. extern int sdio_buffer_push(int port_num, const unsigned char *buf, int count);
  155. extern int sdio_rawbulk_intercept(int port_num, unsigned int inception);
  156. /* debug mechanism */
  157. extern unsigned int c2k_usb_dbg_level; /* refer to rawbulk_transfer.c */
  158. static inline int c2k_dbg_level(unsigned level)
  159. {
  160. return c2k_usb_dbg_level >= level;
  161. }
  162. #define C2K_LOG_EMERG 0
  163. #define C2K_LOG_ALERT 1
  164. #define C2K_LOG_CRIT 2
  165. #define C2K_LOG_ERR 3
  166. #define C2K_LOG_WARN 4
  167. #define C2K_LOG_NOTICE 5
  168. #define C2K_LOG_INFO 6
  169. #define C2K_LOG_DBG 7
  170. #define C2K_USB_DBG_ON
  171. #ifdef C2K_USB_DBG_ON
  172. #define C2K_ERR(format, args...) do {if (c2k_dbg_level(C2K_LOG_ERR)) \
  173. pr_warn("C2K_USB_ERR,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  174. while (0)
  175. #define C2K_WARN(format, args...) do {if (c2k_dbg_level(C2K_LOG_WARN)) \
  176. pr_warn("C2K_USB_WARN,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  177. while (0)
  178. #define C2K_NOTE(format, args...) do {if (c2k_dbg_level(C2K_LOG_NOTICE)) \
  179. pr_warn("C2K_USB_NOTE,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  180. while (0)
  181. #define C2K_INFO(format, args...) do {if (c2k_dbg_level(C2K_LOG_INFO)) \
  182. pr_warn("C2K_USB_INFO,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  183. while (0)
  184. #define C2K_DBG(format, args...) do {if (c2k_dbg_level(C2K_LOG_DBG)) \
  185. pr_warn("C2K_USB_DBG,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  186. while (0)
  187. #else
  188. #define C2K_ERR(format, args...) do {} while (0)
  189. #define C2K_WARN(format, args...) do {} while (0)
  190. #define C2K_NOTE(format, args...) do {} while (0)
  191. #define C2K_INFO(format, args...) do {} while (0)
  192. #define C2K_DBG(format, args...) do {} while (0)
  193. #endif
  194. extern unsigned int upstream_data[_MAX_TID];
  195. extern unsigned int upstream_cnt[_MAX_TID];
  196. extern unsigned int total_drop[_MAX_TID];
  197. extern unsigned int alloc_fail[_MAX_TID];
  198. extern unsigned int total_tran[_MAX_TID];
  199. extern unsigned long volatile jiffies;
  200. #ifdef C2K_USB_UT
  201. extern int delay_set;
  202. extern int ut_err;
  203. #endif
  204. #endif /* __RAWBULK_HEADER_FILE__ */