usbutils.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * Copyright 2012-2013 Andrew Smith
  3. * Copyright 2013 Con Kolivas <kernel@kolivas.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #ifndef USBUTILS_H
  11. #define USBUTILS_H
  12. #include <libusb.h>
  13. #include "util.h"
  14. #define EPI(x) (LIBUSB_ENDPOINT_IN | (unsigned char)(x))
  15. #define EPO(x) (LIBUSB_ENDPOINT_OUT | (unsigned char)(x))
  16. // For 0x0403:0x6014/0x6001 FT232H (and possibly others?) - BFL, BAS, BLT, LLT, AVA
  17. #define FTDI_TYPE_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT)
  18. #define FTDI_TYPE_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN)
  19. #define FTDI_REQUEST_RESET ((uint8_t)0)
  20. #define FTDI_REQUEST_MODEM ((uint8_t)1)
  21. #define FTDI_REQUEST_FLOW ((uint8_t)2)
  22. #define FTDI_REQUEST_BAUD ((uint8_t)3)
  23. #define FTDI_REQUEST_DATA ((uint8_t)4)
  24. #define FTDI_REQUEST_LATENCY ((uint8_t)9)
  25. #define FTDI_VALUE_RESET 0
  26. #define FTDI_VALUE_PURGE_RX 1
  27. #define FTDI_VALUE_PURGE_TX 2
  28. #define FTDI_VALUE_LATENCY 1
  29. // Baud
  30. #define FTDI_VALUE_BAUD_BFL 0xc068
  31. #define FTDI_INDEX_BAUD_BFL 0x0200
  32. #define FTDI_VALUE_BAUD_BAS FTDI_VALUE_BAUD_BFL
  33. #define FTDI_INDEX_BAUD_BAS FTDI_INDEX_BAUD_BFL
  34. // LLT = BLT (same code)
  35. #define FTDI_VALUE_BAUD_BLT 0x001a
  36. #define FTDI_INDEX_BAUD_BLT 0x0000
  37. // Avalon
  38. #define FTDI_VALUE_BAUD_AVA 0x001A
  39. #define FTDI_INDEX_BAUD_AVA 0x0000
  40. #define FTDI_VALUE_DATA_AVA 8
  41. // BitBurner
  42. #define BITBURNER_REQUEST ((uint8_t)0x42)
  43. #define BITBURNER_VALUE 0x4242
  44. #define BITBURNER_INDEX_SET_VOLTAGE 1
  45. #define BITBURNER_INDEX_GET_VOLTAGE 2
  46. #define BITBURNER_INDEX_GET_VERSION 4
  47. // CMR = 115200 & 57600
  48. #define FTDI_VALUE_BAUD_CMR_115 0xc068
  49. #define FTDI_INDEX_BAUD_CMR_115 0x0200
  50. #define FTDI_VALUE_BAUD_CMR_57 0x80d0
  51. #define FTDI_INDEX_BAUD_CMR_57 0x0200
  52. // Data control
  53. #define FTDI_VALUE_DATA_BFL 0
  54. #define FTDI_VALUE_DATA_BAS FTDI_VALUE_DATA_BFL
  55. // LLT = BLT (same code)
  56. #define FTDI_VALUE_DATA_BLT 8
  57. #define FTDI_VALUE_FLOW 0
  58. #define FTDI_VALUE_MODEM 0x0303
  59. // For 0x10c4:0xea60 USB cp210x chip - AMU
  60. #define CP210X_TYPE_OUT 0x41
  61. #define CP210X_REQUEST_IFC_ENABLE 0x00
  62. #define CP210X_REQUEST_DATA 0x07
  63. #define CP210X_REQUEST_BAUD 0x1e
  64. #define CP210X_VALUE_UART_ENABLE 0x0001
  65. #define CP210X_VALUE_DATA 0x0303
  66. #define CP210X_DATA_BAUD 0x0001c200
  67. // For 0x067b:0x2303 Prolific PL2303 - ICA
  68. #define PL2303_CTRL_DTR 0x01
  69. #define PL2303_CTRL_RTS 0x02
  70. #define PL2303_CTRL_OUT 0x21
  71. #define PL2303_VENDOR_OUT 0x40
  72. #define PL2303_REQUEST_CTRL 0x22
  73. #define PL2303_REQUEST_LINE 0x20
  74. #define PL2303_REQUEST_VENDOR 0x01
  75. #define PL2303_REPLY_CTRL 0x21
  76. #define PL2303_VALUE_CTRL (PL2303_CTRL_DTR | PL2303_CTRL_RTS)
  77. #define PL2303_VALUE_LINE 0
  78. #define PL2303_VALUE_LINE0 0x0001c200
  79. #define PL2303_VALUE_LINE1 0x080000
  80. #define PL2303_VALUE_LINE_SIZE 7
  81. #define PL2303_VALUE_VENDOR 0
  82. // Use the device defined timeout
  83. #define DEVTIMEOUT 0
  84. // The default intinfo structure used is the first one
  85. #define DEFAULT_INTINFO 0
  86. // For endpoints defined in usb_find_devices.intinfos.epinfos,
  87. // the first two must be the default IN and OUT and both must always exist
  88. #define DEFAULT_EP_IN 0
  89. #define DEFAULT_EP_OUT 1
  90. struct usb_epinfo {
  91. uint8_t att;
  92. uint16_t size;
  93. unsigned char ep;
  94. uint16_t wMaxPacketSize;
  95. uint16_t PrefPacketSize;
  96. bool found;
  97. };
  98. struct usb_intinfo {
  99. int interface;
  100. int ctrl_transfer;
  101. int epinfo_count;
  102. struct usb_epinfo *epinfos;
  103. };
  104. enum sub_ident {
  105. IDENT_UNK = 0,
  106. IDENT_BAJ,
  107. IDENT_BAL,
  108. IDENT_BAS,
  109. IDENT_BAM,
  110. IDENT_BFL,
  111. IDENT_BFU,
  112. IDENT_MMQ,
  113. IDENT_AVA,
  114. IDENT_BTB,
  115. IDENT_ICA,
  116. IDENT_AMU,
  117. IDENT_BLT,
  118. IDENT_LLT,
  119. IDENT_CMR1,
  120. IDENT_CMR2,
  121. IDENT_ZTX
  122. };
  123. struct usb_find_devices {
  124. int drv;
  125. const char *name;
  126. enum sub_ident ident;
  127. uint16_t idVendor;
  128. uint16_t idProduct;
  129. char *iManufacturer;
  130. char *iProduct;
  131. int config;
  132. unsigned int timeout;
  133. uint16_t latency;
  134. int intinfo_count;
  135. struct usb_intinfo *intinfos;
  136. };
  137. /* Latency is set to 32ms to prevent a transfer ever being more than 512 bytes
  138. * +2 bytes of status such as the ftdi chip, when the chips emulate a 115200
  139. * baud rate, to avoid status bytes being interleaved in larger transfers. */
  140. #define LATENCY_UNUSED 0
  141. #define LATENCY_STD 32
  142. enum usb_types {
  143. USB_TYPE_STD = 0,
  144. USB_TYPE_FTDI
  145. };
  146. struct cg_usb_device {
  147. struct usb_find_devices *found;
  148. libusb_device_handle *handle;
  149. pthread_mutex_t *mutex;
  150. struct libusb_device_descriptor *descriptor;
  151. enum usb_types usb_type;
  152. enum sub_ident ident;
  153. uint16_t usbver;
  154. int cps;
  155. bool usecps;
  156. char *prod_string;
  157. char *manuf_string;
  158. char *serial_string;
  159. unsigned char fwVersion; // ??
  160. unsigned char interfaceVersion; // ??
  161. char *buffer;
  162. uint32_t bufsiz;
  163. uint32_t bufamt;
  164. cgtimer_t cgt_last_write;
  165. size_t last_write_siz;
  166. };
  167. #define USB_NOSTAT 0
  168. #define USB_MAX_READ 8192
  169. #define USB_TMO_0 50
  170. #define USB_TMO_1 100
  171. #define USB_TMO_2 500
  172. #define USB_TMOS 3
  173. struct cg_usb_tmo {
  174. uint32_t count;
  175. uint32_t min_tmo;
  176. uint32_t max_tmo;
  177. uint64_t total_over;
  178. uint64_t total_tmo;
  179. };
  180. struct cg_usb_info {
  181. uint8_t bus_number;
  182. uint8_t device_address;
  183. int usbstat;
  184. bool nodev;
  185. int nodev_count;
  186. struct timeval last_nodev;
  187. uint32_t ioerr_count;
  188. uint32_t continuous_ioerr_count;
  189. /*
  190. * for nodev and cgusb access (read and write)
  191. * it's a pointer so MMQ can have it in multiple devices
  192. *
  193. * N.B. general mining code doesn't need to use the read
  194. * lock for 'nodev' if it calls a usb_read/write/etc function
  195. * that uses the lock - however, all usbutils code MUST use it
  196. * to avoid devices disappearing while in use by multiple threads
  197. */
  198. pthread_rwlock_t *devlock;
  199. time_t last_pipe;
  200. uint64_t pipe_count;
  201. uint64_t clear_err_count;
  202. uint64_t retry_err_count;
  203. uint64_t clear_fail_count;
  204. uint64_t read_delay_count;
  205. double total_read_delay;
  206. uint64_t write_delay_count;
  207. double total_write_delay;
  208. /*
  209. * We add 4: 1 for null, 2 for FTDI status and 1 to round to 4 bytes
  210. * If a single device ever has multiple end points then it will need
  211. * multiple of these
  212. */
  213. unsigned char bulkbuf[USB_MAX_READ+4];
  214. uint64_t tmo_count;
  215. struct cg_usb_tmo usb_tmo[USB_TMOS];
  216. };
  217. #define USB_PARSE_COMMANDS \
  218. USB_ADD_COMMAND(C_REJECTED, "RejectedNoDevice") \
  219. USB_ADD_COMMAND(C_PING, "Ping") \
  220. USB_ADD_COMMAND(C_CLEAR, "Clear") \
  221. USB_ADD_COMMAND(C_REQUESTVERSION, "RequestVersion") \
  222. USB_ADD_COMMAND(C_GETVERSION, "GetVersion") \
  223. USB_ADD_COMMAND(C_REQUESTFPGACOUNT, "RequestFPGACount") \
  224. USB_ADD_COMMAND(C_GETFPGACOUNT, "GetFPGACount") \
  225. USB_ADD_COMMAND(C_STARTPROGRAM, "StartProgram") \
  226. USB_ADD_COMMAND(C_STARTPROGRAMSTATUS, "StartProgramStatus") \
  227. USB_ADD_COMMAND(C_PROGRAM, "Program") \
  228. USB_ADD_COMMAND(C_PROGRAMSTATUS, "ProgramStatus") \
  229. USB_ADD_COMMAND(C_PROGRAMSTATUS2, "ProgramStatus2") \
  230. USB_ADD_COMMAND(C_FINALPROGRAMSTATUS, "FinalProgramStatus") \
  231. USB_ADD_COMMAND(C_SETCLOCK, "SetClock") \
  232. USB_ADD_COMMAND(C_REPLYSETCLOCK, "ReplySetClock") \
  233. USB_ADD_COMMAND(C_REQUESTUSERCODE, "RequestUserCode") \
  234. USB_ADD_COMMAND(C_GETUSERCODE, "GetUserCode") \
  235. USB_ADD_COMMAND(C_REQUESTTEMPERATURE, "RequestTemperature") \
  236. USB_ADD_COMMAND(C_GETTEMPERATURE, "GetTemperature") \
  237. USB_ADD_COMMAND(C_SENDWORK, "SendWork") \
  238. USB_ADD_COMMAND(C_SENDWORKSTATUS, "SendWorkStatus") \
  239. USB_ADD_COMMAND(C_REQUESTWORKSTATUS, "RequestWorkStatus") \
  240. USB_ADD_COMMAND(C_GETWORKSTATUS, "GetWorkStatus") \
  241. USB_ADD_COMMAND(C_REQUESTIDENTIFY, "RequestIdentify") \
  242. USB_ADD_COMMAND(C_GETIDENTIFY, "GetIdentify") \
  243. USB_ADD_COMMAND(C_REQUESTFLASH, "RequestFlash") \
  244. USB_ADD_COMMAND(C_REQUESTSENDWORK, "RequestSendWork") \
  245. USB_ADD_COMMAND(C_REQUESTSENDWORKSTATUS, "RequestSendWorkStatus") \
  246. USB_ADD_COMMAND(C_RESET, "Reset") \
  247. USB_ADD_COMMAND(C_SETBAUD, "SetBaud") \
  248. USB_ADD_COMMAND(C_SETDATA, "SetDataCtrl") \
  249. USB_ADD_COMMAND(C_SETFLOW, "SetFlowCtrl") \
  250. USB_ADD_COMMAND(C_SETMODEM, "SetModemCtrl") \
  251. USB_ADD_COMMAND(C_PURGERX, "PurgeRx") \
  252. USB_ADD_COMMAND(C_PURGETX, "PurgeTx") \
  253. USB_ADD_COMMAND(C_FLASHREPLY, "FlashReply") \
  254. USB_ADD_COMMAND(C_REQUESTDETAILS, "RequestDetails") \
  255. USB_ADD_COMMAND(C_GETDETAILS, "GetDetails") \
  256. USB_ADD_COMMAND(C_REQUESTRESULTS, "RequestResults") \
  257. USB_ADD_COMMAND(C_GETRESULTS, "GetResults") \
  258. USB_ADD_COMMAND(C_REQUESTQUEJOB, "RequestQueJob") \
  259. USB_ADD_COMMAND(C_REQUESTQUEJOBSTATUS, "RequestQueJobStatus") \
  260. USB_ADD_COMMAND(C_QUEJOB, "QueJob") \
  261. USB_ADD_COMMAND(C_QUEJOBSTATUS, "QueJobStatus") \
  262. USB_ADD_COMMAND(C_QUEFLUSH, "QueFlush") \
  263. USB_ADD_COMMAND(C_QUEFLUSHREPLY, "QueFlushReply") \
  264. USB_ADD_COMMAND(C_REQUESTVOLTS, "RequestVolts") \
  265. USB_ADD_COMMAND(C_GETVOLTS, "GetVolts") \
  266. USB_ADD_COMMAND(C_SENDTESTWORK, "SendTestWork") \
  267. USB_ADD_COMMAND(C_LATENCY, "SetLatency") \
  268. USB_ADD_COMMAND(C_SETLINE, "SetLine") \
  269. USB_ADD_COMMAND(C_VENDOR, "Vendor") \
  270. USB_ADD_COMMAND(C_SETFAN, "SetFan") \
  271. USB_ADD_COMMAND(C_FANREPLY, "GetFan") \
  272. USB_ADD_COMMAND(C_AVALON_TASK, "AvalonTask") \
  273. USB_ADD_COMMAND(C_AVALON_READ, "AvalonRead") \
  274. USB_ADD_COMMAND(C_GET_AVALON_READY, "AvalonReady") \
  275. USB_ADD_COMMAND(C_AVALON_RESET, "AvalonReset") \
  276. USB_ADD_COMMAND(C_GET_AVALON_RESET, "GetAvalonReset") \
  277. USB_ADD_COMMAND(C_FTDI_STATUS, "FTDIStatus") \
  278. USB_ADD_COMMAND(C_ENABLE_UART, "EnableUART") \
  279. USB_ADD_COMMAND(C_BB_SET_VOLTAGE, "SetCoreVoltage") \
  280. USB_ADD_COMMAND(C_BB_GET_VOLTAGE, "GetCoreVoltage") \
  281. USB_ADD_COMMAND(C_BF1_OPEN, "BF1Open") \
  282. USB_ADD_COMMAND(C_BF1_CLOSE, "BF1Close") \
  283. USB_ADD_COMMAND(C_BF1_REQINFO, "BF1RequestInfo") \
  284. USB_ADD_COMMAND(C_BF1_GETINFO, "BF1GetInfo") \
  285. USB_ADD_COMMAND(C_BF1_REQRESET, "BF1RequestReset") \
  286. USB_ADD_COMMAND(C_BF1_GETRESET, "BF1GetReset") \
  287. USB_ADD_COMMAND(C_BF1_REQWORK, "BF1RequestWork") \
  288. USB_ADD_COMMAND(C_BF1_GETWORK, "BF1GetWork") \
  289. USB_ADD_COMMAND(C_BF1_GETRES, "BF1GetResults") \
  290. USB_ADD_COMMAND(C_BF1_FLUSH, "BF1Flush") \
  291. USB_ADD_COMMAND(C_BF1_IFLUSH, "BF1InterruptFlush") \
  292. USB_ADD_COMMAND(C_BF1_IDENTIFY, "BF1Identify")
  293. /* Create usb_cmds enum from USB_PARSE_COMMANDS macro */
  294. #define USB_ADD_COMMAND(X, Y) X,
  295. enum usb_cmds {
  296. USB_PARSE_COMMANDS
  297. C_MAX
  298. };
  299. #undef USB_ADD_COMMAND
  300. struct device_drv;
  301. struct cgpu_info;
  302. void usb_all(int level);
  303. const char *usb_cmdname(enum usb_cmds cmd);
  304. void usb_applog(struct cgpu_info *bflsc, enum usb_cmds cmd, char *msg, int amount, int err);
  305. struct cgpu_info *usb_copy_cgpu(struct cgpu_info *orig);
  306. struct cgpu_info *usb_alloc_cgpu(struct device_drv *drv, int threads);
  307. struct cgpu_info *usb_free_cgpu_devlock(struct cgpu_info *cgpu, bool free_devlock);
  308. #define usb_free_cgpu(cgpu) usb_free_cgpu_devlock(cgpu, true)
  309. void usb_uninit(struct cgpu_info *cgpu);
  310. bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
  311. void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
  312. struct api_data *api_usb_stats(int *count);
  313. void update_usb_stats(struct cgpu_info *cgpu);
  314. int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce);
  315. int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds);
  316. int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, unsigned int timeout, enum usb_cmds cmd);
  317. int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, enum usb_cmds cmd);
  318. int usb_ftdi_cts(struct cgpu_info *cgpu);
  319. int _usb_ftdi_set_latency(struct cgpu_info *cgpu, int intinfo);
  320. #define usb_ftdi_set_latency(_cgpu) _usb_ftdi_set_latency(_cgpu, DEFAULT_INTINFO)
  321. void usb_buffer_enable(struct cgpu_info *cgpu);
  322. void usb_buffer_disable(struct cgpu_info *cgpu);
  323. void usb_buffer_clear(struct cgpu_info *cgpu);
  324. uint32_t usb_buffer_size(struct cgpu_info *cgpu);
  325. void usb_set_cps(struct cgpu_info *cgpu, int cps);
  326. void usb_enable_cps(struct cgpu_info *cgpu);
  327. void usb_disable_cps(struct cgpu_info *cgpu);
  328. int _usb_interface(struct cgpu_info *cgpu, int intinfo);
  329. #define usb_interface(_cgpu) _usb_interface(_cgpu, DEFAULT_INTINFO)
  330. enum sub_ident usb_ident(struct cgpu_info *cgpu);
  331. void _usb_set_pps(struct cgpu_info *cgpu, int intinfo, int epinfo, uint16_t PrefPacketSize);
  332. #define usb_set_pps(_cgpu, _pps) _usb_set_pps(_cgpu, -1, -1, _pps)
  333. void usb_set_dev_start(struct cgpu_info *cgpu);
  334. void usb_cleanup();
  335. void usb_initialise();
  336. void *usb_resource_thread(void *userdata);
  337. #define usb_read(cgpu, buf, bufsiz, read, cmd) \
  338. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
  339. #define usb_read_ii(cgpu, intinfo, buf, bufsiz, read, cmd) \
  340. _usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
  341. #define usb_read_once(cgpu, buf, bufsiz, read, cmd) \
  342. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true)
  343. #define usb_read_ii_once(cgpu, intinfo, buf, bufsiz, read, cmd) \
  344. _usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true)
  345. #define usb_read_once_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
  346. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true)
  347. #define usb_read_ii_once_timeout(cgpu, intinfo, buf, bufsiz, read, timeout, cmd) \
  348. _usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, true)
  349. #define usb_read_nl(cgpu, buf, bufsiz, read, cmd) \
  350. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false)
  351. #define usb_read_nl_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
  352. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, "\n", cmd, false)
  353. #define usb_read_ok(cgpu, buf, bufsiz, read, cmd) \
  354. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, false)
  355. #define usb_read_ok_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
  356. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, "OK\n", cmd, false)
  357. #define usb_read_ep(cgpu, ep, buf, bufsiz, read, cmd) \
  358. _usb_read(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false)
  359. #define usb_read_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \
  360. _usb_read(cgpu, DEFAULT_INTINFO, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false)
  361. #define usb_read_ii_timeout(cgpu, intinfo, buf, bufsiz, read, timeout, cmd) \
  362. _usb_read(cgpu, intinfo, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false)
  363. #define usb_read_ep_timeout(cgpu, ep, buf, bufsiz, read, timeout, cmd) \
  364. _usb_read(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, read, timeout, NULL, cmd, false)
  365. #define usb_write(cgpu, buf, bufsiz, wrote, cmd) \
  366. _usb_write(cgpu, DEFAULT_INTINFO, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
  367. #define usb_write_ii(cgpu, intinfo, buf, bufsiz, wrote, cmd) \
  368. _usb_write(cgpu, intinfo, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
  369. #define usb_write_ep(cgpu, ep, buf, bufsiz, wrote, cmd) \
  370. _usb_write(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, wrote, DEVTIMEOUT, cmd)
  371. #define usb_write_timeout(cgpu, buf, bufsiz, wrote, timeout, cmd) \
  372. _usb_write(cgpu, DEFAULT_INTINFO, DEFAULT_EP_OUT, buf, bufsiz, wrote, timeout, cmd)
  373. #define usb_write_ep_timeout(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) \
  374. _usb_write(cgpu, DEFAULT_INTINFO, ep, buf, bufsiz, wrote, timeout, cmd)
  375. #define usb_transfer(cgpu, typ, req, val, idx, cmd) \
  376. _usb_transfer(cgpu, typ, req, val, idx, NULL, 0, DEVTIMEOUT, cmd)
  377. #define usb_transfer_data(cgpu, typ, req, val, idx, data, len, cmd) \
  378. _usb_transfer(cgpu, typ, req, val, idx, data, len, DEVTIMEOUT, cmd)
  379. #define usb_transfer_read(cgpu, typ, req, val, idx, buf, bufsiz, read, cmd) \
  380. _usb_transfer_read(cgpu, typ, req, val, idx, buf, bufsiz, read, DEVTIMEOUT, cmd)
  381. #endif